all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ergus <spacibba@aol.com>
To: Juri Linkov <juri@linkov.net>
Cc: emacs-devel@gnu.org
Subject: [PATCH] Re: Other details about completion.
Date: Fri, 1 Apr 2022 22:24:25 +0200	[thread overview]
Message-ID: <20220401202425.jfrwqmkm3ffmcm5h@Ergus> (raw)
In-Reply-To: <86r16g92v5.fsf@mail.linkov.net>

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

Hi again...

Here I attached a small patch that makes 3 small changes:

1) Remove the trailing newline in completions one-column
2) Use another condition in next-completion to jump to minibuffer.

Normally next-completion with tabs at the end of the buffer needs an
extra tab because it goes to the end of the last completion before
jumping to the minibuffer or wrap.. That extra tab is because the
condition to jump or wrap was eobp/bobp assuming that there is not text
unproppertized after the last candidate.

3) Remove a comment in switch-to-completions. That comment suggested that
the next-completion action must be called inside
minibuffer-completion-help but IMO that is not totally correct when
completion-auto-select has some of the new values.

Please, if anyone could review,correct and push I would be very
grateful.

Best,
Ergus

[-- Attachment #2: next-completion.patch --]
[-- Type: text/plain, Size: 5880 bytes --]

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index d8df1799c9..5ad44a7a2d 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -2044,7 +2044,8 @@ completion--insert-one-column
               (when title
                 (insert (format completions-group-format title) "\n")))))
         (completion--insert str group-fun)
-        (insert "\n")))))
+        (insert "\n")))
+    (delete-char -1)))
 
 (defun completion--insert (str group-fun)
   (if (not (consp str))
diff --git a/lisp/simple.el b/lisp/simple.el
index c60abcb1f4..7918767a75 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -9179,46 +9179,53 @@ next-completion
                 ((/= prev (point))
                  (point))
                 (t prev))))
-  (let ((beg (point-min)) (end (point-max)))
+
+  (let ((beg (point-min))
+        (end (point-max))
+        (tabcommand (member (this-command-keys) '("\t" [backtab])))
+        prop)
     (catch 'bound
       (while (> n 0)
         ;; If in a completion, move to the end of it.
         (when (get-text-property (point) 'mouse-face)
           (goto-char (next-single-property-change (point) 'mouse-face nil end)))
         ;; If at the last completion option, wrap or skip to the
-        ;; minibuffer, if requested.
-        (when (and completion-wrap-movement (eobp))
-          (if (and (member (this-command-keys) '("\t" [backtab]))
-                   completion-auto-select)
+        ;; minibuffer, if requested. We can't use (eobp) because some
+        ;; extra text may be after the last candidate: ex: when
+        ;; completion-detailed
+        (setq prop (next-single-property-change (point) 'mouse-face nil end))
+        (when (and completion-wrap-movement (eq end prop))
+          (if (and completion-auto-select tabcommand)
               (throw 'bound nil)
             (goto-char (point-min))))
         ;; Move to start of next one.
         (unless (get-text-property (point) 'mouse-face)
           (goto-char (next-single-property-change (point) 'mouse-face nil end)))
         (setq n (1- n)))
+
       (while (and (< n 0) (not (bobp)))
-        (let ((prop (get-text-property (1- (point)) 'mouse-face)))
-          ;; If in a completion, move to the start of it.
-          (when (and prop (eq prop (get-text-property (point) 'mouse-face)))
-            (goto-char (previous-single-property-change
-                        (point) 'mouse-face nil beg)))
-          ;; Move to end of the previous completion.
-          (unless (or (bobp) (get-text-property (1- (point)) 'mouse-face))
-            (goto-char (previous-single-property-change
-                        (point) 'mouse-face nil beg)))
-          ;; If at the first completion option, wrap or skip to the
-          ;; minibuffer, if requested.
-          (when (and completion-wrap-movement (bobp))
-            (if (and (member (this-command-keys) '("\t" [backtab]))
-                     completion-auto-select)
-                (progn
-                  (goto-char (next-single-property-change (point) 'mouse-face nil end))
-                  (throw 'bound nil))
-              (goto-char (point-max))))
-          ;; Move to the start of that one.
+        (setq prop (get-text-property (1- (point)) 'mouse-face))
+        ;; If in a completion, move to the start of it.
+        (when (and prop (eq prop (get-text-property (point) 'mouse-face)))
           (goto-char (previous-single-property-change
-                      (point) 'mouse-face nil beg))
-          (setq n (1+ n)))))
+                      (point) 'mouse-face nil beg)))
+        ;; Move to end of the previous completion.
+        (unless (or (bobp) (get-text-property (1- (point)) 'mouse-face))
+          (goto-char (previous-single-property-change
+                      (point) 'mouse-face nil beg)))
+        ;; If at the first completion option, wrap or skip to the
+        ;; minibuffer, if requested.
+        (setq prop (previous-single-property-change (point) 'mouse-face nil beg))
+        (when (and completion-wrap-movement (eq beg prop))
+          (if (and completion-auto-select tabcommand)
+              (progn
+                (goto-char (next-single-property-change (point) 'mouse-face nil end))
+                (throw 'bound nil))
+            (goto-char (point-max))))
+        ;; Move to the start of that one.
+        (goto-char (previous-single-property-change
+                    (point) 'mouse-face nil beg))
+        (setq n (1+ n))))
     (when (/= 0 n)
       (switch-to-minibuffer))))
 
@@ -9436,22 +9443,18 @@ completion-setup-function
 (defun switch-to-completions ()
   "Select the completion list window."
   (interactive)
-  (let ((window (or (get-buffer-window "*Completions*" 0)
-		    ;; Make sure we have a completions window.
-                    (progn (minibuffer-completion-help)
-                           (get-buffer-window "*Completions*" 0)))))
-    (when window
-      (select-window window)
+  (when-let ((window (or (get-buffer-window "*Completions*" 0)
+		         ;; Make sure we have a completions window.
+                         (progn (minibuffer-completion-help)
+                                (get-buffer-window "*Completions*" 0)))))
+    (select-window window)
+    (when (bobp)
       (cond
        ((and (memq this-command '(completion-at-point minibuffer-complete))
-             (equal (this-command-keys) [backtab])
-             (bobp))
+             (equal (this-command-keys) [backtab]))
         (goto-char (point-max))
         (previous-completion 1))
-       ;; In the new buffer, go to the first completion.
-       ;; FIXME: Perhaps this should be done in `minibuffer-completion-help'.
-       ((bobp)
-        (next-completion 1))))))
+       (t (next-completion 1))))))
 
 (defun read-expression-switch-to-completions ()
   "Select the completion list window while reading an expression."

  parent reply	other threads:[~2022-04-01 20:24 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20220401153839.idrzrbfl2yfzga3y.ref@Ergus>
2022-04-01 15:38 ` Other details about completion Ergus
2022-04-01 16:21   ` Eli Zaretskii
2022-04-01 16:43   ` Juri Linkov
2022-04-01 16:45     ` Ergus
2022-04-01 20:24     ` Ergus [this message]
2022-04-02 18:09       ` [PATCH] " Juri Linkov
2022-04-03  0:39         ` Ergus
2022-04-04 19:35       ` Ergus
2022-04-04 19:45         ` Juri Linkov
2022-04-04 20:31           ` Philip Kaludercic
2022-04-05 11:06             ` Ergus
2022-04-04 22:33           ` Ergus
2022-04-05 19:22             ` Juri Linkov
2022-04-05 23:20               ` Ergus
2022-04-06  7:35                 ` Juri Linkov
2022-04-06 13:21                   ` Ergus
2022-04-06 16:48                     ` Juri Linkov
2022-04-06 17:45                       ` [External] : " Drew Adams
2022-04-06 18:25                         ` Juri Linkov
2022-04-06 20:01                           ` Drew Adams
2022-04-06 17:45                       ` Ergus
2022-04-06 18:29                         ` Juri Linkov
2022-04-06 19:50                           ` Ergus
2022-04-07  7:35                             ` Juri Linkov
2022-04-07  9:16                               ` Ergus
2022-04-07 16:53                                 ` Juri Linkov
2022-04-07 17:38                                   ` Ergus
2022-04-07 18:04                                     ` Juri Linkov
2022-04-07 18:35                                       ` Ergus
2022-04-08  7:40                                         ` Juri Linkov
2022-04-08  8:42                                           ` Ergus
2022-04-08 16:20                                             ` [External] : " Drew Adams
2022-04-08 16:46                                             ` Juri Linkov
2022-04-08  9:31                                           ` Philip Kaludercic
2022-04-08 16:20                                             ` [External] : " Drew Adams
2022-04-08 16:51                                             ` Juri Linkov
2022-04-08 20:12                                               ` Philip Kaludercic
2022-04-06 23:55                           ` Ergus
2022-04-06 18:13                       ` Ergus
2022-04-06 18:34                         ` Juri Linkov
2022-04-06 20:34                           ` Ergus
2022-04-07  7:39                             ` Juri Linkov
2022-04-07  9:08                               ` Ergus
2022-04-07 16:50                                 ` Juri Linkov
2022-04-07 17:22                                   ` Ergus
2022-04-07 17:57                                     ` Juri Linkov
2022-04-07 18:27                                       ` Ergus
2022-04-08  7:45                                         ` Juri Linkov
2022-04-08  8:46                                           ` Ergus
2022-04-08 16:20                                             ` [External] : " Drew Adams
2022-04-08 16:53                                             ` Juri Linkov
2022-04-06  9:07                 ` Lars Ingebrigtsen
2022-04-06 16:43                   ` Juri Linkov
2022-04-07 11:09                     ` Lars Ingebrigtsen
2022-04-07 16:46                       ` Juri Linkov
2022-04-08 12:59                         ` Lars Ingebrigtsen

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=20220401202425.jfrwqmkm3ffmcm5h@Ergus \
    --to=spacibba@aol.com \
    --cc=emacs-devel@gnu.org \
    --cc=juri@linkov.net \
    /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.