diff options
| author | Stefan Monnier | 2014-06-12 10:35:09 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2014-06-12 10:35:09 -0400 |
| commit | de825bbb7421f66f6b2354849d81d80f4dbf527d (patch) | |
| tree | 4a8f6e8be033d6501e604f4965ebaf5cdfd1e55c | |
| parent | 8576251878f59f686b3a14c574a402549eabcbc1 (diff) | |
| download | emacs-de825bbb7421f66f6b2354849d81d80f4dbf527d.tar.gz emacs-de825bbb7421f66f6b2354849d81d80f4dbf527d.zip | |
* lisp/hippie-exp.el (he--all-buffers): New function.
(try-expand-line-all-buffers, try-expand-list-all-buffers)
(try-expand-dabbrev-all-buffers): Use it.
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/hippie-exp.el | 152 |
2 files changed, 39 insertions, 119 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d035ce73af1..fce67e553dc 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2014-06-12 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * hippie-exp.el (he--all-buffers): New function. | ||
| 4 | (try-expand-line-all-buffers, try-expand-list-all-buffers) | ||
| 5 | (try-expand-dabbrev-all-buffers): Use it. | ||
| 6 | |||
| 1 | 2014-06-12 Emilio C. Lopes <eclig@gmx.net> | 7 | 2014-06-12 Emilio C. Lopes <eclig@gmx.net> |
| 2 | 8 | ||
| 3 | * hippie-exp.el (try-expand-line-all-buffers) | 9 | * hippie-exp.el (try-expand-line-all-buffers) |
diff --git a/lisp/hippie-exp.el b/lisp/hippie-exp.el index 7cf31d757d4..ec6007ebf82 100644 --- a/lisp/hippie-exp.el +++ b/lisp/hippie-exp.el | |||
| @@ -637,17 +637,27 @@ string). It returns t if a new completion is found, nil otherwise." | |||
| 637 | The argument OLD has to be nil the first call of this function, and t | 637 | The argument OLD has to be nil the first call of this function, and t |
| 638 | for subsequent calls (for further possible completions of the same | 638 | for subsequent calls (for further possible completions of the same |
| 639 | string). It returns t if a new completion is found, nil otherwise." | 639 | string). It returns t if a new completion is found, nil otherwise." |
| 640 | (he--all-buffers | ||
| 641 | old | ||
| 642 | (lambda () (he-line-beg (and (get-buffer-process (current-buffer)) | ||
| 643 | comint-use-prompt-regexp | ||
| 644 | comint-prompt-regexp))) | ||
| 645 | (lambda (string) | ||
| 646 | (he-line-search string | ||
| 647 | (and (get-buffer-process (current-buffer)) | ||
| 648 | comint-use-prompt-regexp | ||
| 649 | comint-prompt-regexp) | ||
| 650 | nil)))) | ||
| 651 | |||
| 652 | (defun he--all-buffers (old beg-function search-function) | ||
| 640 | (let ((expansion ()) | 653 | (let ((expansion ()) |
| 641 | (strip-prompt (and (get-buffer-process (current-buffer)) | 654 | (buf (current-buffer)) |
| 642 | comint-use-prompt-regexp | ||
| 643 | comint-prompt-regexp)) | ||
| 644 | (buf (current-buffer)) | ||
| 645 | (only-buffers hippie-expand-only-buffers) | 655 | (only-buffers hippie-expand-only-buffers) |
| 646 | (ignore-buffers hippie-expand-ignore-buffers) | 656 | (ignore-buffers hippie-expand-ignore-buffers) |
| 647 | (orig-case-fold-search case-fold-search)) | 657 | (orig-case-fold-search case-fold-search)) |
| 648 | (if (not old) | 658 | (if (not old) |
| 649 | (progn | 659 | (progn |
| 650 | (he-init-string (he-line-beg strip-prompt) (point)) | 660 | (he-init-string (funcall beg-function) (point)) |
| 651 | (setq he-search-bufs (buffer-list)) | 661 | (setq he-search-bufs (buffer-list)) |
| 652 | (setq he-searched-n-bufs 0) | 662 | (setq he-searched-n-bufs 0) |
| 653 | (set-marker he-search-loc 1 (car he-search-bufs)))) | 663 | (set-marker he-search-loc 1 (car he-search-bufs)))) |
| @@ -656,24 +666,20 @@ string). It returns t if a new completion is found, nil otherwise." | |||
| 656 | (while (and he-search-bufs | 666 | (while (and he-search-bufs |
| 657 | (not expansion) | 667 | (not expansion) |
| 658 | (or (not hippie-expand-max-buffers) | 668 | (or (not hippie-expand-max-buffers) |
| 659 | (< he-searched-n-bufs hippie-expand-max-buffers))) | 669 | (< he-searched-n-bufs hippie-expand-max-buffers))) |
| 660 | (set-buffer (car he-search-bufs)) | 670 | (set-buffer (car he-search-bufs)) |
| 661 | (if (and (not (eq (current-buffer) buf)) | 671 | (if (and (not (eq (current-buffer) buf)) |
| 662 | (if only-buffers | 672 | (if only-buffers |
| 663 | (he-buffer-member only-buffers) | 673 | (he-buffer-member only-buffers) |
| 664 | (not (he-buffer-member ignore-buffers)))) | 674 | (not (he-buffer-member ignore-buffers)))) |
| 665 | (save-excursion | 675 | (save-excursion |
| 666 | (save-restriction | 676 | (save-restriction |
| 667 | (if hippie-expand-no-restriction | 677 | (if hippie-expand-no-restriction |
| 668 | (widen)) | 678 | (widen)) |
| 669 | (goto-char he-search-loc) | 679 | (goto-char he-search-loc) |
| 670 | (setq strip-prompt (and (get-buffer-process (current-buffer)) | ||
| 671 | comint-use-prompt-regexp | ||
| 672 | comint-prompt-regexp)) | ||
| 673 | (setq expansion | 680 | (setq expansion |
| 674 | (let ((case-fold-search orig-case-fold-search)) | 681 | (let ((case-fold-search orig-case-fold-search)) |
| 675 | (he-line-search he-search-string | 682 | (funcall search-function he-search-string))) |
| 676 | strip-prompt nil))) | ||
| 677 | (set-marker he-search-loc (point)) | 683 | (set-marker he-search-loc (point)) |
| 678 | (if (not expansion) | 684 | (if (not expansion) |
| 679 | (progn | 685 | (progn |
| @@ -688,9 +694,9 @@ string). It returns t if a new completion is found, nil otherwise." | |||
| 688 | (progn | 694 | (progn |
| 689 | (if old (he-reset-string)) | 695 | (if old (he-reset-string)) |
| 690 | ()) | 696 | ()) |
| 691 | (progn | 697 | (progn |
| 692 | (he-substitute-string expansion t) | 698 | (he-substitute-string expansion t) |
| 693 | t)))) | 699 | t)))) |
| 694 | 700 | ||
| 695 | (defun he-line-search (str strip-prompt reverse) | 701 | (defun he-line-search (str strip-prompt reverse) |
| 696 | (let ((result ())) | 702 | (let ((result ())) |
| @@ -771,55 +777,9 @@ string). It returns t if a new completion is found, nil otherwise." | |||
| 771 | The argument OLD has to be nil the first call of this function, and t | 777 | The argument OLD has to be nil the first call of this function, and t |
| 772 | for subsequent calls (for further possible completions of the same | 778 | for subsequent calls (for further possible completions of the same |
| 773 | string). It returns t if a new completion is found, nil otherwise." | 779 | string). It returns t if a new completion is found, nil otherwise." |
| 774 | (let ((expansion ()) | 780 | (he--all-buffers old #'he-list-beg #'he-list-search)) |
| 775 | (buf (current-buffer)) | ||
| 776 | (only-buffers hippie-expand-only-buffers) | ||
| 777 | (ignore-buffers hippie-expand-ignore-buffers) | ||
| 778 | (orig-case-fold-search case-fold-search)) | ||
| 779 | (if (not old) | ||
| 780 | (progn | ||
| 781 | (he-init-string (he-list-beg) (point)) | ||
| 782 | (setq he-search-bufs (buffer-list)) | ||
| 783 | (setq he-searched-n-bufs 0) | ||
| 784 | (set-marker he-search-loc 1 (car he-search-bufs)))) | ||
| 785 | 781 | ||
| 786 | (if (not (equal he-search-string "")) | 782 | (defun he-list-search (str &optional reverse) |
| 787 | (while (and he-search-bufs | ||
| 788 | (not expansion) | ||
| 789 | (or (not hippie-expand-max-buffers) | ||
| 790 | (< he-searched-n-bufs hippie-expand-max-buffers))) | ||
| 791 | (set-buffer (car he-search-bufs)) | ||
| 792 | (if (and (not (eq (current-buffer) buf)) | ||
| 793 | (if only-buffers | ||
| 794 | (he-buffer-member only-buffers) | ||
| 795 | (not (he-buffer-member ignore-buffers)))) | ||
| 796 | (save-excursion | ||
| 797 | (save-restriction | ||
| 798 | (if hippie-expand-no-restriction | ||
| 799 | (widen)) | ||
| 800 | (goto-char he-search-loc) | ||
| 801 | (setq expansion | ||
| 802 | (let ((case-fold-search orig-case-fold-search)) | ||
| 803 | (he-list-search he-search-string nil))) | ||
| 804 | (set-marker he-search-loc (point)) | ||
| 805 | (if (not expansion) | ||
| 806 | (progn | ||
| 807 | (setq he-search-bufs (cdr he-search-bufs)) | ||
| 808 | (setq he-searched-n-bufs (1+ he-searched-n-bufs)) | ||
| 809 | (set-marker he-search-loc 1 (car he-search-bufs)))))) | ||
| 810 | (setq he-search-bufs (cdr he-search-bufs)) | ||
| 811 | (set-marker he-search-loc 1 (car he-search-bufs))))) | ||
| 812 | |||
| 813 | (set-buffer buf) | ||
| 814 | (if (not expansion) | ||
| 815 | (progn | ||
| 816 | (if old (he-reset-string)) | ||
| 817 | ()) | ||
| 818 | (progn | ||
| 819 | (he-substitute-string expansion t) | ||
| 820 | t)))) | ||
| 821 | |||
| 822 | (defun he-list-search (str reverse) | ||
| 823 | (let ((result ()) | 783 | (let ((result ()) |
| 824 | beg pos err) | 784 | beg pos err) |
| 825 | (while (and (not result) | 785 | (while (and (not result) |
| @@ -928,53 +888,7 @@ string). It returns t if a new expansion is found, nil otherwise." | |||
| 928 | The argument OLD has to be nil the first call of this function, and t | 888 | The argument OLD has to be nil the first call of this function, and t |
| 929 | for subsequent calls (for further possible expansions of the same | 889 | for subsequent calls (for further possible expansions of the same |
| 930 | string). It returns t if a new expansion is found, nil otherwise." | 890 | string). It returns t if a new expansion is found, nil otherwise." |
| 931 | (let ((expansion ()) | 891 | (he--all-buffers old #'he-dabbrev-beg #'he-dabbrev-search)) |
| 932 | (buf (current-buffer)) | ||
| 933 | (only-buffers hippie-expand-only-buffers) | ||
| 934 | (ignore-buffers hippie-expand-ignore-buffers) | ||
| 935 | (orig-case-fold-search case-fold-search)) | ||
| 936 | (if (not old) | ||
| 937 | (progn | ||
| 938 | (he-init-string (he-dabbrev-beg) (point)) | ||
| 939 | (setq he-search-bufs (buffer-list)) | ||
| 940 | (setq he-searched-n-bufs 0) | ||
| 941 | (set-marker he-search-loc 1 (car he-search-bufs)))) | ||
| 942 | |||
| 943 | (if (not (equal he-search-string "")) | ||
| 944 | (while (and he-search-bufs | ||
| 945 | (not expansion) | ||
| 946 | (or (not hippie-expand-max-buffers) | ||
| 947 | (< he-searched-n-bufs hippie-expand-max-buffers))) | ||
| 948 | (set-buffer (car he-search-bufs)) | ||
| 949 | (if (and (not (eq (current-buffer) buf)) | ||
| 950 | (if only-buffers | ||
| 951 | (he-buffer-member only-buffers) | ||
| 952 | (not (he-buffer-member ignore-buffers)))) | ||
| 953 | (save-excursion | ||
| 954 | (save-restriction | ||
| 955 | (if hippie-expand-no-restriction | ||
| 956 | (widen)) | ||
| 957 | (goto-char he-search-loc) | ||
| 958 | (setq expansion | ||
| 959 | (let ((case-fold-search orig-case-fold-search)) | ||
| 960 | (he-dabbrev-search he-search-string nil))) | ||
| 961 | (set-marker he-search-loc (point)) | ||
| 962 | (if (not expansion) | ||
| 963 | (progn | ||
| 964 | (setq he-search-bufs (cdr he-search-bufs)) | ||
| 965 | (setq he-searched-n-bufs (1+ he-searched-n-bufs)) | ||
| 966 | (set-marker he-search-loc 1 (car he-search-bufs)))))) | ||
| 967 | (setq he-search-bufs (cdr he-search-bufs)) | ||
| 968 | (set-marker he-search-loc 1 (car he-search-bufs))))) | ||
| 969 | |||
| 970 | (set-buffer buf) | ||
| 971 | (if (not expansion) | ||
| 972 | (progn | ||
| 973 | (if old (he-reset-string)) | ||
| 974 | ()) | ||
| 975 | (progn | ||
| 976 | (he-substitute-string expansion t) | ||
| 977 | t)))) | ||
| 978 | 892 | ||
| 979 | ;; Thanks go to Jeff Dairiki <dairiki@faraday.apl.washington.edu> who | 893 | ;; Thanks go to Jeff Dairiki <dairiki@faraday.apl.washington.edu> who |
| 980 | ;; suggested this one. | 894 | ;; suggested this one. |