X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/9850eff524bd0747a9561f3b4c90dfc3749f4ecb..3ca2c0150d5e482b62d368cf1633ff1587af6ce0:/lisp/hippie-exp.el diff --git a/lisp/hippie-exp.el b/lisp/hippie-exp.el index c8722df46b..7d14d780e2 100644 --- a/lisp/hippie-exp.el +++ b/lisp/hippie-exp.el @@ -1,7 +1,6 @@ ;;; hippie-exp.el --- expand text trying various ways to find its expansion -;; Copyright (C) 1992, 2001, 2002, 2003, 2004, 2005, -;; 2006, 2007, 2008 Free Software Foundation, Inc. +;; Copyright (C) 1992, 2001-2013 Free Software Foundation, Inc. ;; Author: Anders Holst ;; Last change: 3 March 1998 @@ -80,8 +79,8 @@ ;; in all buffers (except the current). (This may be a little ;; slow, don't use it unless you are really fond of `hippie-expand'.) ;; `try-expand-list' : Tries to expand the text back to the nearest -;; open delimiter, to a whole list from the buffer. Convenient for -;; example when writing lisp or TeX. +;; open delimiter, to a whole list from the buffer. Convenient for +;; example when writing Lisp or TeX. ;; `try-expand-list-all-buffers' : Like `try-expand-list' but searches ;; in all buffers (except the current). ;; `try-expand-dabbrev' : works exactly as dabbrev-expand (but of @@ -116,7 +115,7 @@ ;; variable with all kinds of try-functions above, it might be an ;; idea to use `make-hippie-expand-function' to construct different ;; `hippie-expand'-like functions, with different try-lists and bound -;; to different keys. It is also possible to make +;; to different keys. It is also possible to make ;; `hippie-expand-try-functions-list' a buffer local variable, and ;; let it depend on the mode (by setting it in the mode-hooks). ;; @@ -157,7 +156,7 @@ ;; opposite situation to occur, that `hippie-expand' misses some ;; suggestion because it thinks it has already tried it. ;; -;; Acknowledgement +;; Acknowledgment ;; ;; I want to thank Mikael Djurfeldt in discussions with whom the idea ;; of this function took form. @@ -167,7 +166,7 @@ ;;; Code: -(eval-when-compile (require 'comint)) +(require 'comint) (defgroup hippie-expand nil "Expand text trying various ways to find its expansion." @@ -200,6 +199,7 @@ (defvar he-search-window ()) +;;; Autoloaded for historical reasons (bug#12982) ;;;###autoload (defcustom hippie-expand-try-functions-list '(try-complete-file-name-partially @@ -218,49 +218,42 @@ or insert functions in this list." :type '(repeat function) :group 'hippie-expand) -;;;###autoload (defcustom hippie-expand-verbose t - "*Non-nil makes `hippie-expand' output which function it is trying." + "Non-nil makes `hippie-expand' output which function it is trying." :type 'boolean :group 'hippie-expand) -;;;###autoload (defcustom hippie-expand-dabbrev-skip-space nil - "*Non-nil means tolerate trailing spaces in the abbreviation to expand." + "Non-nil means tolerate trailing spaces in the abbreviation to expand." :group 'hippie-expand :type 'boolean) -;;;###autoload (defcustom hippie-expand-dabbrev-as-symbol t - "*Non-nil means expand as symbols, i.e. syntax `_' is considered a letter." + "Non-nil means expand as symbols, i.e. syntax `_' is considered a letter." :group 'hippie-expand :type 'boolean) -;;;###autoload (defcustom hippie-expand-no-restriction t - "*Non-nil means that narrowed buffers are widened during search." + "Non-nil means that narrowed buffers are widened during search." :group 'hippie-expand :type 'boolean) -;;;###autoload (defcustom hippie-expand-max-buffers () - "*The maximum number of buffers (apart from the current) searched. + "The maximum number of buffers (apart from the current) searched. If nil, all buffers are searched." :type '(choice (const :tag "All" nil) integer) :group 'hippie-expand) -;;;###autoload (defcustom hippie-expand-ignore-buffers '("^ \\*.*\\*$" dired-mode) - "*A list specifying which buffers not to search (if not current). + "A list specifying which buffers not to search (if not current). Can contain both regexps matching buffer names (as strings) and major modes \(as atoms)" :type '(repeat (choice regexp (symbol :tag "Major Mode"))) :group 'hippie-expand) -;;;###autoload (defcustom hippie-expand-only-buffers () - "*A list specifying the only buffers to search (in addition to current). + "A list specifying the only buffers to search (in addition to current). Can contain both regexps matching buffer names (as strings) and major modes \(as atoms). If non-nil, this variable overrides the variable `hippie-expand-ignore-buffers'." @@ -392,7 +385,7 @@ undoes the expansion." lst))) ;; Check if current buffer matches any atom or regexp in LST. -;; Atoms are interpreted as major modes, strings as regexps mathing the name. +;; Atoms are interpreted as major modes, strings as regexps matching the name. (defun he-buffer-member (lst) (or (memq major-mode lst) (progn @@ -519,7 +512,7 @@ otherwise." (defun he-concat-directory-file-name (dir-part name-part) "Try to slam together two parts of a file specification, system dependently." (cond ((null dir-part) name-part) - ((memq system-type '(ms-dos w32)) + ((eq system-type 'ms-dos) (if (and (string-match "\\\\" dir-part) (not (string-match "/" dir-part)) (= (aref name-part (1- (length name-part))) ?/)) @@ -716,8 +709,7 @@ string). It returns t if a new completion is found, nil otherwise." (defun he-line-beg (strip-prompt) (save-excursion (if (re-search-backward (he-line-search-regexp "" strip-prompt) - (save-excursion (beginning-of-line) - (point)) t) + (line-beginning-position) t) (match-beginning 2) (point)))) @@ -928,7 +920,7 @@ string). It returns t if a new expansion is found, nil otherwise." t)))) (defun try-expand-dabbrev-all-buffers (old) - "Tries to expand word \"dynamically\", searching all other buffers. + "Try to expand word \"dynamically\", searching all other buffers. 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." @@ -986,40 +978,37 @@ 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)) (flag (if (frame-visible-p (window-frame (selected-window))) 'visible t))) - (if (not old) - (progn - (he-init-string (he-dabbrev-beg) (point)) - (setq he-search-window (selected-window)) - (set-marker he-search-loc - (window-start he-search-window) - (window-buffer he-search-window)))) + (unless old + (he-init-string (he-dabbrev-beg) (point)) + (setq he-search-window (selected-window)) + (set-marker he-search-loc + (window-start he-search-window) + (window-buffer he-search-window))) (while (and (not (equal he-search-string "")) - (marker-position he-search-loc) - (not expansion)) - (save-excursion - (set-buffer (marker-buffer he-search-loc)) - (goto-char he-search-loc) - (setq expansion (he-dabbrev-search he-search-string () - (window-end he-search-window))) - (if (and expansion - (eq (marker-buffer he-string-beg) (current-buffer)) - (eq (marker-position he-string-beg) (match-beginning 0))) - (setq expansion (he-dabbrev-search he-search-string () - (window-end he-search-window)))) - (set-marker he-search-loc (point) (current-buffer))) - (if (not expansion) - (progn - (setq he-search-window (next-window he-search-window nil flag)) - (if (eq he-search-window (selected-window)) - (set-marker he-search-loc nil) - (set-marker he-search-loc (window-start he-search-window) - (window-buffer he-search-window)))))) + (marker-position he-search-loc) + (not expansion)) + (with-current-buffer (marker-buffer he-search-loc) + (save-excursion + (goto-char he-search-loc) + (setq expansion (he-dabbrev-search he-search-string () + (window-end he-search-window))) + (if (and expansion + (eq (marker-buffer he-string-beg) (current-buffer)) + (eq (marker-position he-string-beg) (match-beginning 0))) + (setq expansion + (he-dabbrev-search he-search-string () + (window-end he-search-window)))) + (set-marker he-search-loc (point) (current-buffer)))) + (unless expansion + (setq he-search-window (next-window he-search-window nil flag)) + (if (eq he-search-window (selected-window)) + (set-marker he-search-loc nil) + (set-marker he-search-loc (window-start he-search-window) + (window-buffer he-search-window))))) - (set-buffer buf) (if (not expansion) (progn (if old (he-reset-string)) @@ -1187,5 +1176,4 @@ string). It returns t if a new completion is found, nil otherwise." (provide 'hippie-exp) -;; arch-tag: 5e6e00bf-b061-4a7a-9b46-de0ae105ab99 ;;; hippie-exp.el ends here