]> code.delx.au - gnu-emacs/blobdiff - lisp/hippie-exp.el
Merge from mainline.
[gnu-emacs] / lisp / hippie-exp.el
index ba1c4a0746bb7962080a9b6bd431412e63e05c60..68c8f70cae3cc6057a5095be99399ef86a8752c6 100644 (file)
@@ -1,7 +1,7 @@
 ;;; hippie-exp.el --- expand text trying various ways to find its expansion
 
 ;;; 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, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+;;   2009, 2010  Free Software Foundation, Inc.
 
 ;; Author: Anders Holst <aho@sans.kth.se>
 ;; Last change: 3 March 1998
 
 ;; Author: Anders Holst <aho@sans.kth.se>
 ;; Last change: 3 March 1998
@@ -80,8 +80,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
 ;;      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
 ;;    `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
 ;;  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
 ;;  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).
 ;;
 ;;  `hippie-expand-try-functions-list' a buffer local variable, and
 ;;  let it depend on the mode (by setting it in the mode-hooks).
 ;;
@@ -251,7 +251,7 @@ If nil, all buffers are searched."
   :group 'hippie-expand)
 
 ;;;###autoload
   :group 'hippie-expand)
 
 ;;;###autoload
-(defcustom hippie-expand-ignore-buffers '("^ \\*.*\\*$" dired-mode)
+(defcustom hippie-expand-ignore-buffers (list (purecopy "^ \\*.*\\*$") 'dired-mode)
   "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)"
   "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)"
@@ -519,7 +519,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)
 (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))) ?/))
         (if (and (string-match "\\\\" dir-part)
                  (not (string-match "/" dir-part))
                  (= (aref name-part (1- (length name-part))) ?/))
@@ -928,7 +928,7 @@ string).  It returns t if a new expansion is found, nil otherwise."
          t))))
 
 (defun try-expand-dabbrev-all-buffers (old)
          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."
 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 +986,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 ())
 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)))
        (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 ""))
 
     (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))
     (if (not expansion)
        (progn
          (if old (he-reset-string))