Mercurial > emacs
comparison lisp/hippie-exp.el @ 21131:e4acb217b4af
(hippie-expand-dabbrev-skip-space): Renamed `he-dabbrev-skip-space'.
(hippie-expand-dabbrev-as-symbol): Renamed `he-dabbrev-as-symbol'.
(hippie-expand-no-restriction): New variable.
(hippie-expand-only-buffers): New variable.
(he-init-string,he-line-search,he-list-search,he-dabbrev-search): Use
`buffer-substring-no-properties' to avoid transfer of text properties.
(he-dabbrev-kill-search,he-whole-kill-search): Remove text properties
from search result.
(he-regexp-member): Removed function.
(he-buffer-member): New function used instead of `he-regexp-member'.
(try-expand-line,try-expand-line-all-buffers,try-expand-list,
try-expand-list-all-buffers,try-expand-dabbrev,
try-expand-dabbrev-all-buffers): Depending on
`hippie-expand-no-restriction', widen the buffer before search.
(try-expand-line-all-buffers,try-expand-list-all-buffers,
try-expand-dabbrev-all-buffers): Use `he-buffer-member' and
`hippie-expand-only-buffers'.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 10 Mar 1998 18:30:07 +0000 |
parents | aea386116817 |
children | a77d473867b8 |
comparison
equal
deleted
inserted
replaced
21130:60e882bbb28b | 21131:e4acb217b4af |
---|---|
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 ;; Copyright (C) 1992 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1992 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: Anders Holst <aho@sans.kth.se> | 5 ;; Author: Anders Holst <aho@sans.kth.se> |
6 ;; Last change: 28 May 1997 | 6 ;; Last change: 3 March 1998 |
7 ;; Version: 1.5 | 7 ;; Version: 1.6 |
8 ;; Keywords: abbrev | 8 ;; Keywords: abbrev |
9 | 9 |
10 ;; This file is part of GNU Emacs. | 10 ;; This file is part of GNU Emacs. |
11 | 11 |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | 12 ;; GNU Emacs is free software; you can redistribute it and/or modify |
47 ;; is used by the try-functions named "-all-buffers". | 47 ;; is used by the try-functions named "-all-buffers". |
48 ;; The variable `hippie-expand-ignore-buffers' is a list of regexps | 48 ;; The variable `hippie-expand-ignore-buffers' is a list of regexps |
49 ;; matching buffer names (as strings) or major modes (as atoms) of | 49 ;; matching buffer names (as strings) or major modes (as atoms) of |
50 ;; buffers that should not be searched by the try-functions named | 50 ;; buffers that should not be searched by the try-functions named |
51 ;; "-all-buffers". | 51 ;; "-all-buffers". |
52 ;; If set, the variable `hippie-expand-only-buffers' does the opposite | |
53 ;; of `hippie-expand-ignore-buffers', in that the search is restricted | |
54 ;; to only the kind of buffers listed. | |
55 ;; If the variable `hippie-expand-no-restriction' is non-nil, narrowed | |
56 ;; buffers are widened before they are searched. | |
57 ;; The variable `hippie-expand-dabbrev-skip-space' controls whether | |
58 ;; trailing spaces will be included in the abbreviation to search for, | |
59 ;; which then gives the same behavior as the original `dabbrev-expand'. | |
60 ;; The variable `hippie-expand-dabbrev-as-symbol' controls whether | |
61 ;; characters of syntax '_' is considered part of the words to expand | |
62 ;; dynamically. | |
52 ;; See also the macro `make-hippie-expand-function' below. | 63 ;; See also the macro `make-hippie-expand-function' below. |
53 ;; | 64 ;; |
54 ;; A short description of the current try-functions in this file: | 65 ;; A short description of the current try-functions in this file: |
55 ;; `try-complete-file-name' : very convenient to have in any buffer, | 66 ;; `try-complete-file-name' : very convenient to have in any buffer, |
56 ;; and not just in the minibuffer or (some) shell-mode. It goes | 67 ;; and not just in the minibuffer or (some) shell-mode. It goes |
159 | 170 |
160 (defgroup hippie-expand nil | 171 (defgroup hippie-expand nil |
161 "Expand text trying various ways to find its expansion." | 172 "Expand text trying various ways to find its expansion." |
162 :group 'abbrev) | 173 :group 'abbrev) |
163 | 174 |
164 (defcustom he-dabbrev-skip-space nil | |
165 "Non-nil means tolerate trailing spaces in the abbreviation to expand." | |
166 :group 'hippie-expand | |
167 :type 'boolean) | |
168 | |
169 (defcustom he-dabbrev-as-symbol t | |
170 "Non-nil means expand as symbols, i.e. syntax `_' is considered a letter." | |
171 :group 'hippie-expand | |
172 :type 'boolean) | |
173 | |
174 (defvar he-num -1) | 175 (defvar he-num -1) |
175 | 176 |
176 (defvar he-string-beg (make-marker)) | 177 (defvar he-string-beg (make-marker)) |
177 | 178 |
178 (defvar he-string-end (make-marker)) | 179 (defvar he-string-end (make-marker)) |
215 "*Non-nil makes `hippie-expand' output which function it is trying." | 216 "*Non-nil makes `hippie-expand' output which function it is trying." |
216 :type 'boolean | 217 :type 'boolean |
217 :group 'hippie-expand) | 218 :group 'hippie-expand) |
218 | 219 |
219 ;;;###autoload | 220 ;;;###autoload |
221 (defcustom hippie-expand-dabbrev-skip-space nil | |
222 "*Non-nil means tolerate trailing spaces in the abbreviation to expand." | |
223 :group 'hippie-expand | |
224 :type 'boolean) | |
225 | |
226 ;;;###autoload | |
227 (defcustom hippie-expand-dabbrev-as-symbol t | |
228 "*Non-nil means expand as symbols, i.e. syntax `_' is considered a letter." | |
229 :group 'hippie-expand | |
230 :type 'boolean) | |
231 | |
232 ;;;###autoload | |
233 (defcustom hippie-expand-no-restriction t | |
234 "*Non-nil means that narrowed buffers are widened during search." | |
235 :group 'hippie-expand | |
236 :type 'boolean) | |
237 | |
238 ;;;###autoload | |
220 (defcustom hippie-expand-max-buffers () | 239 (defcustom hippie-expand-max-buffers () |
221 "*The maximum number of buffers (apart from the current) searched. | 240 "*The maximum number of buffers (apart from the current) searched. |
222 If nil, all buffers are searched." | 241 If nil, all buffers are searched." |
223 :type '(choice (const :tag "All" nil) | 242 :type '(choice (const :tag "All" nil) |
224 integer) | 243 integer) |
227 ;;;###autoload | 246 ;;;###autoload |
228 (defcustom hippie-expand-ignore-buffers '("^ \\*.*\\*$" dired-mode) | 247 (defcustom hippie-expand-ignore-buffers '("^ \\*.*\\*$" dired-mode) |
229 "*A list specifying which buffers not to search (if not current). | 248 "*A list specifying which buffers not to search (if not current). |
230 Can contain both regexps matching buffer names (as strings) and major modes | 249 Can contain both regexps matching buffer names (as strings) and major modes |
231 \(as atoms)" | 250 \(as atoms)" |
251 :type '(repeat (choice regexp (symbol :tag "Major Mode"))) | |
252 :group 'hippie-expand) | |
253 | |
254 ;;;###autoload | |
255 (defcustom hippie-expand-only-buffers () | |
256 "*A list specifying the only buffers to search (in addition to current). | |
257 Can contain both regexps matching buffer names (as strings) and major modes | |
258 \(as atoms). If non-NIL, this variable overrides the variable | |
259 `hippie-expand-ignore-buffers'." | |
232 :type '(repeat (choice regexp (symbol :tag "Major Mode"))) | 260 :type '(repeat (choice regexp (symbol :tag "Major Mode"))) |
233 :group 'hippie-expand) | 261 :group 'hippie-expand) |
234 | 262 |
235 ;;;###autoload | 263 ;;;###autoload |
236 (defun hippie-expand (arg) | 264 (defun hippie-expand (arg) |
268 (message "No further expansions found")) | 296 (message "No further expansions found")) |
269 (ding)) | 297 (ding)) |
270 (if (and hippie-expand-verbose | 298 (if (and hippie-expand-verbose |
271 (not (window-minibuffer-p (selected-window)))) | 299 (not (window-minibuffer-p (selected-window)))) |
272 (message "Using %s" | 300 (message "Using %s" |
273 (nth he-num hippie-expand-try-functions-list))))) | 301 (nth he-num hippie-expand-try-functions-list))))) |
274 (if (and (>= he-num 0) | 302 (if (and (>= he-num 0) |
275 (eq (marker-buffer he-string-beg) (current-buffer))) | 303 (eq (marker-buffer he-string-beg) (current-buffer))) |
276 (progn | 304 (progn |
277 (setq he-num -1) | 305 (setq he-num -1) |
278 (he-reset-string) | 306 (he-reset-string) |
282 | 310 |
283 ;; Initializes the region to expand (to between BEG and END). | 311 ;; Initializes the region to expand (to between BEG and END). |
284 (defun he-init-string (beg end) | 312 (defun he-init-string (beg end) |
285 (set-marker he-string-beg beg) | 313 (set-marker he-string-beg beg) |
286 (set-marker he-string-end end) | 314 (set-marker he-string-end end) |
287 (setq he-search-string (buffer-substring beg end))) | 315 (setq he-search-string (buffer-substring-no-properties beg end))) |
288 | 316 |
289 ;; Resets the expanded region to its original contents. | 317 ;; Resets the expanded region to its original contents. |
290 (defun he-reset-string () | 318 (defun he-reset-string () |
291 (let ((newpos (point-marker))) | 319 (let ((newpos (point-marker))) |
292 (goto-char he-string-beg) | 320 (goto-char he-string-beg) |
354 case-fold-search) | 382 case-fold-search) |
355 (he-transfer-case he-search-string str) | 383 (he-transfer-case he-search-string str) |
356 str) | 384 str) |
357 lst))) | 385 lst))) |
358 | 386 |
359 ;; Check if STR matches any regexp in LST. | 387 ;; Check if current buffer matches any atom or regexp in LST. |
360 ;; Ignore possible non-strings in LST. | 388 ;; Atoms are interpreted as major modes, strings as regexps mathing the name. |
361 (defun he-regexp-member (str lst) | 389 (defun he-buffer-member (lst) |
362 (while (and lst | 390 (or (memq major-mode lst) |
363 (or (not (stringp (car lst))) | 391 (progn |
364 (not (string-match (car lst) str)))) | 392 (while (and lst |
365 (setq lst (cdr lst))) | 393 (or (not (stringp (car lst))) |
366 lst) | 394 (not (string-match (car lst) (buffer-name))))) |
395 (setq lst (cdr lst))) | |
396 lst))) | |
367 | 397 |
368 ;; For the real hippie-expand enthusiast: A macro that makes it | 398 ;; For the real hippie-expand enthusiast: A macro that makes it |
369 ;; possible to use many functions like hippie-expand, but with | 399 ;; possible to use many functions like hippie-expand, but with |
370 ;; different try-functions-lists. | 400 ;; different try-functions-lists. |
371 ;; Usage is for example: | 401 ;; Usage is for example: |
474 (defun he-file-name-beg () | 504 (defun he-file-name-beg () |
475 (let ((op (point))) | 505 (let ((op (point))) |
476 (save-excursion | 506 (save-excursion |
477 (skip-chars-backward he-file-name-chars) | 507 (skip-chars-backward he-file-name-chars) |
478 (if (> (skip-syntax-backward "w") 0) ;; No words with non-file chars | 508 (if (> (skip-syntax-backward "w") 0) ;; No words with non-file chars |
479 op | 509 op |
480 (point))))) | 510 (point))))) |
481 | 511 |
482 ;; Thanks go to Richard Levitte <levitte@e.kth.se> who helped to make these | 512 ;; Thanks go to Richard Levitte <levitte@e.kth.se> who helped to make these |
483 ;; work under VMS, and to David Hughes <ukchugd@ukpmr.cs.philips.nl> who | 513 ;; work under VMS, and to David Hughes <ukchugd@ukpmr.cs.philips.nl> who |
484 ;; helped to make it work on PC. | 514 ;; helped to make it work on PC. |
485 (defun he-file-name-nondirectory (file) | 515 (defun he-file-name-nondirectory (file) |
603 (set-marker he-search-loc he-string-beg) | 633 (set-marker he-search-loc he-string-beg) |
604 (setq he-search-bw t))) | 634 (setq he-search-bw t))) |
605 | 635 |
606 (if (not (equal he-search-string "")) | 636 (if (not (equal he-search-string "")) |
607 (save-excursion | 637 (save-excursion |
608 ;; Try looking backward unless inhibited. | 638 (save-restriction |
609 (if he-search-bw | 639 (if hippie-expand-no-restriction |
610 (progn | 640 (widen)) |
611 (goto-char he-search-loc) | 641 ;; Try looking backward unless inhibited. |
612 (setq expansion (he-line-search he-search-string | 642 (if he-search-bw |
613 strip-prompt t)) | 643 (progn |
614 (set-marker he-search-loc (point)) | 644 (goto-char he-search-loc) |
615 (if (not expansion) | 645 (setq expansion (he-line-search he-search-string |
616 (progn | 646 strip-prompt t)) |
617 (set-marker he-search-loc he-string-end) | 647 (set-marker he-search-loc (point)) |
618 (setq he-search-bw ()))))) | 648 (if (not expansion) |
619 | 649 (progn |
620 (if (not expansion) ; Then look forward. | 650 (set-marker he-search-loc he-string-end) |
621 (progn | 651 (setq he-search-bw ()))))) |
622 (goto-char he-search-loc) | 652 |
623 (setq expansion (he-line-search he-search-string | 653 (if (not expansion) ; Then look forward. |
624 strip-prompt nil)) | 654 (progn |
625 (set-marker he-search-loc (point)))))) | 655 (goto-char he-search-loc) |
656 (setq expansion (he-line-search he-search-string | |
657 strip-prompt nil)) | |
658 (set-marker he-search-loc (point))))))) | |
626 | 659 |
627 (if (not expansion) | 660 (if (not expansion) |
628 (progn | 661 (progn |
629 (if old (he-reset-string)) | 662 (if old (he-reset-string)) |
630 ()) | 663 ()) |
654 (not expansion) | 687 (not expansion) |
655 (or (not hippie-expand-max-buffers) | 688 (or (not hippie-expand-max-buffers) |
656 (< he-searched-n-bufs hippie-expand-max-buffers))) | 689 (< he-searched-n-bufs hippie-expand-max-buffers))) |
657 (set-buffer (car he-search-bufs)) | 690 (set-buffer (car he-search-bufs)) |
658 (if (and (not (eq (current-buffer) buf)) | 691 (if (and (not (eq (current-buffer) buf)) |
659 (not (memq major-mode hippie-expand-ignore-buffers)) | 692 (if hippie-expand-only-buffers |
660 (not (he-regexp-member (buffer-name) | 693 (he-buffer-member hippie-expand-only-buffers) |
661 hippie-expand-ignore-buffers))) | 694 (not (he-buffer-member hippie-expand-ignore-buffers)))) |
662 (save-excursion | 695 (save-excursion |
663 (goto-char he-search-loc) | 696 (save-restriction |
664 (setq strip-prompt (and (get-buffer-process (current-buffer)) | 697 (if hippie-expand-no-restriction |
665 comint-prompt-regexp)) | 698 (widen)) |
666 (setq expansion (let ((case-fold-search orig-case-fold-search)) | 699 (goto-char he-search-loc) |
667 (he-line-search he-search-string | 700 (setq strip-prompt (and (get-buffer-process (current-buffer)) |
668 strip-prompt nil))) | 701 comint-prompt-regexp)) |
669 (set-marker he-search-loc (point)) | 702 (setq expansion |
670 (if (not expansion) | 703 (let ((case-fold-search orig-case-fold-search)) |
671 (progn | 704 (he-line-search he-search-string |
672 (setq he-search-bufs (cdr he-search-bufs)) | 705 strip-prompt nil))) |
673 (setq he-searched-n-bufs (1+ he-searched-n-bufs)) | 706 (set-marker he-search-loc (point)) |
674 (set-marker he-search-loc 1 (car he-search-bufs))))) | 707 (if (not expansion) |
708 (progn | |
709 (setq he-search-bufs (cdr he-search-bufs)) | |
710 (setq he-searched-n-bufs (1+ he-searched-n-bufs)) | |
711 (set-marker he-search-loc 1 (car he-search-bufs)))))) | |
675 (setq he-search-bufs (cdr he-search-bufs)) | 712 (setq he-search-bufs (cdr he-search-bufs)) |
676 (set-marker he-search-loc 1 (car he-search-bufs))))) | 713 (set-marker he-search-loc 1 (car he-search-bufs))))) |
677 | 714 |
678 (set-buffer buf) | 715 (set-buffer buf) |
679 (if (not expansion) | 716 (if (not expansion) |
692 (he-line-search-regexp str strip-prompt) | 729 (he-line-search-regexp str strip-prompt) |
693 nil t) | 730 nil t) |
694 (re-search-forward | 731 (re-search-forward |
695 (he-line-search-regexp str strip-prompt) | 732 (he-line-search-regexp str strip-prompt) |
696 nil t))) | 733 nil t))) |
697 (setq result (buffer-substring (match-beginning 2) (match-end 2))) | 734 (setq result (buffer-substring-no-properties (match-beginning 2) |
735 (match-end 2))) | |
698 (if (he-string-member result he-tried-table t) | 736 (if (he-string-member result he-tried-table t) |
699 (setq result nil))) ; if already in table, ignore | 737 (setq result nil))) ; if already in table, ignore |
700 result)) | 738 result)) |
701 | 739 |
702 (defun he-line-beg (strip-prompt) | 740 (defun he-line-beg (strip-prompt) |
728 (set-marker he-search-loc he-string-beg) | 766 (set-marker he-search-loc he-string-beg) |
729 (setq he-search-bw t))) | 767 (setq he-search-bw t))) |
730 | 768 |
731 (if (not (equal he-search-string "")) | 769 (if (not (equal he-search-string "")) |
732 (save-excursion | 770 (save-excursion |
733 ;; Try looking backward unless inhibited. | 771 (save-restriction |
734 (if he-search-bw | 772 (if hippie-expand-no-restriction |
735 (progn | 773 (widen)) |
736 (goto-char he-search-loc) | 774 ;; Try looking backward unless inhibited. |
737 (setq expansion (he-list-search he-search-string t)) | 775 (if he-search-bw |
738 (set-marker he-search-loc (point)) | 776 (progn |
739 (if (not expansion) | 777 (goto-char he-search-loc) |
740 (progn | 778 (setq expansion (he-list-search he-search-string t)) |
741 (set-marker he-search-loc he-string-end) | 779 (set-marker he-search-loc (point)) |
742 (setq he-search-bw ()))))) | 780 (if (not expansion) |
743 | 781 (progn |
744 (if (not expansion) ; Then look forward. | 782 (set-marker he-search-loc he-string-end) |
745 (progn | 783 (setq he-search-bw ()))))) |
746 (goto-char he-search-loc) | 784 |
747 (setq expansion (he-list-search he-search-string nil)) | 785 (if (not expansion) ; Then look forward. |
748 (set-marker he-search-loc (point)))))) | 786 (progn |
787 (goto-char he-search-loc) | |
788 (setq expansion (he-list-search he-search-string nil)) | |
789 (set-marker he-search-loc (point))))))) | |
749 | 790 |
750 (if (not expansion) | 791 (if (not expansion) |
751 (progn | 792 (progn |
752 (if old (he-reset-string)) | 793 (if old (he-reset-string)) |
753 ()) | 794 ()) |
775 (not expansion) | 816 (not expansion) |
776 (or (not hippie-expand-max-buffers) | 817 (or (not hippie-expand-max-buffers) |
777 (< he-searched-n-bufs hippie-expand-max-buffers))) | 818 (< he-searched-n-bufs hippie-expand-max-buffers))) |
778 (set-buffer (car he-search-bufs)) | 819 (set-buffer (car he-search-bufs)) |
779 (if (and (not (eq (current-buffer) buf)) | 820 (if (and (not (eq (current-buffer) buf)) |
780 (not (memq major-mode hippie-expand-ignore-buffers)) | 821 (if hippie-expand-only-buffers |
781 (not (he-regexp-member (buffer-name) | 822 (he-buffer-member hippie-expand-only-buffers) |
782 hippie-expand-ignore-buffers))) | 823 (not (he-buffer-member hippie-expand-ignore-buffers)))) |
783 (save-excursion | 824 (save-excursion |
784 (goto-char he-search-loc) | 825 (save-restriction |
785 (setq expansion (let ((case-fold-search orig-case-fold-search)) | 826 (if hippie-expand-no-restriction |
786 (he-list-search he-search-string nil))) | 827 (widen)) |
787 (set-marker he-search-loc (point)) | 828 (goto-char he-search-loc) |
788 (if (not expansion) | 829 (setq expansion |
789 (progn | 830 (let ((case-fold-search orig-case-fold-search)) |
790 (setq he-search-bufs (cdr he-search-bufs)) | 831 (he-list-search he-search-string nil))) |
791 (setq he-searched-n-bufs (1+ he-searched-n-bufs)) | 832 (set-marker he-search-loc (point)) |
792 (set-marker he-search-loc 1 (car he-search-bufs))))) | 833 (if (not expansion) |
834 (progn | |
835 (setq he-search-bufs (cdr he-search-bufs)) | |
836 (setq he-searched-n-bufs (1+ he-searched-n-bufs)) | |
837 (set-marker he-search-loc 1 (car he-search-bufs)))))) | |
793 (setq he-search-bufs (cdr he-search-bufs)) | 838 (setq he-search-bufs (cdr he-search-bufs)) |
794 (set-marker he-search-loc 1 (car he-search-bufs))))) | 839 (set-marker he-search-loc 1 (car he-search-bufs))))) |
795 | 840 |
796 (set-buffer buf) | 841 (set-buffer buf) |
797 (if (not expansion) | 842 (if (not expansion) |
819 (if (and reverse | 864 (if (and reverse |
820 (> (point) he-string-beg)) | 865 (> (point) he-string-beg)) |
821 (setq err t)) | 866 (setq err t)) |
822 (if (not err) | 867 (if (not err) |
823 (progn | 868 (progn |
824 (setq result (buffer-substring beg (point))) | 869 (setq result (buffer-substring-no-properties beg (point))) |
825 (if (he-string-member result he-tried-table t) | 870 (if (he-string-member result he-tried-table t) |
826 (setq result nil)))) ; if already in table, ignore | 871 (setq result nil)))) ; if already in table, ignore |
827 (goto-char pos)) | 872 (goto-char pos)) |
828 result)) | 873 result)) |
829 | 874 |
876 (set-marker he-search-loc he-string-beg) | 921 (set-marker he-search-loc he-string-beg) |
877 (setq he-search-bw t))) | 922 (setq he-search-bw t))) |
878 | 923 |
879 (if (not (equal he-search-string "")) | 924 (if (not (equal he-search-string "")) |
880 (save-excursion | 925 (save-excursion |
881 ;; Try looking backward unless inhibited. | 926 (save-restriction |
882 (if he-search-bw | 927 (if hippie-expand-no-restriction |
883 (progn | 928 (widen)) |
884 (goto-char he-search-loc) | 929 ;; Try looking backward unless inhibited. |
885 (setq expansion (he-dabbrev-search he-search-string t)) | 930 (if he-search-bw |
886 (set-marker he-search-loc (point)) | 931 (progn |
887 (if (not expansion) | 932 (goto-char he-search-loc) |
888 (progn | 933 (setq expansion (he-dabbrev-search he-search-string t)) |
889 (set-marker he-search-loc he-string-end) | 934 (set-marker he-search-loc (point)) |
890 (setq he-search-bw ()))))) | 935 (if (not expansion) |
891 | 936 (progn |
892 (if (not expansion) ; Then look forward. | 937 (set-marker he-search-loc he-string-end) |
893 (progn | 938 (setq he-search-bw ()))))) |
894 (goto-char he-search-loc) | 939 |
895 (setq expansion (he-dabbrev-search he-search-string nil)) | 940 (if (not expansion) ; Then look forward. |
896 (set-marker he-search-loc (point)))))) | 941 (progn |
942 (goto-char he-search-loc) | |
943 (setq expansion (he-dabbrev-search he-search-string nil)) | |
944 (set-marker he-search-loc (point))))))) | |
897 | 945 |
898 (if (not expansion) | 946 (if (not expansion) |
899 (progn | 947 (progn |
900 (if old (he-reset-string)) | 948 (if old (he-reset-string)) |
901 ()) | 949 ()) |
923 (not expansion) | 971 (not expansion) |
924 (or (not hippie-expand-max-buffers) | 972 (or (not hippie-expand-max-buffers) |
925 (< he-searched-n-bufs hippie-expand-max-buffers))) | 973 (< he-searched-n-bufs hippie-expand-max-buffers))) |
926 (set-buffer (car he-search-bufs)) | 974 (set-buffer (car he-search-bufs)) |
927 (if (and (not (eq (current-buffer) buf)) | 975 (if (and (not (eq (current-buffer) buf)) |
928 (not (memq major-mode hippie-expand-ignore-buffers)) | 976 (if hippie-expand-only-buffers |
929 (not (he-regexp-member (buffer-name) | 977 (he-buffer-member hippie-expand-only-buffers) |
930 hippie-expand-ignore-buffers))) | 978 (not (he-buffer-member hippie-expand-ignore-buffers)))) |
931 (save-excursion | 979 (save-excursion |
932 (goto-char he-search-loc) | 980 (save-restriction |
933 (setq expansion (let ((case-fold-search orig-case-fold-search)) | 981 (if hippie-expand-no-restriction |
934 (he-dabbrev-search he-search-string nil))) | 982 (widen)) |
935 (set-marker he-search-loc (point)) | 983 (goto-char he-search-loc) |
936 (if (not expansion) | 984 (setq expansion |
937 (progn | 985 (let ((case-fold-search orig-case-fold-search)) |
938 (setq he-search-bufs (cdr he-search-bufs)) | 986 (he-dabbrev-search he-search-string nil))) |
939 (setq he-searched-n-bufs (1+ he-searched-n-bufs)) | 987 (set-marker he-search-loc (point)) |
940 (set-marker he-search-loc 1 (car he-search-bufs))))) | 988 (if (not expansion) |
989 (progn | |
990 (setq he-search-bufs (cdr he-search-bufs)) | |
991 (setq he-searched-n-bufs (1+ he-searched-n-bufs)) | |
992 (set-marker he-search-loc 1 (car he-search-bufs)))))) | |
941 (setq he-search-bufs (cdr he-search-bufs)) | 993 (setq he-search-bufs (cdr he-search-bufs)) |
942 (set-marker he-search-loc 1 (car he-search-bufs))))) | 994 (set-marker he-search-loc 1 (car he-search-bufs))))) |
943 | 995 |
944 (set-buffer buf) | 996 (set-buffer buf) |
945 (if (not expansion) | 997 (if (not expansion) |
1000 (he-substitute-string expansion t) | 1052 (he-substitute-string expansion t) |
1001 t)))) | 1053 t)))) |
1002 | 1054 |
1003 (defun he-dabbrev-search (pattern &optional reverse limit) | 1055 (defun he-dabbrev-search (pattern &optional reverse limit) |
1004 (let ((result ()) | 1056 (let ((result ()) |
1005 (regpat (cond ((not he-dabbrev-as-symbol) | 1057 (regpat (cond ((not hippie-expand-dabbrev-as-symbol) |
1006 (concat "\\<" (regexp-quote pattern) "\\sw+")) | 1058 (concat "\\<" (regexp-quote pattern) "\\sw+")) |
1007 ((eq (char-syntax (aref pattern 0)) ?_) | 1059 ((eq (char-syntax (aref pattern 0)) ?_) |
1008 (concat (regexp-quote pattern) "\\(\\sw\\|\\s_\\)+")) | 1060 (concat (regexp-quote pattern) "\\(\\sw\\|\\s_\\)+")) |
1009 (t | 1061 (t |
1010 (concat "\\<" (regexp-quote pattern) | 1062 (concat "\\<" (regexp-quote pattern) |
1011 "\\(\\sw\\|\\s_\\)+"))))) | 1063 "\\(\\sw\\|\\s_\\)+"))))) |
1012 (while (and (not result) | 1064 (while (and (not result) |
1013 (if reverse | 1065 (if reverse |
1014 (re-search-backward regpat limit t) | 1066 (re-search-backward regpat limit t) |
1015 (re-search-forward regpat limit t))) | 1067 (re-search-forward regpat limit t))) |
1016 (setq result (buffer-substring (match-beginning 0) (match-end 0))) | 1068 (setq result (buffer-substring-no-properties (match-beginning 0) |
1017 (if (or (and he-dabbrev-as-symbol | 1069 (match-end 0))) |
1018 (> (match-beginning 0) (point-min)) | 1070 (if (or (and hippie-expand-dabbrev-as-symbol |
1071 (> (match-beginning 0) (point-min)) | |
1019 (memq (char-syntax (char-after (1- (match-beginning 0)))) | 1072 (memq (char-syntax (char-after (1- (match-beginning 0)))) |
1020 '(?_ ?w))) | 1073 '(?_ ?w))) |
1021 (he-string-member result he-tried-table t)) | 1074 (he-string-member result he-tried-table t)) |
1022 (setq result nil))) ; ignore if bad prefix or already in table | 1075 (setq result nil))) ; ignore if bad prefix or already in table |
1023 result)) | 1076 result)) |
1024 | 1077 |
1025 (defun he-dabbrev-beg () | 1078 (defun he-dabbrev-beg () |
1026 (let ((op (point))) | 1079 (let ((op (point))) |
1027 (save-excursion | 1080 (save-excursion |
1028 (if he-dabbrev-skip-space | 1081 (if hippie-expand-dabbrev-skip-space |
1029 (skip-syntax-backward ". ")) | 1082 (skip-syntax-backward ". ")) |
1030 (if (= (skip-syntax-backward (if he-dabbrev-as-symbol "w_" "w")) 0) | 1083 (if (= (skip-syntax-backward (if hippie-expand-dabbrev-as-symbol |
1084 "w_" "w")) | |
1085 0) | |
1031 op | 1086 op |
1032 (point))))) | 1087 (point))))) |
1033 | 1088 |
1034 (defun try-expand-dabbrev-from-kill (old) | 1089 (defun try-expand-dabbrev-from-kill (old) |
1035 "Try to expand word \"dynamically\", searching the kill ring. | 1090 "Try to expand word \"dynamically\", searching the kill ring. |
1054 (he-substitute-string expansion t) | 1109 (he-substitute-string expansion t) |
1055 t)))) | 1110 t)))) |
1056 | 1111 |
1057 (defun he-dabbrev-kill-search (pattern) | 1112 (defun he-dabbrev-kill-search (pattern) |
1058 (let ((result ()) | 1113 (let ((result ()) |
1059 (regpat (cond ((not he-dabbrev-as-symbol) | 1114 (regpat (cond ((not hippie-expand-dabbrev-as-symbol) |
1060 (concat "\\<" (regexp-quote pattern) "\\sw+")) | 1115 (concat "\\<" (regexp-quote pattern) "\\sw+")) |
1061 ((eq (char-syntax (aref pattern 0)) ?_) | 1116 ((eq (char-syntax (aref pattern 0)) ?_) |
1062 (concat (regexp-quote pattern) "\\(\\sw\\|\\s_\\)+")) | 1117 (concat (regexp-quote pattern) "\\(\\sw\\|\\s_\\)+")) |
1063 (t | 1118 (t |
1064 (concat "\\<" (regexp-quote pattern) | 1119 (concat "\\<" (regexp-quote pattern) |
1065 "\\(\\sw\\|\\s_\\)+")))) | 1120 "\\(\\sw\\|\\s_\\)+")))) |
1066 (killstr (car he-expand-list))) | 1121 (killstr (car he-expand-list))) |
1067 (while (and (not result) | 1122 (while (and (not result) |
1068 he-expand-list) | 1123 he-expand-list) |
1069 (while (and (not result) | 1124 (while (and (not result) |
1070 (string-match regpat killstr he-search-loc2)) | 1125 (string-match regpat killstr he-search-loc2)) |
1071 (setq result (substring killstr (match-beginning 0) (match-end 0))) | 1126 (setq result (substring killstr (match-beginning 0) (match-end 0))) |
1127 (set-text-properties 0 (length result) () result) | |
1072 (setq he-search-loc2 (1+ (match-beginning 0))) | 1128 (setq he-search-loc2 (1+ (match-beginning 0))) |
1073 (if (or (and he-dabbrev-as-symbol | 1129 (if (or (and hippie-expand-dabbrev-as-symbol |
1074 (> (match-beginning 0) 0) | 1130 (> (match-beginning 0) 0) |
1075 (memq (char-syntax (aref killstr (1- (match-beginning 0)))) | 1131 (memq (char-syntax (aref killstr (1- (match-beginning 0)))) |
1076 '(?_ ?w))) | 1132 '(?_ ?w))) |
1077 (he-string-member result he-tried-table t)) | 1133 (he-string-member result he-tried-table t)) |
1078 (setq result nil))) ; ignore if bad prefix or already in table | 1134 (setq result nil))) ; ignore if bad prefix or already in table |
1079 (if (and (not result) | 1135 (if (and (not result) |
1128 (goto-char he-string-beg) | 1184 (goto-char he-string-beg) |
1129 (if (and (>= (- (point) pos) (point-min)) ; avoid some string GC | 1185 (if (and (>= (- (point) pos) (point-min)) ; avoid some string GC |
1130 (eq (char-after (- (point) pos)) (aref killstr 0)) | 1186 (eq (char-after (- (point) pos)) (aref killstr 0)) |
1131 (search-backward (substring killstr 0 pos) | 1187 (search-backward (substring killstr 0 pos) |
1132 (- (point) pos) t)) | 1188 (- (point) pos) t)) |
1133 (setq result (substring killstr pos)))) | 1189 (progn |
1190 (setq result (substring killstr pos)) | |
1191 (set-text-properties 0 (length result) () result)))) | |
1134 (if (and result | 1192 (if (and result |
1135 (he-string-member result he-tried-table)) | 1193 (he-string-member result he-tried-table)) |
1136 (setq result nil))) ; ignore if already in table | 1194 (setq result nil))) ; ignore if already in table |
1137 (if (and (not result) | 1195 (if (and (not result) |
1138 he-expand-list) | 1196 he-expand-list) |