Ihor Radchenko <yanta...@posteo.net> writes:

> It has been a while since the last activity in this thread.
> May I know if you still plan to work on this patch?

Thank you Ihor for reminding me of this.

The functionality almost works... there is only one thing that blocked
me. In the `completing-read' function, the value of the passed argument
REQUIRE-MATCH is t. To prevent adding values from outside of the list of
summary-types functions. Unfortunately, when the annotation was added,
it is not possible to choose any function from the list. It throws an
error [Match required].

Maybe you have an idea how to fix it?

Patch below:
>From 75badc5be2ef361f9a228a97f27a8778ca655625 Mon Sep 17 00:00:00 2001
From: Slawomir Grochowski <s...@thinkpad.home>
Date: Sun, 20 Oct 2024 21:48:23 +0200
Subject: [PATCH] lisp/org-colview.el: display annotation for summary type
 functions

---
 lisp/org-colview.el | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/lisp/org-colview.el b/lisp/org-colview.el
index ffed5501a..d3d32e0fd 100644
--- a/lisp/org-colview.el
+++ b/lisp/org-colview.el
@@ -930,6 +930,27 @@ When COLUMNS-FMT-STRING is non-nil, use it as the column format."
 	      (goto-char (car entry))
 	      (org-columns--display-here (cdr entry)))))))))
 
+(defun org-columns--summary-types-completion-function (string pred flag)
+  (pcase flag
+    ('t (all-completions string
+                         (delete-dups
+                          (cons '("") ;Allow empty operator.
+                                (mapcar #'car (append
+                                               org-columns-summary-types
+                                               org-columns-summary-types-default))))
+                         pred))
+    ('metadata (list 'metadata
+                     (cons 'annotation-function
+                           (lambda (string)
+                             (let* ((doc (condition-case nil (documentation (cdr (assoc string (append
+                                                                                                org-columns-summary-types
+                                                                                                org-columns-summary-types-default))))
+                                           (error nil)))
+                                    (doc (and doc (substring doc 0 (string-search "\n" doc)))))
+                               (if doc
+                                   (format " -- %s" doc)
+                                 ""))))))))
+
 (defun org-columns-new (&optional spec &rest attributes)
   "Insert a new column, to the left of the current column.
 Interactively fill attributes for new column.  When column format
@@ -961,12 +982,7 @@ details."
 			 (org-string-nw-p
 			  (completing-read
 			   "Summary: "
-			   (delete-dups
-			    (cons '("")	;Allow empty operator.
-				  (mapcar (lambda (x) (list (car x)))
-					  (append
-					   org-columns-summary-types
-					   org-columns-summary-types-default))))
+			   'org-columns--summary-types-completion-function
 			   nil t (nth 3 spec)))
 			 (org-string-nw-p
 			  (read-string "Format: " (nth 4 spec))))))))
-- 
2.39.5

-- 
Slawomir Grochowski

Reply via email to