unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: p.stephani2@gmail.com, 30668@debbugs.gnu.org
Subject: bug#30668: 27.0.50; Error in `completing-read'
Date: Sat, 26 Jun 2021 09:38:30 -0400	[thread overview]
Message-ID: <jwv5yy0rbts.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87pmwac80a.fsf@gnus.org> (Lars Ingebrigtsen's message of "Fri, 25 Jun 2021 16:51:33 +0200")

Lars Ingebrigtsen [2021-06-25 16:51:33] wrote:

> p.stephani2@gmail.com writes:
>
>> emacs -Q --eval='(completing-read "p: " nil)'
>>
>> Hit <left> <SPC>.  An error will be signaled:
>>
>> completion--some: Args out of range: "", 0, -1
>>
>> Backtrace is
>>
>> Debugger entered--Lisp error: (args-out-of-range "" 0 -1)
>>   completion-basic-try-completion("" nil nil -1)
>>   #f(compiled-function (style) #<bytecode 0x3aabd9>)(basic)
>>   completion--some(#f(compiled-function (style) #<bytecode 0x3aabd9>)
>>   (basic partial-completion emacs22))
>>   completion--nth-completion(1 "" nil nil -1 (metadata))
>>   completion-try-completion("" nil nil -1 (metadata))
>>   completion--try-word-completion("" nil nil -1 (metadata))
>>   completion--do-completion(4 4 completion--try-word-completion)
>
> This problem is still present in Emacs 28.  I'm not quite sure what the
> correct fix is -- just change `completion--do-completion' to not do
> completion if `(- (point) beg)' is negative?
>
> Perhaps Stefan has an opinion here; added to the CCs.

When point is inside the prompt, it's outside of the "completion area".
[ If/when we change the minibuffer completion to use
  `completion-at-point`, there will simply be no completion data when
  we're inside the prompt.  ]

So I installed the change below.


        Stefan


diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index d09a348211..b106fd11a9 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -882,6 +882,12 @@ delete-minibuffer-contents
   ;; is on, the field doesn't cover the entire minibuffer contents.
   (delete-region (minibuffer-prompt-end) (point-max)))
 
+(defun completion--prompt-end ()
+  (let ((end (minibuffer-prompt-end)))
+    (if (< (point) end)
+        (user-error "Can't complete in prompt")
+      end)))
+
 (defvar completion-show-inline-help t
   "If non-nil, print helpful inline messages during completion.")
 
@@ -1349,10 +1355,9 @@ minibuffer-complete
 If you repeat this command after it displayed such a list,
 scroll the window of possible completions."
   (interactive)
-  (when (<= (minibuffer-prompt-end) (point))
-    (completion-in-region (minibuffer-prompt-end) (point-max)
-                          minibuffer-completion-table
-                          minibuffer-completion-predicate)))
+  (completion-in-region (completion--prompt-end) (point-max)
+                        minibuffer-completion-table
+                        minibuffer-completion-predicate))
 
 (defun completion--in-region-1 (beg end)
   ;; If the previous command was not this,
@@ -1530,7 +1535,7 @@ minibuffer-force-complete-and-exit
   (unless completion-cycling
     (minibuffer-force-complete nil nil 'dont-cycle))
   (completion--complete-and-exit
-   (minibuffer-prompt-end) (point-max) #'exit-minibuffer
+   (completion--prompt-end) (point-max) #'exit-minibuffer
    ;; If the previous completion completed to an element which fails
    ;; test-completion, then we shouldn't exit, but that should be rare.
    (lambda ()
@@ -1548,7 +1553,7 @@ minibuffer-force-complete
   ;; FIXME: Need to deal with the extra-size issue here as well.
   ;; FIXME: ~/src/emacs/t<M-TAB>/lisp/minibuffer.el completes to
   ;; ~/src/emacs/trunk/ and throws away lisp/minibuffer.el.
-  (let* ((start (copy-marker (or start (minibuffer-prompt-end))))
+  (let* ((start (copy-marker (or start (completion--prompt-end))))
          (end (or end (point-max)))
          ;; (md (completion--field-metadata start))
          (all (completion-all-sorted-completions start end))
@@ -1619,7 +1624,7 @@ minibuffer-complete-and-exit
  `minibuffer-confirm-exit-commands', and accept the input
  otherwise."
   (interactive)
-  (completion-complete-and-exit (minibuffer-prompt-end) (point-max)
+  (completion-complete-and-exit (completion--prompt-end) (point-max)
                                 #'exit-minibuffer))
 
 (defun completion-complete-and-exit (beg end exit-function)
@@ -1785,7 +1790,7 @@ minibuffer-complete-word
 Return nil if there is no valid completion, else t."
   (interactive)
   (completion-in-region--single-word
-   (minibuffer-prompt-end) (point-max)
+   (completion--prompt-end) (point-max)
    minibuffer-completion-table minibuffer-completion-predicate))
 
 (defun completion-in-region--single-word (beg end collection
@@ -2159,7 +2164,7 @@ minibuffer-completion-help
   "Display a list of possible completions of the current minibuffer contents."
   (interactive)
   (message "Making completion list...")
-  (let* ((start (or start (minibuffer-prompt-end)))
+  (let* ((start (or start (completion--prompt-end)))
          (end (or end (point-max)))
          (string (buffer-substring start end))
          (md (completion--field-metadata start))






  reply	other threads:[~2021-06-26 13:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-01 18:23 bug#30668: 27.0.50; Error in `completing-read' p.stephani2
2018-03-01 18:39 ` Drew Adams
2021-06-25 14:51 ` Lars Ingebrigtsen
2021-06-26 13:38   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2021-06-26 13:55     ` Eli Zaretskii
2021-06-26 16:22       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-06-26 13: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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=jwv5yy0rbts.fsf-monnier+emacs@gnu.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=30668@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=p.stephani2@gmail.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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).