all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: "Basil L. Contovounesios" <contovob@tcd.ie>
Cc: spacibba@aol.com, Jean Louis <bugs@gnu.support>,
	andreyk.mad@gmail.com, emacs-devel@gnu.org, rudalics@gmx.at,
	Stefan Monnier <monnier@iro.umontreal.ca>,
	Gregory Heytings <ghe@sdf.org>, Eli Zaretskii <eliz@gnu.org>,
	Drew Adams <drew.adams@oracle.com>
Subject: Re: on helm substantial differences
Date: Wed, 18 Nov 2020 21:13:40 +0200	[thread overview]
Message-ID: <87ft56h6sr.fsf@mail.linkov.net> (raw)
In-Reply-To: <87lfey28us.fsf@tcd.ie> (Basil L. Contovounesios's message of "Wed, 18 Nov 2020 11:38:19 +0000")

[-- Attachment #1: Type: text/plain, Size: 558 bytes --]

>> -					(+ (string-width (car s))
>> -                                           (string-width (cadr s)))
>> +                                        (cl-reduce #'+ (mapcar #'string-width s))
>
> Nit: If you're calling mapcar anyway, why not simply (apply #'+ 0 ...)?

Thanks, fixed.  Now the patch also adds a new user option
'completions-detailed'.  An option separate from 'completions-format'
is needed in case when a completion function doesn't provide :affix-function,
so there is a need to fall back to the customized value of 'completions-format'.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: completions-detailed.patch --]
[-- Type: text/x-diff, Size: 9685 bytes --]

diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index 170f497541..de4005d6cd 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -127,16 +127,45 @@ help-enable-completion-autoload
   :version "26.3")
 
 (defun help--symbol-completion-table (string pred action)
-  (when help-enable-completion-autoload
-    (let ((prefixes (radix-tree-prefixes (help-definition-prefixes) string)))
-      (help--load-prefixes prefixes)))
-  (let ((prefix-completions
-         (and help-enable-completion-autoload
-              (mapcar #'intern (all-completions string definition-prefixes)))))
-    (complete-with-action action obarray string
-                          (if pred (lambda (sym)
-                                     (or (funcall pred sym)
-                                         (memq sym prefix-completions)))))))
+  (if (eq action 'metadata)
+      (when completions-detailed
+        '(metadata
+	  (affix-function
+           . (lambda (completions)
+               (mapcar (lambda (c)
+                         (let* ((s (intern c))
+                                (doc (condition-case nil (documentation s) (error nil)))
+                                (doc (and doc (substring doc 0 (string-match "\n" doc)))))
+                           (list c (concat (cond ((commandp s)
+                                                  "c")
+                                                 ((eq (car-safe (symbol-function s)) 'macro)
+                                                  "m")
+                                                 ((fboundp s)
+                                                  "f")
+                                                 ((custom-variable-p s)
+                                                  "u") ; user option
+                                                 ((boundp s)
+                                                  "v")
+                                                 ((facep s)
+                                                  "a")
+                                                 ((and (fboundp 'cl-find-class)
+                                                       (cl-find-class s))
+                                                  "t") ; CL type
+                                                 (" "))
+                                           " ")
+                                 (if doc (format " -- %s" doc) ""))))
+                       completions)))))
+
+    (when help-enable-completion-autoload
+      (let ((prefixes (radix-tree-prefixes (help-definition-prefixes) string)))
+        (help--load-prefixes prefixes)))
+    (let ((prefix-completions
+           (and help-enable-completion-autoload
+                (mapcar #'intern (all-completions string definition-prefixes)))))
+      (complete-with-action action obarray string
+                            (if pred (lambda (sym)
+                                       (or (funcall pred sym)
+                                           (memq sym prefix-completions))))))))
 
 (defvar describe-function-orig-buffer nil
   "Buffer that was current when `describe-function' was invoked.
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 9d57a817b2..7e1d806059 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -83,7 +80,6 @@
 
 ;; - add support for ** to pcm.
 ;; - Add vc-file-name-completion-table to read-file-name-internal.
-;; - A feature like completing-help.el.
 
 ;;; Code:
 
@@ -121,6 +117,9 @@ completion-metadata
 - `annotation-function': function to add annotations in *Completions*.
    Takes one argument (STRING), which is a possible completion and
    returns a string to append to STRING.
+- `affix-function': function to prepend/append a prefix/suffix to entries.
+   Takes one argument (COMPLETIONS) and should return a list
+   of completions with a completion, its prefix and suffix.
 - `display-sort-function': function to sort entries in *Completions*.
    Takes one argument (COMPLETIONS) and should return a new list
    of completions.  Can operate destructively.
@@ -1669,7 +1668,7 @@ completion-in-region--single-word
     (#b000 nil)
       (_     t))))
 
-(defface completions-annotations '((t :inherit italic))
+(defface completions-annotations '((t :inherit (italic shadow)))
   "Face to use for annotations in the *Completions* buffer.")
 
 (defcustom completions-format 'horizontal
@@ -1681,6 +1680,16 @@ completions-format
   :type '(choice (const horizontal) (const vertical))
   :version "23.2")
 
+(defcustom completions-detailed nil
+  "When non-nil, display completions vertically with one completion per row.
+This option overrides another related option `completions-format'.
+Some commands might provide a detailed view with more information added
+to completions.  When the used completion function doesn't provide
+a detailed view via `affix-function', then fall back to the value
+defined by `completions-format'."
+  :type 'boolean
+  :version "28.1")
+
 (defun completion--insert-strings (strings)
   "Insert a list of STRINGS into the current buffer.
 Uses columns to keep the listing readable but compact.
@@ -1689,8 +1698,7 @@ completion--insert-strings
     (let* ((length (apply #'max
 			  (mapcar (lambda (s)
 				    (if (consp s)
-					(+ (string-width (car s))
-                                           (string-width (cadr s)))
+					(apply #'+ (mapcar #'string-width s))
 				      (string-width s)))
 				  strings)))
 	   (window (get-buffer-window (current-buffer) 0))
@@ -1715,10 +1723,14 @@ completion--insert-strings
           ;; FIXME: `string-width' doesn't pay attention to
           ;; `display' properties.
           (let ((length (if (consp str)
-                            (+ (string-width (car str))
-                               (string-width (cadr str)))
+                            (apply #'+ (mapcar #'string-width str))
                           (string-width str))))
             (cond
+             ((and completions-detailed (= (length str) 3))
+              ;; Detailed view
+              ;; When `str' contains prefix and suffix this means
+              ;; that caller specified `affix-function'.
+              )
 	     ((eq completions-format 'vertical)
 	      ;; Vertical format
 	      (when (> row rows)
@@ -1754,14 +1766,27 @@ completion--insert-strings
             (if (not (consp str))
                 (put-text-property (point) (progn (insert str) (point))
                                    'mouse-face 'highlight)
-              (put-text-property (point) (progn (insert (car str)) (point))
-                                 'mouse-face 'highlight)
-              (let ((beg (point))
-                    (end (progn (insert (cadr str)) (point))))
-                (put-text-property beg end 'mouse-face nil)
-                (font-lock-prepend-text-property beg end 'face
-                                                 'completions-annotations)))
+              (let* ((prefix (when (nth 2 str) (nth 1 str)))
+                     (suffix (or (nth 2 str) (nth 1 str))))
+                (when prefix
+                  (let ((beg (point))
+                        (end (progn (insert prefix) (point))))
+                    (put-text-property beg end 'mouse-face nil)
+                    (font-lock-prepend-text-property beg end 'face
+                                                     'completions-annotations)))
+                (put-text-property (point) (progn (insert (car str)) (point))
+                                   'mouse-face 'highlight)
+                (let ((beg (point))
+                      (end (progn (insert suffix) (point))))
+                  (put-text-property beg end 'mouse-face nil)
+                  (font-lock-prepend-text-property beg end 'face
+                                                   'completions-annotations))))
 	    (cond
+	     ((and completions-detailed (= (length str) 3))
+	      ;; Detailed view
+	      (when (zerop row) (setq truncate-lines t))
+	      (insert "\n")
+	      (setq row (1+ row)))
 	     ((eq completions-format 'vertical)
 	      ;; Vertical format
 	      (if (> column 0)
@@ -1880,6 +1905,9 @@ completion-extra-properties
    completion).  The function can access the completion data via
    `minibuffer-completion-table' and related variables.
 
+`:affix-function': Function to prepend/append a prefix/suffix to completions.
+   The function must accept one argument, a list of completions.
+
 `:exit-function': Function to run after completion is performed.
 
    The function must accept two arguments, STRING and STATUS.
@@ -1966,6 +1994,9 @@ minibuffer-completion-help
                        (plist-get completion-extra-properties
                                   :annotation-function)
                        completion-annotate-function))
+             (xfun (or (completion-metadata-get all-md 'affix-function)
+                       (plist-get completion-extra-properties
+                                  :affix-function)))
              (mainbuf (current-buffer))
              ;; If the *Completions* buffer is shown in a new
              ;; window, mark it as softly-dedicated, so bury-buffer in
@@ -2012,6 +2043,9 @@ minibuffer-completion-help
                                         (let ((ann (funcall afun s)))
                                           (if ann (list s ann) s)))
                                       completions)))
+                      (when xfun
+                        (setq completions
+                              (funcall xfun completions)))
 
                       (with-current-buffer standard-output
                         (set (make-local-variable 'completion-base-position)

  reply	other threads:[~2020-11-18 19:13 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-12 17:42 on helm substantial differences Drew Adams
2020-11-13 21:16 ` Jean Louis
2020-11-15 11:49 ` Jean Louis
2020-11-15 20:07 ` Juri Linkov
2020-11-15 22:01   ` Stefan Monnier
2020-11-15 22:41     ` Drew Adams
2020-11-16  8:58     ` Juri Linkov
2020-11-16 16:03       ` Drew Adams
2020-11-16 17:36       ` Stefan Monnier
2020-11-16 20:38         ` Juri Linkov
2020-11-16 21:54           ` Stefan Monnier
2020-11-17 19:18         ` Juri Linkov
2020-11-17 20:32           ` Juri Linkov
2020-11-18  9:10             ` Juri Linkov
2020-11-18 11:38               ` Basil L. Contovounesios
2020-11-18 19:13                 ` Juri Linkov [this message]
2020-11-18 20:33                   ` Juri Linkov
2020-11-20  9:24                     ` Juri Linkov
2020-11-20 11:57                       ` Eli Zaretskii
2020-11-20 12:15                         ` Eli Zaretskii
2020-11-20 14:39                           ` Stefan Monnier
2020-11-21 20:18                           ` Juri Linkov
2020-11-22  3:33                             ` Eli Zaretskii
2020-11-22  8:36                               ` Juri Linkov
2020-11-22 15:19                                 ` Eli Zaretskii
2020-11-22 20:11                                   ` Juri Linkov
2020-11-23  3:24                                     ` Eli Zaretskii
2020-11-25  9:10                                       ` Juri Linkov
2020-11-25 15:51                                         ` Eli Zaretskii
2020-11-25 19:16                                           ` Juri Linkov
2020-11-25 19:59                                             ` Eli Zaretskii
2020-11-25 20:35                                               ` Juri Linkov
2020-11-26 13:45                                                 ` Eli Zaretskii
2020-11-27  8:45                                                   ` Juri Linkov
2020-11-27  8:58                                                     ` Eli Zaretskii
2020-11-27  9:17                                                       ` Juri Linkov
2020-11-17 21:14           ` Jean Louis
2020-11-18  9:03             ` Juri Linkov
2020-11-18 19:21           ` Juri Linkov
2020-11-18 22:04             ` select yank via completion Stefan Monnier
2020-11-18 23:02               ` Drew Adams
2020-11-19  7:54               ` Juri Linkov
2020-11-19 17:00                 ` Drew Adams
2020-11-20  8:53                   ` Juri Linkov
2020-11-20 11:53                     ` Eli Zaretskii
2020-11-21 19:38                       ` Juri Linkov
2020-11-21 19:57                         ` Eli Zaretskii
2020-11-21 20:43                           ` Juri Linkov
2020-11-20 14:23                     ` Stefan Monnier
2020-11-21 19:42                       ` Juri Linkov
2020-11-21 21:08                         ` Stefan Monnier
2020-11-21 22:21                         ` Drew Adams
2020-11-21 22:48                           ` Jean Louis
2020-11-21 23:00                           ` Jean Louis
2020-11-25 19:25                           ` Juri Linkov
2020-11-25 19:40                             ` Drew Adams
2020-11-21 21:54                       ` Drew Adams
2020-11-21 21:46                     ` Drew Adams
2020-11-24 22:59                     ` Basil L. Contovounesios
2020-11-25  7:36                       ` Juri Linkov
2020-11-25  8:14                         ` Andrii Kolomoiets
2020-11-25 20:24                           ` Juri Linkov
2020-11-26  8:46                             ` Basil L. Contovounesios
2020-11-26  9:26                               ` Juri Linkov
2020-11-26  9:57                                 ` Eli Zaretskii
2020-11-26 21:17                                   ` Basil L. Contovounesios
2020-11-27  7:13                                     ` Eli Zaretskii
2020-11-27  9:01                                       ` Juri Linkov
2020-11-18 22:36             ` on helm substantial differences Drew Adams
2020-11-16 16:13   ` Eli Zaretskii
2020-11-16 20:41     ` Juri Linkov
2020-11-16 21:18       ` Drew Adams
2020-11-16 22:13         ` Juri Linkov
2020-11-17  0:04           ` Drew Adams
2020-11-17  8:38             ` Juri Linkov
2020-11-17 16:56               ` Drew Adams
2020-11-17 12:06             ` Protesilaos Stavrou
2020-11-17 17:29               ` Drew Adams
2020-11-17 19:23               ` Juri Linkov
2020-11-17  3:24       ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ft56h6sr.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=andreyk.mad@gmail.com \
    --cc=bugs@gnu.support \
    --cc=contovob@tcd.ie \
    --cc=drew.adams@oracle.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=ghe@sdf.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=rudalics@gmx.at \
    --cc=spacibba@aol.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.