comparison lisp/dabbrev.el @ 34596:51c08e149a23

(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.
author Gerd Moellmann <gerd@gnu.org>
date Fri, 15 Dec 2000 11:50:36 +0000
parents edb654a13bf1
children 4eb554667665
comparison
equal deleted inserted replaced
34595:5abdd701bf8d 34596:51c08e149a23
295 (defvar dabbrev--last-buffer-found nil) 295 (defvar dabbrev--last-buffer-found nil)
296 296
297 ;; The buffer we last did a completion in. 297 ;; The buffer we last did a completion in.
298 (defvar dabbrev--last-completion-buffer nil) 298 (defvar dabbrev--last-completion-buffer nil)
299 299
300 ;; Non-nil means we should upcase 300 ;; If non-nil, a function to use when copying successive words.
301 ;; when copying successive words. 301 ;; It should be `upcase' or `downcase'.
302 (defvar dabbrev--last-case-pattern nil) 302 (defvar dabbrev--last-case-pattern nil)
303 303
304 ;; Same as dabbrev-check-other-buffers, but is set for every expand. 304 ;; Same as dabbrev-check-other-buffers, but is set for every expand.
305 (defvar dabbrev--check-other-buffers dabbrev-check-other-buffers) 305 (defvar dabbrev--check-other-buffers dabbrev-check-other-buffers)
306 306
431 (not (string-equal (downcase init) (downcase abbrev)))) 431 (not (string-equal (downcase init) (downcase abbrev))))
432 (if (> (length (all-completions init my-obarray)) 1) 432 (if (> (length (all-completions init my-obarray)) 1)
433 (message "Repeat `%s' to see all completions" 433 (message "Repeat `%s' to see all completions"
434 (key-description (this-command-keys))) 434 (key-description (this-command-keys)))
435 (message "The only possible completion")) 435 (message "The only possible completion"))
436 (dabbrev--substitute-expansion nil abbrev init)) 436 (dabbrev--substitute-expansion nil abbrev init nil))
437 (t 437 (t
438 ;; * String is a common substring completion already. Make list. 438 ;; * String is a common substring completion already. Make list.
439 (message "Making completion list...") 439 (message "Making completion list...")
440 (with-output-to-temp-buffer " *Completions*" 440 (with-output-to-temp-buffer " *Completions*"
441 (display-completion-list (all-completions init my-obarray))) 441 (display-completion-list (all-completions init my-obarray)))
508 ;; as our expansion this time. 508 ;; as our expansion this time.
509 (re-search-forward 509 (re-search-forward
510 (concat "\\(\\(" dabbrev--abbrev-char-regexp "\\)+\\)")) 510 (concat "\\(\\(" dabbrev--abbrev-char-regexp "\\)+\\)"))
511 (setq expansion (buffer-substring-no-properties 511 (setq expansion (buffer-substring-no-properties
512 dabbrev--last-expansion-location (point))) 512 dabbrev--last-expansion-location (point)))
513 (if dabbrev--last-case-pattern
514 (setq expansion (upcase expansion)))
515 513
516 ;; Record the end of this expansion, in case we repeat this. 514 ;; Record the end of this expansion, in case we repeat this.
517 (setq dabbrev--last-expansion-location (point))) 515 (setq dabbrev--last-expansion-location (point)))
518 ;; Indicate that dabbrev--last-expansion-location is 516 ;; Indicate that dabbrev--last-expansion-location is
519 ;; at the end of the expansion. 517 ;; at the end of the expansion.
565 (and (> dabbrev--last-expansion-location (point)))) 563 (and (> dabbrev--last-expansion-location (point))))
566 (setq dabbrev--last-expansion-location 564 (setq dabbrev--last-expansion-location
567 (copy-marker dabbrev--last-expansion-location))) 565 (copy-marker dabbrev--last-expansion-location)))
568 ;; Success: stick it in and return. 566 ;; Success: stick it in and return.
569 (setq buffer-undo-list (cons orig-point buffer-undo-list)) 567 (setq buffer-undo-list (cons orig-point buffer-undo-list))
570 (dabbrev--substitute-expansion old abbrev expansion) 568 (dabbrev--substitute-expansion old abbrev expansion
571 569 record-case-pattern)
572 ;; If we are not copying successive words now,
573 ;; set dabbrev--last-case-pattern.
574 (and record-case-pattern
575 (setq dabbrev--last-case-pattern
576 (and (if (eq dabbrev-case-fold-search 'case-fold-search)
577 case-fold-search
578 dabbrev-case-fold-search)
579 (not dabbrev-upcase-means-case-search)
580 (equal abbrev (upcase abbrev)))))
581 570
582 ;; Save state for re-expand. 571 ;; Save state for re-expand.
583 (setq dabbrev--last-expansion expansion) 572 (setq dabbrev--last-expansion expansion)
584 (setq dabbrev--last-abbreviation abbrev) 573 (setq dabbrev--last-abbreviation abbrev)
585 (setq dabbrev--last-abbrev-location (point-marker)))))) 574 (setq dabbrev--last-abbrev-location (point-marker))))))
767 (let* (friend-buffer-list non-friend-buffer-list) 756 (let* (friend-buffer-list non-friend-buffer-list)
768 (setq dabbrev--friend-buffer-list 757 (setq dabbrev--friend-buffer-list
769 (funcall dabbrev-select-buffers-function)) 758 (funcall dabbrev-select-buffers-function))
770 (if dabbrev-check-all-buffers 759 (if dabbrev-check-all-buffers
771 (setq non-friend-buffer-list 760 (setq non-friend-buffer-list
772 (nreverse 761 (dabbrev-filter-elements
773 (dabbrev-filter-elements 762 buffer (buffer-list)
774 buffer (buffer-list) 763 (let ((bn (buffer-name buffer)))
775 (let ((bn (buffer-name buffer))) 764 (and (not (member bn dabbrev-ignored-buffer-names))
776 (and (not (member bn dabbrev-ignored-buffer-names)) 765 (not (memq buffer dabbrev--friend-buffer-list))
777 (not (memq buffer dabbrev--friend-buffer-list)) 766 (not
778 (not 767 (let ((tail dabbrev-ignored-regexps)
779 (let ((tail dabbrev-ignored-regexps) 768 (match nil))
780 (match nil)) 769 (while (and tail (not match))
781 (while (and tail (not match)) 770 (setq match (string-match (car tail) bn)
782 (setq match (string-match (car tail) bn) 771 tail (cdr tail)))
783 tail (cdr tail))) 772 match)))))
784 match))))))
785 dabbrev--friend-buffer-list 773 dabbrev--friend-buffer-list
786 (append dabbrev--friend-buffer-list 774 (append dabbrev--friend-buffer-list
787 non-friend-buffer-list))))) 775 non-friend-buffer-list)))))
788 ;; Move buffers that are visible on the screen 776 ;; Move buffers that are visible on the screen
789 ;; to the front of the list. Remove the current buffer. 777 ;; to the front of the list. Remove the current buffer.
812 (if (eq major-mode 'picture-mode) 800 (if (eq major-mode 'picture-mode)
813 (picture-replace-match string fixedcase literal) 801 (picture-replace-match string fixedcase literal)
814 (replace-match string fixedcase literal))) 802 (replace-match string fixedcase literal)))
815 803
816 ;;;---------------------------------------------------------------- 804 ;;;----------------------------------------------------------------
817 ;;; Substitute the current string in buffer with the expansion 805 (defun dabbrev--substitute-expansion (old abbrev expansion record-case-pattern)
818 ;;; OLD is nil or the last expansion substring. 806 "Replace OLD with EXPANSION in the buffer.
819 ;;; ABBREV is the abbreviation we are working with. 807 OLD is text currently in the buffer, perhaps the abbreviation
820 ;;; EXPANSION is the expansion substring. 808 or perhaps another expansion that was tried previously.
821 (defun dabbrev--substitute-expansion (old abbrev expansion) 809 ABBREV is the abbreviation we are expanding.
810 It is \" \" if we are copying subsequent words.
811 EXPANSION is the expansion substring to be used this time.
812 RECORD-CASE-PATTERN, if non-nil, means set `dabbrev--last-case-pattern'
813 to record whether we upcased the expansion, downcased it, or did neither."
822 ;;(undo-boundary) 814 ;;(undo-boundary)
823 (let ((use-case-replace (and (if (eq dabbrev-case-fold-search 'case-fold-search) 815 (let ((use-case-replace (and (if (eq dabbrev-case-fold-search 'case-fold-search)
824 case-fold-search 816 case-fold-search
825 dabbrev-case-fold-search) 817 dabbrev-case-fold-search)
826 (or (not dabbrev-upcase-means-case-search) 818 (or (not dabbrev-upcase-means-case-search)
827 (string= abbrev (downcase abbrev))) 819 (string= abbrev (downcase abbrev)))
828 (if (eq dabbrev-case-replace 'case-replace) 820 (if (eq dabbrev-case-replace 'case-replace)
829 case-replace 821 case-replace
830 dabbrev-case-replace)))) 822 dabbrev-case-replace))))
831 (and nil use-case-replace 823
832 (setq old (concat abbrev (or old ""))) 824 ;; If we upcased or downcased the original expansion,
833 (setq expansion (concat abbrev expansion))) 825 ;; do likewise for the subsequent words when we copy them.
826 (and (equal abbrev " ")
827 dabbrev--last-case-pattern
828 (setq expansion
829 (funcall dabbrev--last-case-pattern expansion)))
830
834 ;; If the expansion has mixed case 831 ;; If the expansion has mixed case
835 ;; and it is not simply a capitalized word, 832 ;; and it is not simply a capitalized word,
836 ;; or if the abbrev has mixed case, 833 ;; or if the abbrev has mixed case,
837 ;; and if the given abbrev's case pattern 834 ;; and if the given abbrev's case pattern
838 ;; matches the start of the expansion, 835 ;; matches the start of the expansion,
848 (setq use-case-replace nil))) 845 (setq use-case-replace nil)))
849 (if (equal abbrev " ") 846 (if (equal abbrev " ")
850 (setq use-case-replace nil)) 847 (setq use-case-replace nil))
851 (if use-case-replace 848 (if use-case-replace
852 (setq expansion (downcase expansion))) 849 (setq expansion (downcase expansion)))
850
851 ;; In case we insert subsequent words,
852 ;; record if we upcased or downcased the first word,
853 ;; in order to do likewise for subsequent words.
854 (and record-case-pattern
855 (setq dabbrev--last-case-pattern
856 (and use-case-replace
857 (cond ((equal abbrev (upcase abbrev)) 'upcase)
858 ((equal abbrev (downcase abbrev)) 'downcase)))))
859
853 (if old 860 (if old
854 (save-excursion 861 (save-excursion
855 (search-backward old)) 862 (search-backward old))
856 ;;(set-match-data (list (point-marker) (point-marker))) 863 ;;(set-match-data (list (point-marker) (point-marker)))
857 (search-backward abbrev)) 864 (search-backward abbrev))