# HG changeset patch # User Gerd Moellmann # Date 976881036 0 # Node ID 51c08e149a23eb950d4d90473879f20f807ae360 # Parent 5abdd701bf8df765d52222986a8b64b7a17afc4b (dabbrev--last-case-pattern): Value is now `upcase' or `downcase' or nil. (dabbrev-expand): Don't do anything with dabbrev--last-case-pattern. Pass new record-case-pattern arg to dabbrev--substitute-expansion. (dabbrev--substitute-expansion): New arg record-case-pattern. If it is non-nil, set dabbrev--last-case-pattern. If ABBREV is " ", use dabbrev--last-case-pattern to change EXPANSION. (dabbrev--find-expansion): Remove extra nreverse. diff -r 5abdd701bf8d -r 51c08e149a23 lisp/dabbrev.el --- a/lisp/dabbrev.el Fri Dec 15 11:41:20 2000 +0000 +++ b/lisp/dabbrev.el Fri Dec 15 11:50:36 2000 +0000 @@ -297,8 +297,8 @@ ;; The buffer we last did a completion in. (defvar dabbrev--last-completion-buffer nil) -;; Non-nil means we should upcase -;; when copying successive words. +;; If non-nil, a function to use when copying successive words. +;; It should be `upcase' or `downcase'. (defvar dabbrev--last-case-pattern nil) ;; Same as dabbrev-check-other-buffers, but is set for every expand. @@ -433,7 +433,7 @@ (message "Repeat `%s' to see all completions" (key-description (this-command-keys))) (message "The only possible completion")) - (dabbrev--substitute-expansion nil abbrev init)) + (dabbrev--substitute-expansion nil abbrev init nil)) (t ;; * String is a common substring completion already. Make list. (message "Making completion list...") @@ -510,8 +510,6 @@ (concat "\\(\\(" dabbrev--abbrev-char-regexp "\\)+\\)")) (setq expansion (buffer-substring-no-properties dabbrev--last-expansion-location (point))) - (if dabbrev--last-case-pattern - (setq expansion (upcase expansion))) ;; Record the end of this expansion, in case we repeat this. (setq dabbrev--last-expansion-location (point))) @@ -567,17 +565,8 @@ (copy-marker dabbrev--last-expansion-location))) ;; Success: stick it in and return. (setq buffer-undo-list (cons orig-point buffer-undo-list)) - (dabbrev--substitute-expansion old abbrev expansion) - - ;; If we are not copying successive words now, - ;; set dabbrev--last-case-pattern. - (and record-case-pattern - (setq dabbrev--last-case-pattern - (and (if (eq dabbrev-case-fold-search 'case-fold-search) - case-fold-search - dabbrev-case-fold-search) - (not dabbrev-upcase-means-case-search) - (equal abbrev (upcase abbrev))))) + (dabbrev--substitute-expansion old abbrev expansion + record-case-pattern) ;; Save state for re-expand. (setq dabbrev--last-expansion expansion) @@ -769,19 +758,18 @@ (funcall dabbrev-select-buffers-function)) (if dabbrev-check-all-buffers (setq non-friend-buffer-list - (nreverse - (dabbrev-filter-elements - buffer (buffer-list) - (let ((bn (buffer-name buffer))) - (and (not (member bn dabbrev-ignored-buffer-names)) - (not (memq buffer dabbrev--friend-buffer-list)) - (not - (let ((tail dabbrev-ignored-regexps) - (match nil)) - (while (and tail (not match)) - (setq match (string-match (car tail) bn) - tail (cdr tail))) - match)))))) + (dabbrev-filter-elements + buffer (buffer-list) + (let ((bn (buffer-name buffer))) + (and (not (member bn dabbrev-ignored-buffer-names)) + (not (memq buffer dabbrev--friend-buffer-list)) + (not + (let ((tail dabbrev-ignored-regexps) + (match nil)) + (while (and tail (not match)) + (setq match (string-match (car tail) bn) + tail (cdr tail))) + match))))) dabbrev--friend-buffer-list (append dabbrev--friend-buffer-list non-friend-buffer-list))))) @@ -814,11 +802,15 @@ (replace-match string fixedcase literal))) ;;;---------------------------------------------------------------- -;;; Substitute the current string in buffer with the expansion -;;; OLD is nil or the last expansion substring. -;;; ABBREV is the abbreviation we are working with. -;;; EXPANSION is the expansion substring. -(defun dabbrev--substitute-expansion (old abbrev expansion) +(defun dabbrev--substitute-expansion (old abbrev expansion record-case-pattern) + "Replace OLD with EXPANSION in the buffer. +OLD is text currently in the buffer, perhaps the abbreviation +or perhaps another expansion that was tried previously. +ABBREV is the abbreviation we are expanding. +It is \" \" if we are copying subsequent words. +EXPANSION is the expansion substring to be used this time. +RECORD-CASE-PATTERN, if non-nil, means set `dabbrev--last-case-pattern' +to record whether we upcased the expansion, downcased it, or did neither." ;;(undo-boundary) (let ((use-case-replace (and (if (eq dabbrev-case-fold-search 'case-fold-search) case-fold-search @@ -828,9 +820,14 @@ (if (eq dabbrev-case-replace 'case-replace) case-replace dabbrev-case-replace)))) - (and nil use-case-replace - (setq old (concat abbrev (or old ""))) - (setq expansion (concat abbrev expansion))) + + ;; If we upcased or downcased the original expansion, + ;; do likewise for the subsequent words when we copy them. + (and (equal abbrev " ") + dabbrev--last-case-pattern + (setq expansion + (funcall dabbrev--last-case-pattern expansion))) + ;; If the expansion has mixed case ;; and it is not simply a capitalized word, ;; or if the abbrev has mixed case, @@ -850,6 +847,16 @@ (setq use-case-replace nil)) (if use-case-replace (setq expansion (downcase expansion))) + + ;; In case we insert subsequent words, + ;; 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 + (and use-case-replace + (cond ((equal abbrev (upcase abbrev)) 'upcase) + ((equal abbrev (downcase abbrev)) 'downcase))))) + (if old (save-excursion (search-backward old))