emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: on helm substantial differences


From: Juri Linkov
Subject: Re: on helm substantial differences
Date: Wed, 18 Nov 2020 21:21:07 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu)

> diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
> index 9d57a817b2..b98033753d 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:
>  

BTW, there is another TODO item in minibuffer.el:

;;   - indicate how to display the completions in *Completions* (turn
;;     \n into something else, add special boundaries between
;;     completions).  E.g. when completing from the kill-ring.

Such pre-processing can be performed by the caller.
For a long time I used the command 'yank-from-kill-ring'
bound to 'C-M-y' that relies on query-replace-descr
to display newlines as ^J and displays long completions
with an ellipsis at the end and an ellipsis on leading whitespace.

These pre-processed completions also needed to display
shorter strings in the minibuffer in icomplete-mode,
so this is usable in icomplete-mode as well:

diff --git a/lisp/simple.el b/lisp/simple.el
index bb28145502..076469b3d2 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -5449,6 +5449,55 @@ rotate-yank-pointer
 "With ARG, rotate that many kills forward (or backward, if negative)."
   (interactive "p")
   (current-kill arg))
+
+(defvar yank-from-kill-ring-history)
+(defun yank-from-kill-ring (string)
+  "Insert the kill-ring item selected from the minibuffer history.
+Use minibuffer navigation and search commands to browse the kill-ring
+in the minibuffer history before typing RET to insert the item,
+or use completion on the elements of the kill-ring."
+  (interactive
+   (list (let* ((history-add-new-input nil)
+                ;; Remove keymaps from text properties of copied string,
+                ;; because typing RET in the minibuffer might call
+                ;; an irrelevant command from the map of copied string.
+                (yank-from-kill-ring-history
+                 (mapcar (lambda (s)
+                           (remove-list-of-text-properties
+                            0 (length s)
+                            '(
+                              keymap local-map action mouse-action
+                              button category help-args)
+                            s)
+                           s)
+                         kill-ring))
+                (completions
+                 (mapcar (lambda (s)
+                           (let* ((s (query-replace-descr s))
+                                  (b 0))
+                             ;; Add ellipsis on leading whitespace
+                             (when (string-match "\\`[[:space:]]+" s)
+                               (setq b (match-end 0))
+                               (add-text-properties 0 b `(display "…") s))
+                             (when (> (length s) (- 40 b))
+                               (add-text-properties
+                                (min (+ b 40) (length s)) (length s)
+                                `(display "…") s))
+                             s))
+                         yank-from-kill-ring-history)))
+           (completing-read "Yank from kill-ring: "
+                            (lambda (string pred action)
+                              (if (eq action 'metadata)
+                                  ;; Keep sorted by recency
+                                 '(metadata (display-sort-function . identity))
+                                (complete-with-action action completions 
string pred)))
+                            nil nil nil
+                            'yank-from-kill-ring-history))))
+  (setq yank-window-start (window-start))
+  (push-mark)
+  (insert-for-yank string))
+
+(global-set-key "\M-\C-y" 'yank-from-kill-ring)
 
 ;; Some kill commands.
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]