(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)))))
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,
;; 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
"\\(" 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