]> code.delx.au - gnu-emacs/blobdiff - lisp/dabbrev.el
(choose-completion-string): Use `minibufferp';
[gnu-emacs] / lisp / dabbrev.el
index f2beb01124735f5e4b9c52285fc4670f76056037..202cb9edf74a8bc98bf23f004d0a8ee37ac15d5c 100644 (file)
@@ -613,16 +613,15 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
 (defun dabbrev--goto-start-of-abbrev ()
   ;; Move backwards over abbrev chars
   (save-match-data
-    (if (not (bobp))
-       (progn
-         (forward-char -1)
-         (while (and (looking-at dabbrev--abbrev-char-regexp)
-                     (not (bobp))
-                     (not (= (point) (field-beginning (point) nil
-                                                      (1- (point))))))
-           (forward-char -1))
-         (or (looking-at dabbrev--abbrev-char-regexp)
-             (forward-char 1))))
+    (when (> (point) (minibuffer-prompt-end))
+      (forward-char -1)
+      (while (and (looking-at dabbrev--abbrev-char-regexp)
+                 (> (point) (minibuffer-prompt-end))
+                 (not (= (point) (field-beginning (point) nil
+                                                  (1- (point))))))
+       (forward-char -1))
+      (or (looking-at dabbrev--abbrev-char-regexp)
+         (forward-char 1)))
     (and dabbrev-abbrev-skip-leading-regexp
         (while (looking-at dabbrev-abbrev-skip-leading-regexp)
           (forward-char 1)))))
@@ -751,7 +750,7 @@ DIRECTION = 0 means try both backward and forward.
 IGNORE-CASE non-nil means ignore case when searching.
 This sets `dabbrev--last-direction' to 1 or -1 according
 to the direction in which the occurrence was actually found.
-It sets `dabbrev--last-expansion-location' to the location 
+It sets `dabbrev--last-expansion-location' to the location
 of the start of the occurrence."
   (save-excursion
     ;; If we were scanning something other than the current buffer,
@@ -921,15 +920,19 @@ to record whether we upcased the expansion, downcased it, or did neither."
     ;; record if we upcased or downcased the first word,
     ;; in order to do likewise for subsequent words.
     (and record-case-pattern
-        (setq dabbrev--last-case-pattern 
+        (setq dabbrev--last-case-pattern
               (and use-case-replace
                    (cond ((equal abbrev (upcase abbrev)) 'upcase)
                          ((equal abbrev (downcase abbrev)) 'downcase)))))
 
-    ;; Convert newlines to spaces.
+    ;; Convert whitespace to single spaces.
     (if dabbrev--eliminate-newlines
-       (while (string-match "\n" expansion)
-         (setq expansion (replace-match " " nil nil expansion))))
+       ;; Start searching at end of ABBREV so that any whitespace
+       ;; carried over from the existing text is not changed.
+       (let ((pos (length abbrev)))
+         (while (string-match "[\n \t]+" expansion pos)
+           (setq pos (1+ (match-beginning 0)))
+           (setq expansion (replace-match " " nil nil expansion)))))
 
     (if old
        (save-excursion
@@ -972,6 +975,9 @@ Leaves point at the location of the start of the expansion."
                            "\\(" dabbrev--abbrev-char-regexp "\\)"))
          (pattern2 (concat (regexp-quote abbrev)
                           "\\(\\(" dabbrev--abbrev-char-regexp "\\)+\\)"))
+         ;; This makes it possible to find matches in minibuffer prompts
+         ;; even when they are "inviolable".
+         (inhibit-point-motion-hooks t)
          found-string result)
       ;; Limited search.
       (save-restriction