Ihor Radchenko <[email protected]> writes:
 
> According to https://github.com/minad/vertico/discussions/599, it looks
> like you can simply call `completion-table-with-metadata' instead of
> that pcase.

With your help, I finally managed to come up with the proper
solution. Thank you. I'm not sure if the commit message is correct
because I haven't done it for a long time.

Patch below:

>From 699ef2d9564b9086b255a911c2c3597a0ccea731 Mon Sep 17 00:00:00 2001
From: Slawomir Grochowski <[email protected]>
Date: Tue, 26 Aug 2025 22:31:33 +0200
Subject: [PATCH] lisp/org-colview.el: add annotation for functions
 summary-types

* org-colview.el (org-columns--summary-types-completion-function): Add
function that adds annotations to 'summary-types'. Annotations are
taken from doctrings of summary-types functions.
(org-columns-new): Pass `org-columns--summary-types-completion-function
to `completing-read function.
---
 lisp/org-colview.el | 36 +++++++++++++++++++++++++++---------
 1 file changed, 27 insertions(+), 9 deletions(-)

diff --git a/lisp/org-colview.el b/lisp/org-colview.el
index 2bf31d9cc..d4aa4acc1 100644
--- a/lisp/org-colview.el
+++ b/lisp/org-colview.el
@@ -930,6 +930,29 @@ 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)
+  (let ((completion-table
+         (completion-table-with-metadata
+          (lambda (str pred comp)
+            (complete-with-action comp
+                                  (delete-dups
+                                   (cons '("" "")
+                                         (mapcar #'car
+                                                 (append org-columns-summary-types
+                                                         org-columns-summary-types-default))))
+                                  str pred))
+          `(metadata
+            . ((annotation-function
+                . ,(lambda (string)
+                     (let* ((doc (ignore-errors
+                                   (documentation
+                                    (cdr (assoc string
+                                                (append org-columns-summary-types
+                                                        org-columns-summary-types-default))))))
+                            (doc (and doc (substring doc 0 (string-search "\n" doc)))))
+                       (if doc (format " -- %s" doc) "")))))))))
+    (complete-with-action flag completion-table string pred)))
+
 (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
@@ -959,15 +982,10 @@ details."
 					(number-to-string (nth 2 spec))))))
 			   (and (org-string-nw-p w) (string-to-number w)))
 			 (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))))
-			   nil t (nth 3 spec)))
+                          (completing-read
+                           "Summary: "
+                           'org-columns--summary-types-completion-function
+                           nil t (nth 3 spec)))
 			 (org-string-nw-p
 			  (read-string "Format: " (nth 4 spec))))))))
     (if spec
-- 
2.39.5

-- 
Slawomir Grochowski

Reply via email to