completion--replace: Fix completion cycling
authorDmitry Gutov <dmitry@gutov.dev>
Sun, 12 May 2024 02:57:10 +0000 (05:57 +0300)
committerDmitry Gutov <dmitry@gutov.dev>
Sun, 12 May 2024 16:02:36 +0000 (19:02 +0300)
* lisp/minibuffer.el (completion--replace):
Don't "insert before markers" after all because in some cases
(https://lists.gnu.org/archive/html/emacs-devel/2024-05/msg00701.html)
- like cycling - BEG can be denoted by a marker as well.
(minibuffer-completion-help): Make FIELD-END simply a fixnum.  And
adjust its value manually inside the local
completion-list-insert-choice-function (bug#48356).

lisp/minibuffer.el

index 6139557703584070ec7834c178e2c5c1c1dfb3b7..fbd49b569a8925a6a2e108b3ba48923f0f0e21d2 100644 (file)
@@ -1363,7 +1363,7 @@ Moves point to the end of the new text."
       (setq newtext (substring newtext 0 (- suffix-len))))
     (goto-char beg)
     (let ((length (- end beg)))         ;Read `end' before we insert the text.
-      (insert-before-markers-and-inherit newtext)
+      (insert-and-inherit newtext)
       (delete-region (point) (+ (point) length)))
     (forward-char suffix-len)))
 
@@ -2594,7 +2594,7 @@ The candidate will still be chosen by `choose-completion' unless
                                              ctable
                                              cpred
                                              (buffer-substring (point) end))))
-                (point-marker)))
+                (point)))
              (field-char (and (< field-end end) (char-after field-end)))
              (all-md (completion--metadata (buffer-substring-no-properties
                                             start (point))
@@ -2702,6 +2702,7 @@ The candidate will still be chosen by `choose-completion' unless
                                             (= (aref choice (1- (length choice)))
                                                field-char))
                                    (setq end (1+ end)))
+                                 (cl-decf field-end (- end start (length choice)))
                                  ;; FIXME: Use `md' to do quoting&terminator here.
                                  (completion--replace start end choice)
                                  (let* ((minibuffer-completion-table ctable)