From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: James N. V. Cash Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Handle case where `beg` and `end` are strings instead of markers Date: Fri, 29 Apr 2022 08:10:38 -0400 Message-ID: <87czh03xa9.fsf@occasionallycogent.com> References: <87k0b84tfr.fsf@occasionallycogent.com> <87h76c4ruf.fsf@occasionallycogent.com> <86sfpwwerz.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25521"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Juri Linkov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Apr 29 14:11:56 2022 Return-path: Envelope-to: ged-emacs-devel@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 1nkPTY-0006Qz-Fu for ged-emacs-devel@m.gmane-mx.org; Fri, 29 Apr 2022 14:11:56 +0200 Original-Received: from localhost ([::1]:40316 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nkPTX-00046I-8N for ged-emacs-devel@m.gmane-mx.org; Fri, 29 Apr 2022 08:11:55 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55696) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nkPSO-0003Je-LG for emacs-devel@gnu.org; Fri, 29 Apr 2022 08:10:44 -0400 Original-Received: from mail-qt1-f178.google.com ([209.85.160.178]:38628) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nkPSM-0006y0-G0 for emacs-devel@gnu.org; Fri, 29 Apr 2022 08:10:43 -0400 Original-Received: by mail-qt1-f178.google.com with SMTP id fu47so5498543qtb.5 for ; Fri, 29 Apr 2022 05:10:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=dyMZC6rvzjxwdWGaaxsmqfKqXOw9bXL+kRQwZrDcwf0=; b=Ob4m6uprO6MT6ctH8rpFZhF4Akmjt6n1+bz1+fOaTlJKnmBNAJW4a52y6Y3E5Xuemv iQtfGCKOkeSl8ANHceVeuO3KadN/kC6BWxcmwhndFdws6vdcBd93ACxe7UmPBspS8tCO VQqea8SAmQ206AG2EW5hqKERZjhPukZYrqZGyx79wPaojKg/i5+Tkwu5MloM30FoTlbn Rsrw8LwHX0ZMYHM6hJUShRZ+HGTQ3zkUcBnog76Ldb2IFCaE3h71ksquwB1OVUbiq5ui /broLtV6vN3W1JAXequVBE98l4ofVTRZRd2oH+N0mVwrgI1WY8d+t9esrj8VuwBjm2NX 3idg== X-Gm-Message-State: AOAM531jWiSZxfRhYNU20GS4+or+49roEo2op9J1Nps9OBIwQxEs/zxM VY/flpaeOevleCJ8VqPQjfzykxyDA2s= X-Google-Smtp-Source: ABdhPJx2GoC/cBmeWmQG8RjTNgBYBos9vrqTV6UqVGR9wIibfGApSL5sVUY2ML6Rx2UazTrVGuEqKg== X-Received: by 2002:a05:622a:349:b0:2f1:ffc2:821a with SMTP id r9-20020a05622a034900b002f1ffc2821amr26386423qtw.36.1651234241226; Fri, 29 Apr 2022 05:10:41 -0700 (PDT) Original-Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com. [66.111.4.228]) by smtp.gmail.com with ESMTPSA id x188-20020a3795c5000000b0069eb51aa159sm1336039qkd.108.2022.04.29.05.10.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 05:10:40 -0700 (PDT) Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailauth.nyi.internal (Postfix) with ESMTP id D426027C0054; Fri, 29 Apr 2022 08:10:39 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Fri, 29 Apr 2022 08:10:39 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrudelgdegjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufgjfhffkfggtgesthdtredttddttdenucfhrhhomheplfgrmhgvshcu pfdrucggrdcuvegrshhhuceojhgrmhgvshdrnhhvtgesghhmrghilhdrtghomheqnecugg ftrfgrthhtvghrnhepveeggedvhfeffefgvedvgfeftdejieeljeduuedvuddtfeefueef gefhkedvleeknecuffhomhgrihhnpegvlhdrqdihohhupdgvlhdrhihouhenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehjrghmvghspggtrghs hhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidquddvfedvtddvjeelvddqvd ejkeegtdduhedvqdhjrghmvghsrdhnvhgtpeepghhmrghilhdrtghomhesohgttggrshhi ohhnrghllhihtghoghgvnhhtrdgtohhm X-ME-Proxy: Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 29 Apr 2022 08:10:39 -0400 (EDT) In-Reply-To: <86sfpwwerz.fsf@mail.linkov.net> Received-SPF: pass client-ip=209.85.160.178; envelope-from=james.nvc@gmail.com; helo=mail-qt1-f178.google.com X-Spam_score_int: -9 X-Spam_score: -1.0 X-Spam_bar: - X-Spam_report: (-1.0 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, NML_ADSP_CUSTOM_MED=0.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:288977 Archived-At: Juri Linkov writes: > Please describe how do you expect this should behave from a UI point of view. > I see that when using on a simple call: > > (completing-read-multiple "Tags: " '(("tag1") ("tag2") ("tag3"))) > > subsequent completions can be selected properly > after replacing these lines in your patch > > + (+ (search-forward beg) > + (length beg))))) > > with > > + (search-forward beg)))) Ah, that seems to do it -- I was seeing subsequent completions only partially inserting, but that change you suggest fixes that and works as expected. New patch as follows then: --- lisp/minibuffer.el | 68 ++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index ef71b4e6be..08e2dc5a37 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -1147,35 +1147,45 @@ completion--replace newtext) ;; Remove all text properties. (set-text-properties 0 (length newtext) nil newtext)) - ;; Maybe this should be in subr.el. - ;; You'd think this is trivial to do, but details matter if you want - ;; to keep markers "at the right place" and be robust in the face of - ;; after-change-functions that may themselves modify the buffer. - (let ((prefix-len 0)) - ;; Don't touch markers in the shared prefix (if any). - (while (and (< prefix-len (length newtext)) - (< (+ beg prefix-len) end) - (eq (char-after (+ beg prefix-len)) - (aref newtext prefix-len))) - (setq prefix-len (1+ prefix-len))) - (unless (zerop prefix-len) - (setq beg (+ beg prefix-len)) - (setq newtext (substring newtext prefix-len)))) - (let ((suffix-len 0)) - ;; Don't touch markers in the shared suffix (if any). - (while (and (< suffix-len (length newtext)) - (< beg (- end suffix-len)) - (eq (char-before (- end suffix-len)) - (aref newtext (- (length newtext) suffix-len 1)))) - (setq suffix-len (1+ suffix-len))) - (unless (zerop suffix-len) - (setq end (- end suffix-len)) - (setq newtext (substring newtext 0 (- suffix-len)))) - (goto-char beg) - (let ((length (- end beg))) ;Read `end' before we insert the text. - (insert-and-inherit newtext) - (delete-region (point) (+ (point) length))) - (forward-char suffix-len))) + (let ((beg (if (number-or-marker-p beg) + beg + (save-excursion + (goto-char (minibuffer-prompt-end)) + (search-forward beg)))) + (end (if (number-or-marker-p end) + end + (save-excursion + (goto-char (point-max)) + (search-backward end))))) + ;; Maybe this should be in subr.el. + ;; You'd think this is trivial to do, but details matter if you want + ;; to keep markers "at the right place" and be robust in the face of + ;; after-change-functions that may themselves modify the buffer. + (let ((prefix-len 0)) + ;; Don't touch markers in the shared prefix (if any). + (while (and (< prefix-len (length newtext)) + (< (+ beg prefix-len) end) + (eq (char-after (+ beg prefix-len)) + (aref newtext prefix-len))) + (setq prefix-len (1+ prefix-len))) + (unless (zerop prefix-len) + (setq beg (+ beg prefix-len)) + (setq newtext (substring newtext prefix-len)))) + (let ((suffix-len 0)) + ;; Don't touch markers in the shared suffix (if any). + (while (and (< suffix-len (length newtext)) + (< beg (- end suffix-len)) + (eq (char-before (- end suffix-len)) + (aref newtext (- (length newtext) suffix-len 1)))) + (setq suffix-len (1+ suffix-len))) + (unless (zerop suffix-len) + (setq end (- end suffix-len)) + (setq newtext (substring newtext 0 (- suffix-len)))) + (goto-char beg) + (let ((length (- end beg))) ;Read `end' before we insert the text. + (insert-and-inherit newtext) + (delete-region (point) (+ (point) length))) + (forward-char suffix-len)))) (defcustom completion-cycle-threshold nil "Number of completion candidates below which cycling is used. -- 2.25.1