diff options
| -rw-r--r-- | lisp/dabbrev.el | 89 |
1 files changed, 59 insertions, 30 deletions
diff --git a/lisp/dabbrev.el b/lisp/dabbrev.el index 62c3befa908..4187d361eb1 100644 --- a/lisp/dabbrev.el +++ b/lisp/dabbrev.el | |||
| @@ -128,6 +128,12 @@ Set this to nil if no characters should be skipped." | |||
| 128 | (const :tag "off" nil)) | 128 | (const :tag "off" nil)) |
| 129 | :group 'dabbrev) | 129 | :group 'dabbrev) |
| 130 | 130 | ||
| 131 | (defcustom dabbrev--eliminate-newlines t | ||
| 132 | "*Non-nil means dabbrev should not insert newlines. | ||
| 133 | Instead it converts them to spaces." | ||
| 134 | :type 'boolean | ||
| 135 | :group 'dabbrev) | ||
| 136 | |||
| 131 | (defcustom dabbrev-case-fold-search 'case-fold-search | 137 | (defcustom dabbrev-case-fold-search 'case-fold-search |
| 132 | "*Control whether dabbrev searches should ignore case. | 138 | "*Control whether dabbrev searches should ignore case. |
| 133 | A value of nil means case is significant. | 139 | A value of nil means case is significant. |
| @@ -648,8 +654,6 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." | |||
| 648 | "\\sw\\|\\s_") | 654 | "\\sw\\|\\s_") |
| 649 | dabbrev--check-other-buffers dabbrev-check-other-buffers)) | 655 | dabbrev--check-other-buffers dabbrev-check-other-buffers)) |
| 650 | 656 | ||
| 651 | ;;; Find all buffers that are considered "friends" according to the | ||
| 652 | ;;; function pointed out by dabbrev-friend-buffer-function. | ||
| 653 | (defun dabbrev--select-buffers () | 657 | (defun dabbrev--select-buffers () |
| 654 | "Return a list of all buffers that should be searched for a possible abbrev. | 658 | "Return a list of all buffers that should be searched for a possible abbrev. |
| 655 | 659 | ||
| @@ -666,9 +670,11 @@ if it is bound, returns nil. The resulting partial list is returned." | |||
| 666 | (boundp 'dabbrev-friend-buffer-function) | 670 | (boundp 'dabbrev-friend-buffer-function) |
| 667 | (funcall dabbrev-friend-buffer-function buffer)))))) | 671 | (funcall dabbrev-friend-buffer-function buffer)))))) |
| 668 | 672 | ||
| 669 | ;;; Search for ABBREV, N times, normally looking forward, | ||
| 670 | ;;; but looking in reverse instead if REVERSE is non-nil. | ||
| 671 | (defun dabbrev--try-find (abbrev reverse n ignore-case) | 673 | (defun dabbrev--try-find (abbrev reverse n ignore-case) |
| 674 | "Search for ABBREV, backwards if REVERSE, N times. | ||
| 675 | If IGNORE-CASE is non-nil, ignore case while searching. | ||
| 676 | Return the expansion found, and save the location of the start | ||
| 677 | of the expansion in `dabbrev--last-expansion-location'." | ||
| 672 | (save-excursion | 678 | (save-excursion |
| 673 | (save-restriction | 679 | (save-restriction |
| 674 | (widen) | 680 | (widen) |
| @@ -686,8 +692,9 @@ if it is bound, returns nil. The resulting partial list is returned." | |||
| 686 | (setq dabbrev--last-expansion-location (point))) | 692 | (setq dabbrev--last-expansion-location (point))) |
| 687 | expansion)))) | 693 | expansion)))) |
| 688 | 694 | ||
| 689 | ;;; Find all expansions of ABBREV | ||
| 690 | (defun dabbrev--find-all-expansions (abbrev ignore-case) | 695 | (defun dabbrev--find-all-expansions (abbrev ignore-case) |
| 696 | "Return a list of all possible expansions of ABBREV. | ||
| 697 | If IGNORE-CASE is non-nil, accept matches which differ in case." | ||
| 691 | (let ((all-expansions nil) | 698 | (let ((all-expansions nil) |
| 692 | expansion) | 699 | expansion) |
| 693 | (save-excursion | 700 | (save-excursion |
| @@ -699,12 +706,16 @@ if it is bound, returns nil. The resulting partial list is returned." | |||
| 699 | (defun dabbrev--scanning-message () | 706 | (defun dabbrev--scanning-message () |
| 700 | (message "Scanning `%s'" (buffer-name (current-buffer)))) | 707 | (message "Scanning `%s'" (buffer-name (current-buffer)))) |
| 701 | 708 | ||
| 702 | ;;; Find one occasion of ABBREV. | ||
| 703 | ;;; DIRECTION > 0 means look that many times backwards. | ||
| 704 | ;;; DIRECTION < 0 means look that many times forward. | ||
| 705 | ;;; DIRECTION = 0 means try both backward and forward. | ||
| 706 | ;;; IGNORE-CASE non-nil means ignore case when searching. | ||
| 707 | (defun dabbrev--find-expansion (abbrev direction ignore-case) | 709 | (defun dabbrev--find-expansion (abbrev direction ignore-case) |
| 710 | "Find one occurrence of ABBREV, and return the expansion. | ||
| 711 | DIRECTION > 0 means look that many times backwards. | ||
| 712 | DIRECTION < 0 means look that many times forward. | ||
| 713 | DIRECTION = 0 means try both backward and forward. | ||
| 714 | IGNORE-CASE non-nil means ignore case when searching. | ||
| 715 | This sets `dabbrev--last-direction' to 1 or -1 according | ||
| 716 | to the direction in which the occurrence was actually found. | ||
| 717 | It sets `dabbrev--last-expansion-location' to the location | ||
| 718 | of the start of the occurrence." | ||
| 708 | (let (expansion) | 719 | (let (expansion) |
| 709 | (save-excursion | 720 | (save-excursion |
| 710 | (cond | 721 | (cond |
| @@ -828,10 +839,12 @@ to record whether we upcased the expansion, downcased it, or did neither." | |||
| 828 | 839 | ||
| 829 | ;; If we upcased or downcased the original expansion, | 840 | ;; If we upcased or downcased the original expansion, |
| 830 | ;; do likewise for the subsequent words when we copy them. | 841 | ;; do likewise for the subsequent words when we copy them. |
| 831 | (and (equal abbrev " ") | 842 | ;; Don't do any of the usual case processing, though. |
| 832 | dabbrev--last-case-pattern | 843 | (when (equal abbrev " ") |
| 833 | (setq expansion | 844 | (if dabbrev--last-case-pattern |
| 834 | (funcall dabbrev--last-case-pattern expansion))) | 845 | (setq expansion |
| 846 | (funcall dabbrev--last-case-pattern expansion))) | ||
| 847 | (setq use-case-replace nil)) | ||
| 835 | 848 | ||
| 836 | ;; If the expansion has mixed case | 849 | ;; If the expansion has mixed case |
| 837 | ;; and it is not simply a capitalized word, | 850 | ;; and it is not simply a capitalized word, |
| @@ -852,8 +865,15 @@ to record whether we upcased the expansion, downcased it, or did neither." | |||
| 852 | (string= abbrev | 865 | (string= abbrev |
| 853 | (substring expansion 0 (length abbrev)))) | 866 | (substring expansion 0 (length abbrev)))) |
| 854 | (setq use-case-replace nil))) | 867 | (setq use-case-replace nil))) |
| 855 | (if (equal abbrev " ") | 868 | |
| 869 | ;; If the abbrev and the expansion are both all-lower-case | ||
| 870 | ;; then don't do any conversion. The conversion would be a no-op | ||
| 871 | ;; for this replacement, but it would carry forward to subsequent words. | ||
| 872 | ;; The goal of this is to preven that carrying forward. | ||
| 873 | (if (and (string= expansion (downcase expansion)) | ||
| 874 | (string= abbrev (downcase abbrev))) | ||
| 856 | (setq use-case-replace nil)) | 875 | (setq use-case-replace nil)) |
| 876 | |||
| 857 | (if use-case-replace | 877 | (if use-case-replace |
| 858 | (setq expansion (downcase expansion))) | 878 | (setq expansion (downcase expansion))) |
| 859 | 879 | ||
| @@ -866,11 +886,18 @@ to record whether we upcased the expansion, downcased it, or did neither." | |||
| 866 | (cond ((equal abbrev (upcase abbrev)) 'upcase) | 886 | (cond ((equal abbrev (upcase abbrev)) 'upcase) |
| 867 | ((equal abbrev (downcase abbrev)) 'downcase))))) | 887 | ((equal abbrev (downcase abbrev)) 'downcase))))) |
| 868 | 888 | ||
| 889 | ;; Convert newlines to spaces. | ||
| 890 | (if dabbrev--eliminate-newlines | ||
| 891 | (while (string-match "\n" expansion) | ||
| 892 | (setq expansion (replace-match " " nil nil expansion)))) | ||
| 893 | |||
| 869 | (if old | 894 | (if old |
| 870 | (save-excursion | 895 | (save-excursion |
| 871 | (search-backward old)) | 896 | (search-backward old)) |
| 872 | ;;(set-match-data (list (point-marker) (point-marker))) | 897 | ;;(set-match-data (list (point-marker) (point-marker))) |
| 873 | (search-backward abbrev)) | 898 | (search-backward abbrev) |
| 899 | (search-forward abbrev)) | ||
| 900 | |||
| 874 | ;; Make case of replacement conform to case of abbreviation | 901 | ;; Make case of replacement conform to case of abbreviation |
| 875 | ;; provided (1) that kind of thing is enabled in this buffer | 902 | ;; provided (1) that kind of thing is enabled in this buffer |
| 876 | ;; and (2) the replacement itself is all lower case. | 903 | ;; and (2) the replacement itself is all lower case. |
| @@ -882,22 +909,24 @@ to record whether we upcased the expansion, downcased it, or did neither." | |||
| 882 | ;;;---------------------------------------------------------------- | 909 | ;;;---------------------------------------------------------------- |
| 883 | ;;; Search function used by dabbrevs library. | 910 | ;;; Search function used by dabbrevs library. |
| 884 | 911 | ||
| 885 | ;;; ABBREV is string to find as prefix of word. Second arg, REVERSE, | ||
| 886 | ;;; is t for reverse search, nil for forward. Variable dabbrev-limit | ||
| 887 | ;;; controls the maximum search region size. Third argument IGNORE-CASE | ||
| 888 | ;;; non-nil means treat case as insignificant while looking for a match | ||
| 889 | ;;; and when comparing with previous matches. Also if that's non-nil | ||
| 890 | ;;; and the match is found at the beginning of a sentence and is in | ||
| 891 | ;;; lower case except for the initial then it is converted to all lower | ||
| 892 | ;;; case for return. | ||
| 893 | |||
| 894 | ;;; Table of expansions already seen is examined in buffer | ||
| 895 | ;;; `dabbrev--last-table' so that only distinct possibilities are found | ||
| 896 | ;;; by dabbrev-re-expand. | ||
| 897 | |||
| 898 | ;;; Value is the expansion, or nil if not found. | ||
| 899 | 912 | ||
| 900 | (defun dabbrev--search (abbrev reverse ignore-case) | 913 | (defun dabbrev--search (abbrev reverse ignore-case) |
| 914 | "Search for something that could be used to expand ABBREV. | ||
| 915 | |||
| 916 | Second arg, REVERSE, is t for reverse search, nil for forward. | ||
| 917 | The variable `dabbrev-limit' controls the maximum search region size. | ||
| 918 | Third argument IGNORE-CASE non-nil means treat case as insignificant while | ||
| 919 | looking for a match and when comparing with previous matches. Also if | ||
| 920 | that's non-nil and the match is found at the beginning of a sentence | ||
| 921 | and is in lower case except for the initial then it is converted to | ||
| 922 | all lower case for return. | ||
| 923 | |||
| 924 | Table of expansions already seen is examined in buffer | ||
| 925 | `dabbrev--last-table' so that only distinct possibilities are found | ||
| 926 | by dabbrev-re-expand. | ||
| 927 | |||
| 928 | Returns the expansion found, or nil if not found. | ||
| 929 | Leaves point at the location of the start of the expansion." | ||
| 901 | (save-match-data | 930 | (save-match-data |
| 902 | (let ((pattern1 (concat (regexp-quote abbrev) | 931 | (let ((pattern1 (concat (regexp-quote abbrev) |
| 903 | "\\(" dabbrev--abbrev-char-regexp "\\)")) | 932 | "\\(" dabbrev--abbrev-char-regexp "\\)")) |