Mercurial > emacs
comparison lisp/hippie-exp.el @ 106377:10ceddf3698e
(try-expand-dabbrev-visible): Preserve point in the
buffers visited. Remove redundant current-buffer-saving.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Thu, 03 Dec 2009 01:33:56 +0000 |
parents | 009383a57ce8 |
children | 1d1d5d9bd884 |
comparison
equal
deleted
inserted
replaced
106376:642af15d3e89 | 106377:10ceddf3698e |
---|---|
78 ;; list in shell-like buffers. At other times, only confusing. | 78 ;; list in shell-like buffers. At other times, only confusing. |
79 ;; `try-expand-line-all-buffers' : Like `try-expand-line' but searches | 79 ;; `try-expand-line-all-buffers' : Like `try-expand-line' but searches |
80 ;; in all buffers (except the current). (This may be a little | 80 ;; in all buffers (except the current). (This may be a little |
81 ;; slow, don't use it unless you are really fond of `hippie-expand'.) | 81 ;; slow, don't use it unless you are really fond of `hippie-expand'.) |
82 ;; `try-expand-list' : Tries to expand the text back to the nearest | 82 ;; `try-expand-list' : Tries to expand the text back to the nearest |
83 ;; open delimiter, to a whole list from the buffer. Convenient for | 83 ;; open delimiter, to a whole list from the buffer. Convenient for |
84 ;; example when writing lisp or TeX. | 84 ;; example when writing Lisp or TeX. |
85 ;; `try-expand-list-all-buffers' : Like `try-expand-list' but searches | 85 ;; `try-expand-list-all-buffers' : Like `try-expand-list' but searches |
86 ;; in all buffers (except the current). | 86 ;; in all buffers (except the current). |
87 ;; `try-expand-dabbrev' : works exactly as dabbrev-expand (but of | 87 ;; `try-expand-dabbrev' : works exactly as dabbrev-expand (but of |
88 ;; course in a way compatible with the other try-functions). | 88 ;; course in a way compatible with the other try-functions). |
89 ;; `try-expand-dabbrev-all-buffers' : perhaps the most useful of them, | 89 ;; `try-expand-dabbrev-all-buffers' : perhaps the most useful of them, |
114 ;; in ".emacs" to make `hippie-expand' behave maximally convenient | 114 ;; in ".emacs" to make `hippie-expand' behave maximally convenient |
115 ;; according to personal taste. Also, instead of loading the | 115 ;; according to personal taste. Also, instead of loading the |
116 ;; variable with all kinds of try-functions above, it might be an | 116 ;; variable with all kinds of try-functions above, it might be an |
117 ;; idea to use `make-hippie-expand-function' to construct different | 117 ;; idea to use `make-hippie-expand-function' to construct different |
118 ;; `hippie-expand'-like functions, with different try-lists and bound | 118 ;; `hippie-expand'-like functions, with different try-lists and bound |
119 ;; to different keys. It is also possible to make | 119 ;; to different keys. It is also possible to make |
120 ;; `hippie-expand-try-functions-list' a buffer local variable, and | 120 ;; `hippie-expand-try-functions-list' a buffer local variable, and |
121 ;; let it depend on the mode (by setting it in the mode-hooks). | 121 ;; let it depend on the mode (by setting it in the mode-hooks). |
122 ;; | 122 ;; |
123 ;; To write new try-functions, consider the following: | 123 ;; To write new try-functions, consider the following: |
124 ;; Each try-function takes one argument OLD which is nil the first | 124 ;; Each try-function takes one argument OLD which is nil the first |
926 (progn | 926 (progn |
927 (he-substitute-string expansion t) | 927 (he-substitute-string expansion t) |
928 t)))) | 928 t)))) |
929 | 929 |
930 (defun try-expand-dabbrev-all-buffers (old) | 930 (defun try-expand-dabbrev-all-buffers (old) |
931 "Tries to expand word \"dynamically\", searching all other buffers. | 931 "Try to expand word \"dynamically\", searching all other buffers. |
932 The argument OLD has to be nil the first call of this function, and t | 932 The argument OLD has to be nil the first call of this function, and t |
933 for subsequent calls (for further possible expansions of the same | 933 for subsequent calls (for further possible expansions of the same |
934 string). It returns t if a new expansion is found, nil otherwise." | 934 string). It returns t if a new expansion is found, nil otherwise." |
935 (let ((expansion ()) | 935 (let ((expansion ()) |
936 (buf (current-buffer)) | 936 (buf (current-buffer)) |
984 "Try to expand word \"dynamically\", searching visible window parts. | 984 "Try to expand word \"dynamically\", searching visible window parts. |
985 The argument OLD has to be nil the first call of this function, and t | 985 The argument OLD has to be nil the first call of this function, and t |
986 for subsequent calls (for further possible expansions of the same | 986 for subsequent calls (for further possible expansions of the same |
987 string). It returns t if a new expansion is found, nil otherwise." | 987 string). It returns t if a new expansion is found, nil otherwise." |
988 (let ((expansion ()) | 988 (let ((expansion ()) |
989 (buf (current-buffer)) | |
990 (flag (if (frame-visible-p (window-frame (selected-window))) | 989 (flag (if (frame-visible-p (window-frame (selected-window))) |
991 'visible t))) | 990 'visible t))) |
992 (if (not old) | 991 (unless old |
993 (progn | 992 (he-init-string (he-dabbrev-beg) (point)) |
994 (he-init-string (he-dabbrev-beg) (point)) | 993 (setq he-search-window (selected-window)) |
995 (setq he-search-window (selected-window)) | 994 (set-marker he-search-loc |
996 (set-marker he-search-loc | 995 (window-start he-search-window) |
997 (window-start he-search-window) | 996 (window-buffer he-search-window))) |
998 (window-buffer he-search-window)))) | |
999 | 997 |
1000 (while (and (not (equal he-search-string "")) | 998 (while (and (not (equal he-search-string "")) |
1001 (marker-position he-search-loc) | 999 (marker-position he-search-loc) |
1002 (not expansion)) | 1000 (not expansion)) |
1003 (with-current-buffer (marker-buffer he-search-loc) | 1001 (with-current-buffer (marker-buffer he-search-loc) |
1004 (goto-char he-search-loc) | 1002 (save-excursion |
1005 (setq expansion (he-dabbrev-search he-search-string () | 1003 (goto-char he-search-loc) |
1006 (window-end he-search-window))) | 1004 (setq expansion (he-dabbrev-search he-search-string () |
1007 (if (and expansion | 1005 (window-end he-search-window))) |
1008 (eq (marker-buffer he-string-beg) (current-buffer)) | 1006 (if (and expansion |
1009 (eq (marker-position he-string-beg) (match-beginning 0))) | 1007 (eq (marker-buffer he-string-beg) (current-buffer)) |
1010 (setq expansion (he-dabbrev-search he-search-string () | 1008 (eq (marker-position he-string-beg) (match-beginning 0))) |
1011 (window-end he-search-window)))) | 1009 (setq expansion |
1012 (set-marker he-search-loc (point) (current-buffer))) | 1010 (he-dabbrev-search he-search-string () |
1013 (if (not expansion) | 1011 (window-end he-search-window)))) |
1014 (progn | 1012 (set-marker he-search-loc (point) (current-buffer)))) |
1015 (setq he-search-window (next-window he-search-window nil flag)) | 1013 (unless expansion |
1016 (if (eq he-search-window (selected-window)) | 1014 (setq he-search-window (next-window he-search-window nil flag)) |
1017 (set-marker he-search-loc nil) | 1015 (if (eq he-search-window (selected-window)) |
1018 (set-marker he-search-loc (window-start he-search-window) | 1016 (set-marker he-search-loc nil) |
1019 (window-buffer he-search-window)))))) | 1017 (set-marker he-search-loc (window-start he-search-window) |
1020 | 1018 (window-buffer he-search-window))))) |
1021 (set-buffer buf) | 1019 |
1022 (if (not expansion) | 1020 (if (not expansion) |
1023 (progn | 1021 (progn |
1024 (if old (he-reset-string)) | 1022 (if old (he-reset-string)) |
1025 ()) | 1023 ()) |
1026 (progn | 1024 (progn |