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: [PATCH] Handle case where `beg` and `end` are strings instead of markers Date: Thu, 28 Apr 2022 20:36:08 -0400 Message-ID: <87k0b84tfr.fsf@occasionallycogent.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31275"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Apr 29 02:37:08 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 1nkEdA-00081R-My for ged-emacs-devel@m.gmane-mx.org; Fri, 29 Apr 2022 02:37:08 +0200 Original-Received: from localhost ([::1]:53712 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nkEd9-0008Tg-A7 for ged-emacs-devel@m.gmane-mx.org; Thu, 28 Apr 2022 20:37:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51142) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nkEcM-0007nI-G7 for emacs-devel@gnu.org; Thu, 28 Apr 2022 20:36:18 -0400 Original-Received: from mail-qv1-xf2f.google.com ([2607:f8b0:4864:20::f2f]:34537) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nkEcJ-0002UT-TH for emacs-devel@gnu.org; Thu, 28 Apr 2022 20:36:17 -0400 Original-Received: by mail-qv1-xf2f.google.com with SMTP id a5so4407772qvx.1 for ; Thu, 28 Apr 2022 17:36:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version; bh=6EYW6zZ4BZlnjkzLuKXge30OHiOlGo4fWcQX3jOXn+E=; b=HRc3RyWEqH9BJe495b6CKhD1IGKHhJng6UOatHD/SVToVpCb+fHVfoHd+LUzljw0Vm H7QMeuib/IrD5qq3P5V/yihWVpkx+DJ/D/F21nxDGmPXZkcKKrcnyyoTv1JPHLUvT7x5 IR6cmcHxRxhU4b9qEkTi+L1Bvcm9WEqv5AtyTqBesgEtpvWyTayJ3Usv/hK6Bhd77vUc 39eqtGq0ciyjljYodJRshjwtFdQg+644uKhO+KFdWXcBOHoeYW9FlaXbqKB2rCDZSj1U 2CkSFZC1pQAQ2gOywOOeFvJGlTp9r7nyYKxl1BESQVS9mA/rLiz8Yo0Vav3ezGX4to3c swWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=6EYW6zZ4BZlnjkzLuKXge30OHiOlGo4fWcQX3jOXn+E=; b=rFSx+V9GGo6k7G8ENwEuasad97emUMP7KqtuJxxsMU+t+8L2eOyJRmPr6sMwhzYKje zqreWeRdkp+9HK7A+IFIvpXQnAcmeoskSbhyYhP4vphfQRnQ496KwPrTOevyvZwfy5PY H0oD/HwX+u+GAqScJaLQHEcYq4RDC8JbQ6oh9p25cVSrMeFyinyYEkPHCkUOWpdW45sf 1Ad3F1rRuVOca8zDd0LBRYiwPUu1nU5GOUmVAzHVhqp4AiRkdtrmUftSC9O8UrJqZA2x 3DCID0RciTL61bpQwO2ZAUX6mf15ttFF/rbscNchZaKH9bQiU7fMo5b44GCZCVqpTDH+ E/Uw== X-Gm-Message-State: AOAM533t4Vi0HWGCNnbU4azK460ZYE7K3DxzEcRXHF5QH2ipigCBbonK lwiqTRZbU/xntSWuqzRFgmYfbdTpx9A= X-Google-Smtp-Source: ABdhPJzBZl9bWlG2+KS7+vcIyVmk0sSIvFBKnJb8kE26vBii76y4uuaThv0PgGVJn+EaZ7w/Q6mI+A== X-Received: by 2002:a05:6214:76a:b0:456:4fd4:dcd6 with SMTP id f10-20020a056214076a00b004564fd4dcd6mr8698039qvz.41.1651192572524; Thu, 28 Apr 2022 17:36:12 -0700 (PDT) Original-Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com. [66.111.4.228]) by smtp.gmail.com with ESMTPSA id o189-20020a375ac6000000b0069f73d3b544sm695118qkb.43.2022.04.28.17.36.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 17:36:10 -0700 (PDT) Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailauth.nyi.internal (Postfix) with ESMTP id 10F0227C0054 for ; Thu, 28 Apr 2022 20:36:10 -0400 (EDT) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 28 Apr 2022 20:36:10 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrudekgdeffecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkfggtgesthdtredttddttd enucfhrhhomhepfdflrghmvghsucfprdcuggdrucevrghshhdfuceojhgrmhgvshdrnhhv tgesghhmrghilhdrtghomheqnecuggftrfgrthhtvghrnhepveegiedtkeefvedtkedule ekfefhhefflefhtdeitdegfeffleetfeevgfejtefhnecuffhomhgrihhnpegvlhdrqdih ohhupdgvlhdrhihouhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehjrghmvghspggtrghshhdomhgvshhmthhprghuthhhphgvrhhsohhnrghl ihhthidquddvfedvtddvjeelvddqvdejkeegtdduhedvqdhjrghmvghsrdhnvhgtpeepgh hmrghilhdrtghomhesohgttggrshhiohhnrghllhihtghoghgvnhhtrdgtohhm X-ME-Proxy: Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 28 Apr 2022 20:36:09 -0400 (EDT) Received-SPF: pass client-ip=2607:f8b0:4864:20::f2f; envelope-from=james.nvc@gmail.com; helo=mail-qv1-xf2f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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:288953 Archived-At: With the changes to pass affixes to the completion functions, the begin and end points passed to the completion function are now sometimes strings instead of numbers or markers. This handles that case by searching for said prefix and suffix. Without this, completion functions that call `completion--replace` error out -- for example, completing tags in org-mode. --- lisp/minibuffer.el | 69 +++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 29 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index ef71b4e6be..d75b771044 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -1147,35 +1147,46 @@ 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) + (length 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