diff options
| author | Richard M. Stallman | 1993-12-23 04:38:57 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1993-12-23 04:38:57 +0000 |
| commit | d1d1ddbd6ade29048745cc46cf9f4169678605c8 (patch) | |
| tree | adf64439073a5c20ce77846356aca2746fcd271f | |
| parent | 2368506ddc7b8614d38dc3b7ddf1de2ff62b46f5 (diff) | |
| download | emacs-d1d1ddbd6ade29048745cc46cf9f4169678605c8.tar.gz emacs-d1d1ddbd6ade29048745cc46cf9f4169678605c8.zip | |
(;; Keywords:): Changed to "abbrev".
(hippie-expand-ignore-buffers): New variable.
(he-regexp-member): New function.
(hippie-expand-try-functions-list): Added `try-expand-list'.
(try-expand-line-all-buffers, try-expand-list-all-buffers,
try-expand-dabbrev-all-buffers): Use `he-regexp-member' and
`hippie-expand-ignore-buffers'.
(he-list-search): Don't find list containing point.
(he-dab-search-regexp): Just match at beginning of words.
(he-dabbrev-beg): Never move point forward.
| -rw-r--r-- | lisp/hippie-exp.el | 66 |
1 files changed, 44 insertions, 22 deletions
diff --git a/lisp/hippie-exp.el b/lisp/hippie-exp.el index 9036427b2fa..65317f96a9d 100644 --- a/lisp/hippie-exp.el +++ b/lisp/hippie-exp.el | |||
| @@ -1,11 +1,11 @@ | |||
| 1 | ;;; hippie-exp.el --- expand text trying various ways to find its expansion. | 1 | ;;; hippie-exp.el --- expand text trying various ways to find its expansion. |
| 2 | 2 | ||
| 3 | ;; Author: Anders Holst <aho@sans.kth.se> | 3 | ;; Author: Anders Holst <aho@sans.kth.se> |
| 4 | ;; Last change: 22 June 1993 | 4 | ;; Last change: 2 September 1993 |
| 5 | ;; Version: 1.2 | 5 | ;; Version: 1.3 |
| 6 | ;; Keywords: extensions | 6 | ;; Keywords: abbrev |
| 7 | 7 | ||
| 8 | ;; Copyright (C) 1992 Free Software Foundation, Inc. | 8 | ;; Copyright (C) 1992, 1993 Free Software Foundation, Inc. |
| 9 | ;; | 9 | ;; |
| 10 | ;; This file is part of GNU Emacs. | 10 | ;; This file is part of GNU Emacs. |
| 11 | 11 | ||
| @@ -36,6 +36,7 @@ | |||
| 36 | ;; ARG functions forward in this list. Given some other argument | 36 | ;; ARG functions forward in this list. Given some other argument |
| 37 | ;; (a negative argument or just Ctrl-U) it undoes the tried | 37 | ;; (a negative argument or just Ctrl-U) it undoes the tried |
| 38 | ;; completion. | 38 | ;; completion. |
| 39 | ;; | ||
| 39 | ;; If the variable `hippie-expand-verbose' is non-nil, `hippie-expand' | 40 | ;; If the variable `hippie-expand-verbose' is non-nil, `hippie-expand' |
| 40 | ;; outputs in a message which try-function in the list that is used | 41 | ;; outputs in a message which try-function in the list that is used |
| 41 | ;; currently (ie. was used currently and will be tried first the next | 42 | ;; currently (ie. was used currently and will be tried first the next |
| @@ -43,6 +44,10 @@ | |||
| 43 | ;; The variable `hippie-expand-max-buffers' determines in how many | 44 | ;; The variable `hippie-expand-max-buffers' determines in how many |
| 44 | ;; buffers, apart from the current, to search for expansions in. It | 45 | ;; buffers, apart from the current, to search for expansions in. It |
| 45 | ;; is used by the try-functions named "-all-buffers". | 46 | ;; is used by the try-functions named "-all-buffers". |
| 47 | ;; The variable `hippie-expand-ignore-buffers' is a list of regexps | ||
| 48 | ;; matching buffer names (as strings) or major modes (as atoms) of | ||
| 49 | ;; buffers that should not be searched by the try-functions named | ||
| 50 | ;; "-all-buffers". | ||
| 46 | ;; See also the macro `make-hippie-expand-function' below. | 51 | ;; See also the macro `make-hippie-expand-function' below. |
| 47 | ;; | 52 | ;; |
| 48 | ;; A short description of the current try-functions in this file: | 53 | ;; A short description of the current try-functions in this file: |
| @@ -127,7 +132,7 @@ | |||
| 127 | ;; because different try-functions may try to complete different | 132 | ;; because different try-functions may try to complete different |
| 128 | ;; lengths of text, and thus put different amounts of the | 133 | ;; lengths of text, and thus put different amounts of the |
| 129 | ;; text in `he-try-table'. Anyway this seems to occur seldom enough not | 134 | ;; text in `he-try-table'. Anyway this seems to occur seldom enough not |
| 130 | ;; to be too disturbing. Also it should NOT bee possible for the | 135 | ;; to be too disturbing. Also it should NOT be possible for the |
| 131 | ;; opposite situation to occur, that `hippie-expand' misses some | 136 | ;; opposite situation to occur, that `hippie-expand' misses some |
| 132 | ;; suggestion because it thinks it has already tried it. | 137 | ;; suggestion because it thinks it has already tried it. |
| 133 | ;; | 138 | ;; |
| @@ -164,6 +169,7 @@ | |||
| 164 | ;;;###autoload | 169 | ;;;###autoload |
| 165 | (defvar hippie-expand-try-functions-list '(try-complete-file-name | 170 | (defvar hippie-expand-try-functions-list '(try-complete-file-name |
| 166 | try-expand-all-abbrevs | 171 | try-expand-all-abbrevs |
| 172 | try-expand-list | ||
| 167 | try-expand-line | 173 | try-expand-line |
| 168 | try-expand-dabbrev | 174 | try-expand-dabbrev |
| 169 | try-expand-dabbrev-all-buffers | 175 | try-expand-dabbrev-all-buffers |
| @@ -182,6 +188,12 @@ or insert functions in this list.") | |||
| 182 | If nil, all buffers are searched.") | 188 | If nil, all buffers are searched.") |
| 183 | 189 | ||
| 184 | ;;;###autoload | 190 | ;;;###autoload |
| 191 | (defvar hippie-expand-ignore-buffers '("^ \\*.*\\*$" dired-mode) | ||
| 192 | "*A list specifying which buffers not to search (if not current). | ||
| 193 | Can contain both regexps matching buffer names (as strings) and major modes | ||
| 194 | (as atoms)") | ||
| 195 | |||
| 196 | ;;;###autoload | ||
| 185 | (defun hippie-expand (arg) | 197 | (defun hippie-expand (arg) |
| 186 | "Try to expand text before point, using multiple methods. | 198 | "Try to expand text before point, using multiple methods. |
| 187 | The expansion functions in `hippie-expand-try-functions-list' are | 199 | The expansion functions in `hippie-expand-try-functions-list' are |
| @@ -295,6 +307,15 @@ undoes the expansion." | |||
| 295 | (setq lst (cdr lst))) | 307 | (setq lst (cdr lst))) |
| 296 | lst) | 308 | lst) |
| 297 | 309 | ||
| 310 | ;; Check if STR matches any regexp in LST. | ||
| 311 | ;; Ignore possible non-strings in LST. | ||
| 312 | (defun he-regexp-member (str lst) | ||
| 313 | (while (and lst | ||
| 314 | (or (not (stringp (car lst))) | ||
| 315 | (not (string-match (car lst) str)))) | ||
| 316 | (setq lst (cdr lst))) | ||
| 317 | lst) | ||
| 318 | |||
| 298 | ;; For the real hippie-expand enthusiast: A macro that makes it | 319 | ;; For the real hippie-expand enthusiast: A macro that makes it |
| 299 | ;; possible to use many functions like hippie-expand, but with | 320 | ;; possible to use many functions like hippie-expand, but with |
| 300 | ;; different try-functions-lists. | 321 | ;; different try-functions-lists. |
| @@ -527,10 +548,9 @@ string). It returns t if a new completion is found, nil otherwise." | |||
| 527 | (< he-searched-n-bufs hippie-expand-max-buffers))) | 548 | (< he-searched-n-bufs hippie-expand-max-buffers))) |
| 528 | (set-buffer (car he-search-bufs)) | 549 | (set-buffer (car he-search-bufs)) |
| 529 | (if (and (not (eq (current-buffer) buf)) | 550 | (if (and (not (eq (current-buffer) buf)) |
| 530 | (not (string-match " \\*Minibuf-[0-9]+\\*" | 551 | (not (memq major-mode hippie-expand-ignore-buffers)) |
| 531 | (buffer-name (current-buffer)))) | 552 | (not (he-regexp-member (buffer-name) |
| 532 | (not (eq major-mode 'dired-mode))) | 553 | hippie-expand-ignore-buffers))) |
| 533 | ;; Dont search minibuffers nor dired buffers | ||
| 534 | (save-excursion | 554 | (save-excursion |
| 535 | (goto-char he-search-loc) | 555 | (goto-char he-search-loc) |
| 536 | (setq strip-prompt (and (get-buffer-process (current-buffer)) | 556 | (setq strip-prompt (and (get-buffer-process (current-buffer)) |
| @@ -650,10 +670,9 @@ string). It returns t if a new completion is found, nil otherwise." | |||
| 650 | (< he-searched-n-bufs hippie-expand-max-buffers))) | 670 | (< he-searched-n-bufs hippie-expand-max-buffers))) |
| 651 | (set-buffer (car he-search-bufs)) | 671 | (set-buffer (car he-search-bufs)) |
| 652 | (if (and (not (eq (current-buffer) buf)) | 672 | (if (and (not (eq (current-buffer) buf)) |
| 653 | (not (string-match " \\*Minibuf-[0-9]+\\*" | 673 | (not (memq major-mode hippie-expand-ignore-buffers)) |
| 654 | (buffer-name (current-buffer)))) | 674 | (not (he-regexp-member (buffer-name) |
| 655 | (not (eq major-mode 'dired-mode))) | 675 | hippie-expand-ignore-buffers))) |
| 656 | ;; Dont search minibuffers nor dired buffers | ||
| 657 | (save-excursion | 676 | (save-excursion |
| 658 | (goto-char he-search-loc) | 677 | (goto-char he-search-loc) |
| 659 | (setq expansion (he-list-search he-search-string nil)) | 678 | (setq expansion (he-list-search he-search-string nil)) |
| @@ -689,6 +708,9 @@ string). It returns t if a new completion is found, nil otherwise." | |||
| 689 | (condition-case () | 708 | (condition-case () |
| 690 | (forward-list 1) | 709 | (forward-list 1) |
| 691 | (error (setq err t))) | 710 | (error (setq err t))) |
| 711 | (if (and reverse | ||
| 712 | (> (point) he-string-beg)) | ||
| 713 | (setq err t)) | ||
| 692 | (if (not err) | 714 | (if (not err) |
| 693 | (progn | 715 | (progn |
| 694 | (setq result (buffer-substring beg (point))) | 716 | (setq result (buffer-substring beg (point))) |
| @@ -795,10 +817,9 @@ string). It returns t if a new expansion is found, nil otherwise." | |||
| 795 | (< he-searched-n-bufs hippie-expand-max-buffers))) | 817 | (< he-searched-n-bufs hippie-expand-max-buffers))) |
| 796 | (set-buffer (car he-search-bufs)) | 818 | (set-buffer (car he-search-bufs)) |
| 797 | (if (and (not (eq (current-buffer) buf)) | 819 | (if (and (not (eq (current-buffer) buf)) |
| 798 | (not (string-match " \\*Minibuf-[0-9]+\\*" | 820 | (not (memq major-mode hippie-expand-ignore-buffers)) |
| 799 | (buffer-name (current-buffer)))) | 821 | (not (he-regexp-member (buffer-name) |
| 800 | (not (eq major-mode 'dired-mode))) | 822 | hippie-expand-ignore-buffers))) |
| 801 | ;; Dont search minibuffers nor dired buffers | ||
| 802 | (save-excursion | 823 | (save-excursion |
| 803 | (goto-char he-search-loc) | 824 | (goto-char he-search-loc) |
| 804 | (setq expansion (he-dab-search he-search-string nil)) | 825 | (setq expansion (he-dab-search he-search-string nil)) |
| @@ -821,7 +842,7 @@ string). It returns t if a new expansion is found, nil otherwise." | |||
| 821 | t)))) | 842 | t)))) |
| 822 | 843 | ||
| 823 | (defun he-dab-search-regexp (pat) | 844 | (defun he-dab-search-regexp (pat) |
| 824 | (concat "\\b" (regexp-quote pat) | 845 | (concat "\\<" (regexp-quote pat) |
| 825 | "\\(\\sw\\|\\s_\\)+")) | 846 | "\\(\\sw\\|\\s_\\)+")) |
| 826 | 847 | ||
| 827 | (defun he-dab-search (pattern reverse) | 848 | (defun he-dab-search (pattern reverse) |
| @@ -838,10 +859,11 @@ string). It returns t if a new expansion is found, nil otherwise." | |||
| 838 | result)) | 859 | result)) |
| 839 | 860 | ||
| 840 | (defun he-dabbrev-beg () | 861 | (defun he-dabbrev-beg () |
| 841 | (save-excursion | 862 | (min (point) |
| 842 | (skip-syntax-backward "w_") | 863 | (save-excursion |
| 843 | (skip-syntax-forward "_") | 864 | (skip-syntax-backward "w_") |
| 844 | (point))) | 865 | (skip-syntax-forward "_") |
| 866 | (point)))) | ||
| 845 | 867 | ||
| 846 | (provide 'hippie-exp) | 868 | (provide 'hippie-exp) |
| 847 | 869 | ||