diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2014-06-12 10:35:09 -0400 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2014-06-12 10:35:09 -0400 |
commit | de825bbb7421f66f6b2354849d81d80f4dbf527d (patch) | |
tree | 4a8f6e8be033d6501e604f4965ebaf5cdfd1e55c | |
parent | 8576251878f59f686b3a14c574a402549eabcbc1 (diff) | |
download | emacs-de825bbb7421f66f6b2354849d81d80f4dbf527d.tar.gz |
* 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 @@ +2014-06-12 Stefan Monnier <monnier@iro.umontreal.ca> + + * 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. + 2014-06-12 Emilio C. Lopes <eclig@gmx.net> * 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." The argument OLD has to be nil the first call of this function, and t for subsequent calls (for further possible completions of the same string). It returns t if a new completion is found, nil otherwise." + (he--all-buffers + old + (lambda () (he-line-beg (and (get-buffer-process (current-buffer)) + comint-use-prompt-regexp + comint-prompt-regexp))) + (lambda (string) + (he-line-search string + (and (get-buffer-process (current-buffer)) + comint-use-prompt-regexp + comint-prompt-regexp) + nil)))) + +(defun he--all-buffers (old beg-function search-function) (let ((expansion ()) - (strip-prompt (and (get-buffer-process (current-buffer)) - comint-use-prompt-regexp - comint-prompt-regexp)) - (buf (current-buffer)) + (buf (current-buffer)) (only-buffers hippie-expand-only-buffers) (ignore-buffers hippie-expand-ignore-buffers) - (orig-case-fold-search case-fold-search)) + (orig-case-fold-search case-fold-search)) (if (not old) - (progn - (he-init-string (he-line-beg strip-prompt) (point)) + (progn + (he-init-string (funcall beg-function) (point)) (setq he-search-bufs (buffer-list)) (setq he-searched-n-bufs 0) (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." (while (and he-search-bufs (not expansion) (or (not hippie-expand-max-buffers) - (< he-searched-n-bufs hippie-expand-max-buffers))) - (set-buffer (car he-search-bufs)) - (if (and (not (eq (current-buffer) buf)) - (if only-buffers - (he-buffer-member only-buffers) - (not (he-buffer-member ignore-buffers)))) - (save-excursion - (save-restriction - (if hippie-expand-no-restriction + (< he-searched-n-bufs hippie-expand-max-buffers))) + (set-buffer (car he-search-bufs)) + (if (and (not (eq (current-buffer) buf)) + (if only-buffers + (he-buffer-member only-buffers) + (not (he-buffer-member ignore-buffers)))) + (save-excursion + (save-restriction + (if hippie-expand-no-restriction (widen)) (goto-char he-search-loc) - (setq strip-prompt (and (get-buffer-process (current-buffer)) - comint-use-prompt-regexp - comint-prompt-regexp)) (setq expansion (let ((case-fold-search orig-case-fold-search)) - (he-line-search he-search-string - strip-prompt nil))) + (funcall search-function he-search-string))) (set-marker he-search-loc (point)) (if (not expansion) (progn @@ -688,9 +694,9 @@ string). It returns t if a new completion is found, nil otherwise." (progn (if old (he-reset-string)) ()) - (progn - (he-substitute-string expansion t) - t)))) + (progn + (he-substitute-string expansion t) + t)))) (defun he-line-search (str strip-prompt reverse) (let ((result ())) @@ -771,55 +777,9 @@ string). It returns t if a new completion is found, nil otherwise." The argument OLD has to be nil the first call of this function, and t for subsequent calls (for further possible completions of the same string). It returns t if a new completion is found, nil otherwise." - (let ((expansion ()) - (buf (current-buffer)) - (only-buffers hippie-expand-only-buffers) - (ignore-buffers hippie-expand-ignore-buffers) - (orig-case-fold-search case-fold-search)) - (if (not old) - (progn - (he-init-string (he-list-beg) (point)) - (setq he-search-bufs (buffer-list)) - (setq he-searched-n-bufs 0) - (set-marker he-search-loc 1 (car he-search-bufs)))) + (he--all-buffers old #'he-list-beg #'he-list-search)) - (if (not (equal he-search-string "")) - (while (and he-search-bufs - (not expansion) - (or (not hippie-expand-max-buffers) - (< he-searched-n-bufs hippie-expand-max-buffers))) - (set-buffer (car he-search-bufs)) - (if (and (not (eq (current-buffer) buf)) - (if only-buffers - (he-buffer-member only-buffers) - (not (he-buffer-member ignore-buffers)))) - (save-excursion - (save-restriction - (if hippie-expand-no-restriction - (widen)) - (goto-char he-search-loc) - (setq expansion - (let ((case-fold-search orig-case-fold-search)) - (he-list-search he-search-string nil))) - (set-marker he-search-loc (point)) - (if (not expansion) - (progn - (setq he-search-bufs (cdr he-search-bufs)) - (setq he-searched-n-bufs (1+ he-searched-n-bufs)) - (set-marker he-search-loc 1 (car he-search-bufs)))))) - (setq he-search-bufs (cdr he-search-bufs)) - (set-marker he-search-loc 1 (car he-search-bufs))))) - - (set-buffer buf) - (if (not expansion) - (progn - (if old (he-reset-string)) - ()) - (progn - (he-substitute-string expansion t) - t)))) - -(defun he-list-search (str reverse) +(defun he-list-search (str &optional reverse) (let ((result ()) beg pos err) (while (and (not result) @@ -928,53 +888,7 @@ string). It returns t if a new expansion is found, nil otherwise." The argument OLD has to be nil the first call of this function, and t for subsequent calls (for further possible expansions of the same string). It returns t if a new expansion is found, nil otherwise." - (let ((expansion ()) - (buf (current-buffer)) - (only-buffers hippie-expand-only-buffers) - (ignore-buffers hippie-expand-ignore-buffers) - (orig-case-fold-search case-fold-search)) - (if (not old) - (progn - (he-init-string (he-dabbrev-beg) (point)) - (setq he-search-bufs (buffer-list)) - (setq he-searched-n-bufs 0) - (set-marker he-search-loc 1 (car he-search-bufs)))) - - (if (not (equal he-search-string "")) - (while (and he-search-bufs - (not expansion) - (or (not hippie-expand-max-buffers) - (< he-searched-n-bufs hippie-expand-max-buffers))) - (set-buffer (car he-search-bufs)) - (if (and (not (eq (current-buffer) buf)) - (if only-buffers - (he-buffer-member only-buffers) - (not (he-buffer-member ignore-buffers)))) - (save-excursion - (save-restriction - (if hippie-expand-no-restriction - (widen)) - (goto-char he-search-loc) - (setq expansion - (let ((case-fold-search orig-case-fold-search)) - (he-dabbrev-search he-search-string nil))) - (set-marker he-search-loc (point)) - (if (not expansion) - (progn - (setq he-search-bufs (cdr he-search-bufs)) - (setq he-searched-n-bufs (1+ he-searched-n-bufs)) - (set-marker he-search-loc 1 (car he-search-bufs)))))) - (setq he-search-bufs (cdr he-search-bufs)) - (set-marker he-search-loc 1 (car he-search-bufs))))) - - (set-buffer buf) - (if (not expansion) - (progn - (if old (he-reset-string)) - ()) - (progn - (he-substitute-string expansion t) - t)))) + (he--all-buffers old #'he-dabbrev-beg #'he-dabbrev-search)) ;; Thanks go to Jeff Dairiki <dairiki@faraday.apl.washington.edu> who ;; suggested this one. |