X-Git-Url: http://git.hcoop.net/bpt/emacs.git/blobdiff_plain/41306318777a942420bc4feadbfacf662ea179dc..f0ee9096ba9f35b9e6b85fb5c5f5f56168a67824:/lisp/hippie-exp.el diff --git a/lisp/hippie-exp.el b/lisp/hippie-exp.el index ad233b2a50..ec6007ebf8 100644 --- a/lisp/hippie-exp.el +++ b/lisp/hippie-exp.el @@ -1,9 +1,9 @@ ;;; hippie-exp.el --- expand text trying various ways to find its expansion -;; Copyright (C) 1992, 2001-2013 Free Software Foundation, Inc. +;; Copyright (C) 1992, 2001-2014 Free Software Foundation, Inc. ;; Author: Anders Holst -;; Last change: 3 March 1998 +;; Maintainer: emacs-devel@gnu.org ;; Version: 1.6 ;; Keywords: abbrev convenience @@ -637,15 +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)) - (orig-case-fold-search case-fold-search)) + (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-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)))) @@ -654,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 hippie-expand-only-buffers - (he-buffer-member hippie-expand-only-buffers) - (not (he-buffer-member hippie-expand-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 @@ -686,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 ())) @@ -715,7 +723,7 @@ string). It returns t if a new completion is found, nil otherwise." (defun he-line-search-regexp (pat strip-prompt) (if strip-prompt - (concat "\\(" comint-prompt-regexp "\\|^\\s-*\\)\\(" + (concat "\\(" comint-prompt-regexp "\\|^\\s-*\\)\\(?2:" (regexp-quote pat) "[^\n]*[^ \t\n]\\)") (concat "^\\(\\s-*\\)\\(" @@ -769,53 +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)) - (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)))) - - (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 hippie-expand-only-buffers - (he-buffer-member hippie-expand-only-buffers) - (not (he-buffer-member hippie-expand-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)))) + (he--all-buffers old #'he-list-beg #'he-list-search)) -(defun he-list-search (str reverse) +(defun he-list-search (str &optional reverse) (let ((result ()) beg pos err) (while (and (not result) @@ -924,51 +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)) - (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 hippie-expand-only-buffers - (he-buffer-member hippie-expand-only-buffers) - (not (he-buffer-member hippie-expand-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 who ;; suggested this one.