From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#30668: 27.0.50; Error in `completing-read' Date: Sat, 26 Jun 2021 09:38:30 -0400 Message-ID: References: <87pmwac80a.fsf@gnus.org> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39378"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: p.stephani2@gmail.com, 30668@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jun 26 15:39:11 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lx8Wc-000A31-WD for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 26 Jun 2021 15:39:11 +0200 Original-Received: from localhost ([::1]:54322 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lx8Wc-0002jb-1y for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 26 Jun 2021 09:39:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40472) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lx8WU-0002jE-I8 for bug-gnu-emacs@gnu.org; Sat, 26 Jun 2021 09:39:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35784) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lx8WU-0002Vk-AI for bug-gnu-emacs@gnu.org; Sat, 26 Jun 2021 09:39:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lx8WU-0006vv-9C for bug-gnu-emacs@gnu.org; Sat, 26 Jun 2021 09:39:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 26 Jun 2021 13:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30668 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed Original-Received: via spool by 30668-submit@debbugs.gnu.org id=B30668.162471472126617 (code B ref 30668); Sat, 26 Jun 2021 13:39:02 +0000 Original-Received: (at 30668) by debbugs.gnu.org; 26 Jun 2021 13:38:41 +0000 Original-Received: from localhost ([127.0.0.1]:47328 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lx8W9-0006vF-6t for submit@debbugs.gnu.org; Sat, 26 Jun 2021 09:38:41 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:63969) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lx8W6-0006ux-C4 for 30668@debbugs.gnu.org; Sat, 26 Jun 2021 09:38:39 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 68095801F2; Sat, 26 Jun 2021 09:38:32 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 01F2E8065C; Sat, 26 Jun 2021 09:38:31 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1624714711; bh=OYZrp7SUuOIjlNdNS4jDvJsGgu+2M+9E2RB9kRVa9fI=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=j679yQha65Zi0qMFqgnzq6RwMeCymdps4T79k5hyuoZFid8iT6M73BjaQYFcwuiQ0 eLyXkx1f8TW9AcPXmZ5+7QBSF5ce6JuZhqb36KblGt02/AbNG7LiOsrU1dYE7hHhMw 9MZN/RjC5bKRvnTSNRM3imG6I+ARD6g9Gn+2gXH8c51uh6m3W9WNnOUxc+gPjQHAYd QPfhxwUaUm1jAPcRTwfUxWagh1KNF259AcYZIsYfqwEUmnEw6XjPOLAhRHmSWXM0K3 XGHt8X6s+h+EONSmBmKjC+0mSEisjNiCAvTIuzXOCc0u6ak+OcMHYjlk7lfwESvM0m ukEDjSBruXYVA== Original-Received: from alfajor (69-196-163-239.dsl.teksavvy.com [69.196.163.239]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id C62F8120176; Sat, 26 Jun 2021 09:38:30 -0400 (EDT) In-Reply-To: <87pmwac80a.fsf@gnus.org> (Lars Ingebrigtsen's message of "Fri, 25 Jun 2021 16:51:33 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:209016 Archived-At: Lars Ingebrigtsen [2021-06-25 16:51:33] wrote: > p.stephani2@gmail.com writes: > >> emacs -Q --eval='(completing-read "p: " nil)' >> >> Hit . 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) #)(basic) >> completion--some(#f(compiled-function (style) #) >> (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/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))