diff options
| author | Richard M. Stallman | 1994-12-24 01:30:55 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-12-24 01:30:55 +0000 |
| commit | 7313ccdbd00f786160b04715c7dcb664e7ebffc0 (patch) | |
| tree | 30f086efd1b581ae60f8fb6fae96f554796cbadd | |
| parent | 6163b3ba745fd0fe24d0924b70884ef2295d80df (diff) | |
| download | emacs-7313ccdbd00f786160b04715c7dcb664e7ebffc0.tar.gz emacs-7313ccdbd00f786160b04715c7dcb664e7ebffc0.zip | |
Don't require cl, picture, or reporter.
Don't provide new-dabbrev.
(dabbrev--try-find): Don't use `loop'.
Don't create or kill local bindings.
(dabbrev-completion): Use key-description to say what to type.
Fix style of "done" message.
(dabbrev-submit-feedback): Function deleted.
(dabbrev--same-major-mode-p): Simplify.
(dabbrev-completion, dabbrev--abbrev-at-point): Fix error msg style.
(dabbrev-filter-elements): New macro.
(dabbrev--select-buffers, dabbrev--find-expansion): Use that.
(dabbrev--search): Use that.
| -rw-r--r-- | lisp/dabbrev.el | 355 |
1 files changed, 130 insertions, 225 deletions
diff --git a/lisp/dabbrev.el b/lisp/dabbrev.el index fdb9e27c805..f9df40e211b 100644 --- a/lisp/dabbrev.el +++ b/lisp/dabbrev.el | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | ;;; new-dabbrev.el --- dynamic abbreviation package | 1 | ;;; dabbrev.el --- dynamic abbreviation package |
| 2 | ;; Copyright (C) 1985, 1986 Free Software Foundation, Inc. | 2 | ;; Copyright (C) 1985, 1986, 1992, 1994 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | ;; Author: Don Morrison | 4 | ;; Author: Don Morrison |
| 5 | ;; Maintainer: Lars Lindberg <Lars.Lindberg@sypro.cap.se> | 5 | ;; Maintainer: Lars Lindberg <Lars.Lindberg@sypro.cap.se> |
| @@ -32,14 +32,14 @@ | |||
| 32 | ;; M-/ (dabbrev-expand) or M-C-/ (dabbrev-completion). | 32 | ;; M-/ (dabbrev-expand) or M-C-/ (dabbrev-completion). |
| 33 | ;; | 33 | ;; |
| 34 | ;; There are powerful things in this package that aren't turned on by | 34 | ;; There are powerful things in this package that aren't turned on by |
| 35 | ;; default. I recommend you to do the following. | 35 | ;; default. I recommend you to do the following. |
| 36 | ;; | 36 | ;; |
| 37 | ;; Put the following 2 lines in your .emacs file: | 37 | ;; Put the following 2 lines in your .emacs file: |
| 38 | ;; (setq dabbrev-always-check-other-buffers t) | 38 | ;; (setq dabbrev-always-check-other-buffers t) |
| 39 | ;; (setq dabbrev-abbrev-char-regexp "\\sw\\|\\s_") | 39 | ;; (setq dabbrev-abbrev-char-regexp "\\sw\\|\\s_") |
| 40 | ;; | 40 | ;; |
| 41 | ;; Dabbrev will now search in all buffers with the same major mode for | 41 | ;; Dabbrev will now search in all buffers with the same major mode for |
| 42 | ;; your expansions. It will also search for complete symbols, the old | 42 | ;; your expansions. It will also search for complete symbols, the old |
| 43 | ;; dabbrev package only looked half-heartedly for symbols. | 43 | ;; dabbrev package only looked half-heartedly for symbols. |
| 44 | ;; | 44 | ;; |
| 45 | ;; Check out the customizable variables below to learn about all the | 45 | ;; Check out the customizable variables below to learn about all the |
| @@ -72,69 +72,6 @@ | |||
| 72 | ;; (set-buffer buffer) | 72 | ;; (set-buffer buffer) |
| 73 | ;; (memq major-mode '(news-reply-mode gnus-article-mode))))) | 73 | ;; (memq major-mode '(news-reply-mode gnus-article-mode))))) |
| 74 | 74 | ||
| 75 | ;;; Change Log | ||
| 76 | ;; 4.4.2 1994-11-25 | ||
| 77 | ;; Added new variable; `dabbrev-check-rest-of-buffers'. | ||
| 78 | ;; 4.4.1 1994-11-24 | ||
| 79 | ;; Now has correct creation date. | ||
| 80 | ;; Added kill-ring idea to "Future enhancements". | ||
| 81 | ;; 4.4 1994-11-22 | ||
| 82 | ;; Changed the copyright text. Thanks [hymie]. | ||
| 83 | ;; new-dabbrev now handles abbrevs that starts with symbol | ||
| 84 | ;; syntax. Thanks [burgett] for kicking me to do it. | ||
| 85 | ;; Now also handles `dabbrev-abbrev-skip-leading-regexp' better. | ||
| 86 | ;; 4.3 1994-11-14 | ||
| 87 | ;; Now only displays "Expansion found in <buffer>" when the | ||
| 88 | ;; expansion has been found in buffers that hasn't been examined | ||
| 89 | ;; yet. Thanks [kifer]. | ||
| 90 | ;; Added a new variable; `dabbrev-search-these-buffers-only'. | ||
| 91 | ;; Fixed bug in mini-buffer completion. Thanks [kifer]. | ||
| 92 | ;; Found a real time-waster when using `dabbrev-completion'. | ||
| 93 | ;; Thanks for the elp.el package Barry Warsaw! | ||
| 94 | ;; Found bug that made point move in other buffers. | ||
| 95 | ;; Now handles Lucid emacs define-key style. | ||
| 96 | ;; Thanks [jules]. | ||
| 97 | ;; Now uses the `<symbol>' syntax in doc strings. | ||
| 98 | ;; Cosmetic bugs and syntactical bugs in documentation strings. | ||
| 99 | ;; Thanks [hawley]. | ||
| 100 | ;; 4.2 1994-03-04 | ||
| 101 | ;; Now searches other buffers again. Thanks [ake]. | ||
| 102 | ;; 4.1 1994-02-22 | ||
| 103 | ;; Introduced the new variables `dabbrev-case-fold-search' and | ||
| 104 | ;; `dabbrev-case-replace'. | ||
| 105 | ;; Introduced the new variable `dabbrev-select-buffers-function'. | ||
| 106 | ;; Introduced the new variable `dabbrev-abbrev-skip-leading-regexp'. | ||
| 107 | ;; Changed `dabbrev-always-check-other-buffers' to not buffer local. | ||
| 108 | ;; Thanks [kifer]. | ||
| 109 | ;; Bug in `dabbrev-completion', x expanded to xxy instead of xy. | ||
| 110 | ;; Thanks [kifer]. | ||
| 111 | ;; Added `dabbrev-submit-feedback' for better error-reporting. | ||
| 112 | ;; The hooks (`dabbrev-select-buffers-function' and | ||
| 113 | ;; `dabbrev-friend-buffer-function') are now not automatically | ||
| 114 | ;; buffer local. | ||
| 115 | ;; Now provides dabbrev too. | ||
| 116 | ;; 3.2 1993-12-14 | ||
| 117 | ;; Message for expansion found in buffer other than current. | ||
| 118 | ;; Minor bugs. | ||
| 119 | ;; 3.1 1993-12-13 | ||
| 120 | ;; Better comment for `dabbrev-abbrev-char-regexp'. | ||
| 121 | ;; 3.0 1993-12-09 | ||
| 122 | ;; Freshed things up for the release. | ||
| 123 | ;; `dabbrev-completion' now doesn't have to use the minibuffer. | ||
| 124 | ;; Thanks [alon]. | ||
| 125 | ;; 2.0 1993-12-02 Lars Lindberg <lli@sypro.cap.se> | ||
| 126 | ;; Searches in other buffers for the expansion. | ||
| 127 | ;; Works also for the minibuffer. | ||
| 128 | ;; Added `dabbrev-completion'. | ||
| 129 | ;; More efficient code. | ||
| 130 | ;; Found minor bugs. | ||
| 131 | ;; 1.0 converted to Emacs Lisp by Spencer Thomas. | ||
| 132 | ;; Thoroughly cleaned up by Richard Stallman. | ||
| 133 | ;; 0.0 | ||
| 134 | ;; DABBREVS - "Dynamic abbreviations" hack, originally written by | ||
| 135 | ;; Don Morrison for Twenex Emacs. Converted to mlisp by Russ Fish. | ||
| 136 | ;; Supports the table feature to avoid hitting the same expansion on | ||
| 137 | ;; re-expand, and the search size limit variable. | ||
| 138 | 75 | ||
| 139 | ;; Known bugs and limitations. | 76 | ;; Known bugs and limitations. |
| 140 | ;; - Possible to do several levels of `dabbrev-completion' in the | 77 | ;; - Possible to do several levels of `dabbrev-completion' in the |
| @@ -146,8 +83,8 @@ | |||
| 146 | ;; - Check the tags-files? Like tags-complete? | 83 | ;; - Check the tags-files? Like tags-complete? |
| 147 | ;; - Add the possibility of searching both forward and backward to | 84 | ;; - Add the possibility of searching both forward and backward to |
| 148 | ;; the nearest expansion. | 85 | ;; the nearest expansion. |
| 149 | ;; - Check the kill-ring when everything else fails. (Maybe something | 86 | ;; - Check the kill-ring when everything else fails. (Maybe something |
| 150 | ;; for hippie-expand?). [Bng] <boris@cs.rochester.edu> | 87 | ;; for hippie-expand?). [Bng] <boris@cs.rochester.edu> |
| 151 | 88 | ||
| 152 | ;;; Thanks goes to | 89 | ;;; Thanks goes to |
| 153 | ;; [hymie] Hyman Rosen <marks!hymie@jyacc.jyacc.com> | 90 | ;; [hymie] Hyman Rosen <marks!hymie@jyacc.jyacc.com> |
| @@ -164,7 +101,6 @@ | |||
| 164 | ;; ... and to all the people who have participated in the beta tests. | 101 | ;; ... and to all the people who have participated in the beta tests. |
| 165 | 102 | ||
| 166 | ;;; Code: | 103 | ;;; Code: |
| 167 | (require 'cl) | ||
| 168 | 104 | ||
| 169 | ;;;---------------------------------------------------------------- | 105 | ;;;---------------------------------------------------------------- |
| 170 | ;;;---------------------------------------------------------------- | 106 | ;;;---------------------------------------------------------------- |
| @@ -172,7 +108,7 @@ | |||
| 172 | ;;;---------------------------------------------------------------- | 108 | ;;;---------------------------------------------------------------- |
| 173 | ;;;---------------------------------------------------------------- | 109 | ;;;---------------------------------------------------------------- |
| 174 | (defvar dabbrev-backward-only nil | 110 | (defvar dabbrev-backward-only nil |
| 175 | "*If non-NIL, `dabbrev-expand' only looks backwards.") | 111 | "*If non-nil, `dabbrev-expand' only looks backwards.") |
| 176 | 112 | ||
| 177 | (defvar dabbrev-limit nil | 113 | (defvar dabbrev-limit nil |
| 178 | "*Limits region searched by `dabbrev-expand' to this many chars away.") | 114 | "*Limits region searched by `dabbrev-expand' to this many chars away.") |
| @@ -180,72 +116,67 @@ | |||
| 180 | (defvar dabbrev-abbrev-skip-leading-regexp nil | 116 | (defvar dabbrev-abbrev-skip-leading-regexp nil |
| 181 | "*Regexp for skipping leading characters of an abbreviation. | 117 | "*Regexp for skipping leading characters of an abbreviation. |
| 182 | 118 | ||
| 183 | Example: Set this to \"\\\\$\" for programming languages that sometimes | 119 | Example: Set this to \"\\\\$\" for programming languages |
| 184 | has and sometimes has not a leading $ for variable names. | 120 | in which variable names may appear with or without a leading `$'. |
| 121 | (For example, in Makefiles.) | ||
| 185 | 122 | ||
| 186 | Set this to nil if no characters should be skipped.") | 123 | Set this to nil if no characters should be skipped.") |
| 187 | 124 | ||
| 188 | ;; I recommend that you set this to nil. | 125 | ;; I recommend that you set this to nil. |
| 189 | (defvar dabbrev-case-fold-search 'case-fold-search | 126 | (defvar dabbrev-case-fold-search 'case-fold-search |
| 190 | "*T if dabbrev searches should ignore case. | 127 | "*Non-nil if dabbrev searches should ignore case. |
| 191 | nil if case is significant. | 128 | A value of nil means case is significant. |
| 192 | Non-nil and not t means evaluate for value. | ||
| 193 | 129 | ||
| 194 | Example:Setting this to 'case-fold-search means evaluate that variable | 130 | The value of this variable is an expression; it is evaluated |
| 195 | to see if it is t or non-nil.") | 131 | and the resulting value determines the decision. |
| 132 | For example: setting this to `case-fold-search' means evaluate that | ||
| 133 | variable to see whether its value is nil.") | ||
| 196 | 134 | ||
| 197 | (defvar dabbrev-upcase-means-case-search nil | 135 | (defvar dabbrev-upcase-means-case-search nil |
| 198 | "*The significance of an uppercase character in an abbreviation. | 136 | "*The significance of an uppercase character in an abbreviation. |
| 137 | nil means case fold search, non-nil means case sensitive search. | ||
| 199 | 138 | ||
| 200 | This variable only makes sense when the value of | 139 | This variable has an effect only when the value of |
| 201 | `dabbrev-case-fold-search' evaluates to t. | 140 | `dabbrev-case-fold-search' evaluates to t.") |
| 202 | |||
| 203 | nil = case fold search | ||
| 204 | t = case sensitive search") | ||
| 205 | 141 | ||
| 206 | ;; I recommend that you set this to nil. | 142 | ;; I recommend that you set this to nil. |
| 207 | (defvar dabbrev-case-replace 'case-replace | 143 | (defvar dabbrev-case-replace 'case-replace |
| 208 | "*T if dabbrev should preserve case when expanding the abbreviation. | 144 | "*Non-nil means dabbrev should preserve case when expanding the abbreviation. |
| 209 | nil if it should not. | 145 | The value of this variable is an expression; it is evaluated |
| 210 | Non-nil and not t means evaluate for value. | 146 | and the resulting value determines the decision. |
| 211 | 147 | For example, setting this to `case-replace' means evaluate that | |
| 212 | This variable only makes sense when the value of | 148 | variable to see if its value is t or nil. |
| 213 | `dabbrev-case-fold-search' evaluates to t. | ||
| 214 | 149 | ||
| 215 | Example: Setting this to 'case-replace means evaluate that variable to | 150 | This variable has an effect only when the value of |
| 216 | see if it is t or non-nil.") | 151 | `dabbrev-case-fold-search' evaluates to t.") |
| 217 | 152 | ||
| 218 | ;; I recommend that you set this to "\\sw\\|\\s_" | 153 | ;; I recommend that you set this to "\\sw\\|\\s_" |
| 219 | (defvar dabbrev-abbrev-char-regexp nil | 154 | (defvar dabbrev-abbrev-char-regexp nil |
| 220 | "*A regexp that recognizes a character in an abbreviation or an | 155 | "*Regexp to recognize a character in an abbreviation or expansion. |
| 221 | expansion. Will be surrounded with \\\\( ... \\\\) when used. | 156 | This regexp will be surrounded with \\\\( ... \\\\) when actually used. |
| 222 | 157 | ||
| 223 | Set this to \"\\\\sw\" if you want ordinary words or | 158 | Set this variable to \"\\\\sw\" if you want ordinary words or |
| 224 | \"\\\\sw\\\\|\\\\s_\" if you want symbols. | 159 | \"\\\\sw\\\\|\\\\s_\" if you want symbols. |
| 225 | 160 | ||
| 226 | You can also set it to nil if you want old-style dabbrev searching | 161 | You can also set it to nil if you want old-style dabbrev searching |
| 227 | (the abbreviation is from point to previous word-start, the | 162 | \(the abbreviation is from point to previous word-start, the |
| 228 | search is for symbols). | 163 | search is for symbols). |
| 229 | 164 | ||
| 230 | For instance, if you are programming in Lisp, yes-or-no-p is a symbol, | 165 | For instance, if you are programming in Lisp, `yes-or-no-p' is a symbol, |
| 231 | while 'yes', 'or', 'no' and 'p' are considered words. If you set this | 166 | while `yes', `or', `no' and `p' are considered words. If you set this |
| 232 | variable to nil, then expanding yes-or-no- will look for a symbol | 167 | variable to nil, then expanding `yes-or-no-' looks for a symbol |
| 233 | starting with or containing 'no-'. If you set this variable to | 168 | starting with or containing `no-'. If you set this variable to |
| 234 | \"\\\\sw\\\\|\\\\s_\" dabbrev will look for a symbol starting with | 169 | \"\\\\sw\\\\|\\\\s_\", that expansion looks for a symbol starting with |
| 235 | \"yes-or-no-\". Finally, if you set this variable to \"\\\\sw\", then an | 170 | `yes-or-no-'. Finally, if you set this variable to \"\\\\sw\", then |
| 236 | error will be signalled, because \"-\" is not part of a word but if you | 171 | expanding `yes-or-no-' signals an error because `-' is not part of a word; |
| 237 | try to expand \"yes-or-no\", dabbrev will look for a word starting with | 172 | but expanding `yes-or-no' looks for a word starting with `no'. |
| 238 | \"no\". | ||
| 239 | 173 | ||
| 240 | The recommended value is \"\\\\sw\\\\|\\\\s_\".") | 174 | The recommended value is \"\\\\sw\\\\|\\\\s_\".") |
| 241 | 175 | ||
| 242 | ;; I recommend that you set this to t. | 176 | (defvar dabbrev-check-rest-of-buffers t |
| 243 | (defvar dabbrev-check-rest-of-buffers nil | 177 | "*Non-nil means dabbrev package should search in all buffers. |
| 244 | "*Should dabbrev package search in all buffers?. | 178 | It searches the buffers pointed out by `dabbrev-select-buffers-function' |
| 245 | 179 | first; afterward it looks in the rest of the buffers.") | |
| 246 | Non-nil means first look in buffers pointed out by | ||
| 247 | `dabbrev-select-buffers-function' and then look in the rest of the | ||
| 248 | buffers.") | ||
| 249 | 180 | ||
| 250 | 181 | ||
| 251 | ;; I recommend that you set this to t. | 182 | ;; I recommend that you set this to t. |
| @@ -277,17 +208,17 @@ The function should take one argument, OTHER-BUFFER, and return | |||
| 277 | non-nil if that buffer should be searched. Have a look at | 208 | non-nil if that buffer should be searched. Have a look at |
| 278 | `dabbrev--same-major-mode-p' for an example. | 209 | `dabbrev--same-major-mode-p' for an example. |
| 279 | 210 | ||
| 280 | Setting this makes sense only if the function pointed out by | 211 | The value of `dabbrev-friend-buffer-function' has an effect only if |
| 281 | `dabbrev-select-buffers-function' uses it. The package function | 212 | the value of `dabbrev-select-buffers-function' uses it. The function |
| 282 | `dabbrev--select-buffers' is such a function. | 213 | `dabbrev--select-buffers' is one function you can use here. |
| 283 | 214 | ||
| 284 | A mode setting this variable should make it buffer local.") | 215 | A mode setting this variable should make it buffer local.") |
| 285 | 216 | ||
| 286 | (defvar dabbrev-search-these-buffers-only nil | 217 | (defvar dabbrev-search-these-buffers-only nil |
| 287 | "Should be a list of buffers if non-nil. | 218 | "If non-nil, a list of buffers which dabbrev should search. |
| 288 | 219 | If this variable is non-nil, dabbrev will only look in these buffers. | |
| 289 | Dabbrev search will only look in these buffers. It will not even look | 220 | It will not even look in the current buffer if it is not a member of |
| 290 | in the current buffer if it is not a member of this list.") | 221 | this list.") |
| 291 | 222 | ||
| 292 | ;;;---------------------------------------------------------------- | 223 | ;;;---------------------------------------------------------------- |
| 293 | ;;;---------------------------------------------------------------- | 224 | ;;;---------------------------------------------------------------- |
| @@ -344,6 +275,20 @@ in the current buffer if it is not a member of this list.") | |||
| 344 | (defsubst dabbrev--minibuffer-origin () | 275 | (defsubst dabbrev--minibuffer-origin () |
| 345 | (car (cdr (buffer-list)))) | 276 | (car (cdr (buffer-list)))) |
| 346 | 277 | ||
| 278 | ;; Make a list of some of the elements of LIST. | ||
| 279 | ;; Check each element of LIST, storing it temporarily in the | ||
| 280 | ;; variable ELEMENT, and include it in the result | ||
| 281 | ;; if CONDITION evaluates non-nil. | ||
| 282 | (defmacro dabbrev-filter-elements (element list condition) | ||
| 283 | (` (let (dabbrev-result dabbrev-tail (, element)) | ||
| 284 | (setq dabbrev-tail (, list)) | ||
| 285 | (while dabbrev-tail | ||
| 286 | (setq (, element) (car dabbrev-tail)) | ||
| 287 | (if (, condition) | ||
| 288 | (setq dabbrev-result (cons (, element) dabbrev-result))) | ||
| 289 | (setq dabbrev-tail (cdr dabbrev-tail))) | ||
| 290 | (nreverse dabbrev-result)))) | ||
| 291 | |||
| 347 | ;;;---------------------------------------------------------------- | 292 | ;;;---------------------------------------------------------------- |
| 348 | ;;;---------------------------------------------------------------- | 293 | ;;;---------------------------------------------------------------- |
| 349 | ;;; Exported functions | 294 | ;;; Exported functions |
| @@ -352,24 +297,22 @@ in the current buffer if it is not a member of this list.") | |||
| 352 | 297 | ||
| 353 | ;;;###autoload | 298 | ;;;###autoload |
| 354 | (define-key esc-map "/" 'dabbrev-expand) | 299 | (define-key esc-map "/" 'dabbrev-expand) |
| 300 | ;;;??? Do we want this? | ||
| 355 | ;;;###autoload | 301 | ;;;###autoload |
| 356 | (if (string-match "Lucid$" emacs-version) | 302 | (define-key esc-map [?\C-/] 'dabbrev-completion)) |
| 357 | (define-key esc-map [(control /)] 'dabbrev-completion) | ||
| 358 | (define-key esc-map [?\C-/] 'dabbrev-completion)) | ||
| 359 | 303 | ||
| 360 | ;;;###autoload | 304 | ;;;###autoload |
| 361 | (defun dabbrev-completion (&optional arg) | 305 | (defun dabbrev-completion (&optional arg) |
| 362 | "Completion on current word. | 306 | "Completion on current word. |
| 363 | |||
| 364 | Like \\[dabbrev-expand] but finds all expansions in the current buffer | 307 | Like \\[dabbrev-expand] but finds all expansions in the current buffer |
| 365 | and presents suggestions for completion. | 308 | and presents suggestions for completion. |
| 366 | 309 | ||
| 367 | If you call this function with prefix ARG, then it searches all | 310 | With a prefix argument, it searches all buffers accepted by the |
| 368 | buffers accepted by the function pointed out by | 311 | function pointed out by `dabbrev-friend-buffer-function' to find the |
| 369 | `dabbrev-friend-buffer-function' to find the completions. | 312 | completions. \(The argument value does not matter.) |
| 370 | 313 | ||
| 371 | With no prefix ARG it tries to reuse the old completion list | 314 | With no prefix argument, it reuses an old completion list |
| 372 | before making a new one." | 315 | if there is a suitable one already." |
| 373 | 316 | ||
| 374 | (interactive "*P") | 317 | (interactive "*P") |
| 375 | (let* ((dabbrev-always-check-other-buffers (and arg t)) | 318 | (let* ((dabbrev-always-check-other-buffers (and arg t)) |
| @@ -392,10 +335,8 @@ before making a new one." | |||
| 392 | (substring abbrev 0 | 335 | (substring abbrev 0 |
| 393 | (length dabbrev--last-abbreviation))) | 336 | (length dabbrev--last-abbreviation))) |
| 394 | (setq init (try-completion abbrev my-obarray))) | 337 | (setq init (try-completion abbrev my-obarray))) |
| 395 | ;;-------------------------------- | 338 | ;; We can reuse the existing completion list. |
| 396 | ;; This is a continue. | 339 | nil |
| 397 | ;;-------------------------------- | ||
| 398 | (progn) | ||
| 399 | ;;-------------------------------- | 340 | ;;-------------------------------- |
| 400 | ;; New abbreviation to expand. | 341 | ;; New abbreviation to expand. |
| 401 | ;;-------------------------------- | 342 | ;;-------------------------------- |
| @@ -407,7 +348,7 @@ before making a new one." | |||
| 407 | ;; Make an obarray with all expansions | 348 | ;; Make an obarray with all expansions |
| 408 | (setq my-obarray (make-vector (length completion-list) 0)) | 349 | (setq my-obarray (make-vector (length completion-list) 0)) |
| 409 | (or (> (length my-obarray) 0) | 350 | (or (> (length my-obarray) 0) |
| 410 | (error "No dynamic expansion for \"%s\" found%s." | 351 | (error "No dynamic expansion for \"%s\" found%s" |
| 411 | abbrev | 352 | abbrev |
| 412 | (if dabbrev--check-other-buffers "" " in this-buffer"))) | 353 | (if dabbrev--check-other-buffers "" " in this-buffer"))) |
| 413 | (cond | 354 | (cond |
| @@ -443,7 +384,8 @@ before making a new one." | |||
| 443 | ((and (not (string-equal init "")) | 384 | ((and (not (string-equal init "")) |
| 444 | (not (string-equal (downcase init) (downcase abbrev)))) | 385 | (not (string-equal (downcase init) (downcase abbrev)))) |
| 445 | (if (> (length (all-completions init my-obarray)) 1) | 386 | (if (> (length (all-completions init my-obarray)) 1) |
| 446 | (message "Repeat '%s' to see all completions" this-command) | 387 | (message "Repeat `%s' to see all completions" |
| 388 | (key-description (this-command-keys))) | ||
| 447 | (message "The only possible completion")) | 389 | (message "The only possible completion")) |
| 448 | (dabbrev--substitute-expansion nil abbrev init)) | 390 | (dabbrev--substitute-expansion nil abbrev init)) |
| 449 | (t | 391 | (t |
| @@ -451,7 +393,7 @@ before making a new one." | |||
| 451 | (message "Making completion list...") | 393 | (message "Making completion list...") |
| 452 | (with-output-to-temp-buffer " *Completions*" | 394 | (with-output-to-temp-buffer " *Completions*" |
| 453 | (display-completion-list (all-completions init my-obarray))) | 395 | (display-completion-list (all-completions init my-obarray))) |
| 454 | (message "Making completion list... Done."))) | 396 | (message "Making completion list...done"))) |
| 455 | (and (window-minibuffer-p (selected-window)) | 397 | (and (window-minibuffer-p (selected-window)) |
| 456 | (message nil)))) | 398 | (message nil)))) |
| 457 | 399 | ||
| @@ -465,7 +407,7 @@ considered. If still no suitable word is found, then look in the | |||
| 465 | buffers accepted by the function pointed out by variable | 407 | buffers accepted by the function pointed out by variable |
| 466 | `dabbrev-friend-buffer-function'. | 408 | `dabbrev-friend-buffer-function'. |
| 467 | 409 | ||
| 468 | A positive prefix argument, N, says to take the Nth backward _distinct_ | 410 | A positive prefix argument, N, says to take the Nth backward *distinct* |
| 469 | possibility. A negative argument says search forward. | 411 | possibility. A negative argument says search forward. |
| 470 | 412 | ||
| 471 | If the cursor has not moved from the end of the previous expansion and | 413 | If the cursor has not moved from the end of the previous expansion and |
| @@ -475,10 +417,11 @@ with the next possible expansion not yet tried. | |||
| 475 | The variable `dabbrev-backward-only' may be used to limit the | 417 | The variable `dabbrev-backward-only' may be used to limit the |
| 476 | direction of search to backward if set non-nil. | 418 | direction of search to backward if set non-nil. |
| 477 | 419 | ||
| 420 | ??? | ||
| 478 | To make it more powerful, make sure that | 421 | To make it more powerful, make sure that |
| 479 | `dabbrev-always-check-other-buffers' is set to t. | 422 | `dabbrev-always-check-other-buffers' is set to t. |
| 480 | 423 | ||
| 481 | Also check out `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." | 424 | See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." |
| 482 | (interactive "*P") | 425 | (interactive "*P") |
| 483 | (let (abbrev expansion old direction) | 426 | (let (abbrev expansion old direction) |
| 484 | ;; abbrev -- the abbrev to expand | 427 | ;; abbrev -- the abbrev to expand |
| @@ -492,16 +435,12 @@ Also check out `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." | |||
| 492 | (and (window-minibuffer-p (selected-window)) | 435 | (and (window-minibuffer-p (selected-window)) |
| 493 | (= dabbrev--last-abbrev-location | 436 | (= dabbrev--last-abbrev-location |
| 494 | (point))))) | 437 | (point))))) |
| 495 | ;;-------------------------------- | 438 | ;; Find a different expansion for the same abbrev as last time. |
| 496 | ;; This is a redo. | ||
| 497 | ;;-------------------------------- | ||
| 498 | (progn | 439 | (progn |
| 499 | (setq abbrev dabbrev--last-abbreviation) | 440 | (setq abbrev dabbrev--last-abbreviation) |
| 500 | (setq old dabbrev--last-expansion) | 441 | (setq old dabbrev--last-expansion) |
| 501 | (setq direction dabbrev--last-direction)) | 442 | (setq direction dabbrev--last-direction)) |
| 502 | ;;-------------------------------- | 443 | ;; We have a different abbrev to expand. |
| 503 | ;; New abbreviation to expand. | ||
| 504 | ;;-------------------------------- | ||
| 505 | (dabbrev--reset-global-variables) | 444 | (dabbrev--reset-global-variables) |
| 506 | (setq direction (if (null arg) | 445 | (setq direction (if (null arg) |
| 507 | (if dabbrev-backward-only 1 0) | 446 | (if dabbrev-backward-only 1 0) |
| @@ -524,7 +463,7 @@ Also check out `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." | |||
| 524 | (save-excursion | 463 | (save-excursion |
| 525 | (search-backward (substring old (length abbrev))) | 464 | (search-backward (substring old (length abbrev))) |
| 526 | (delete-region (match-beginning 0) (match-end 0)))) | 465 | (delete-region (match-beginning 0) (match-end 0)))) |
| 527 | (error "No%s dynamic expansion for \"%s\" found." | 466 | (error "No%s dynamic expansion for `%s' found" |
| 528 | (if old " further" "") abbrev)) | 467 | (if old " further" "") abbrev)) |
| 529 | (t | 468 | (t |
| 530 | (if (not (eq dabbrev--last-buffer dabbrev--last-buffer-found)) | 469 | (if (not (eq dabbrev--last-buffer dabbrev--last-buffer-found)) |
| @@ -540,26 +479,6 @@ Also check out `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." | |||
| 540 | (setq dabbrev--last-abbreviation abbrev) | 479 | (setq dabbrev--last-abbreviation abbrev) |
| 541 | (setq dabbrev--last-abbrev-location (point-marker)))))) | 480 | (setq dabbrev--last-abbrev-location (point-marker)))))) |
| 542 | 481 | ||
| 543 | (eval-when-compile (require 'reporter)) | ||
| 544 | (defun dabbrev-submit-feedback () | ||
| 545 | "Submit via mail a bug report on the dabbrev package." | ||
| 546 | (interactive) | ||
| 547 | (require 'reporter) | ||
| 548 | (and (y-or-n-p "Do you really want to submit a report on the dabbrev package? ") | ||
| 549 | (reporter-submit-bug-report | ||
| 550 | "Lars Lindberg <lli@sypro.cap.se>" | ||
| 551 | (format "new-dabbrev.el (Release %s)" (dabbrev--version)) | ||
| 552 | '(dabbrev-backward-only | ||
| 553 | dabbrev-limit | ||
| 554 | dabbrev-case-fold-search | ||
| 555 | dabbrev-case-replace | ||
| 556 | dabbrev-upcase-means-case-search | ||
| 557 | dabbrev-abbrev-char-regexp | ||
| 558 | dabbrev-always-check-other-buffers | ||
| 559 | dabbrev-select-buffers-function | ||
| 560 | dabbrev-friend-buffer-function) | ||
| 561 | nil nil nil))) | ||
| 562 | |||
| 563 | ;;;---------------------------------------------------------------- | 482 | ;;;---------------------------------------------------------------- |
| 564 | ;;;---------------------------------------------------------------- | 483 | ;;;---------------------------------------------------------------- |
| 565 | ;;; Local functions | 484 | ;;; Local functions |
| @@ -584,28 +503,29 @@ Also check out `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." | |||
| 584 | 503 | ||
| 585 | ;;; Checks if OTHER-BUFFER has the same major mode as current buffer. | 504 | ;;; Checks if OTHER-BUFFER has the same major mode as current buffer. |
| 586 | (defun dabbrev--same-major-mode-p (other-buffer) | 505 | (defun dabbrev--same-major-mode-p (other-buffer) |
| 587 | (let ((orig-mode major-mode)) | 506 | (eq major-mode |
| 588 | (save-excursion | 507 | (save-excursion |
| 589 | (set-buffer other-buffer) | 508 | (set-buffer other-buffer) |
| 590 | (eq orig-mode major-mode)))) | 509 | major-mode))) |
| 591 | 510 | ||
| 592 | ;;; Back over all abbrev type characters and then moves forward over | 511 | ;;; Back over all abbrev type characters and then moves forward over |
| 593 | ;;; all skip characters. | 512 | ;;; all skip characters. |
| 594 | (defun dabbrev--goto-start-of-abbrev () | 513 | (defun dabbrev--goto-start-of-abbrev () |
| 595 | ;; Move backwards over abbrev chars | 514 | ;; Move backwards over abbrev chars |
| 596 | (save-match-data | 515 | (save-match-data |
| 597 | (when (not (bobp)) | 516 | (if (not (bobp)) |
| 598 | (forward-char -1) | 517 | (progn |
| 599 | (while (and (looking-at dabbrev--abbrev-char-regexp) | 518 | (forward-char -1) |
| 600 | (not (bobp))) | 519 | (while (and (looking-at dabbrev--abbrev-char-regexp) |
| 601 | (forward-char -1)) | 520 | (not (bobp))) |
| 602 | (or (looking-at dabbrev--abbrev-char-regexp) | 521 | (forward-char -1)) |
| 603 | (forward-char 1))) | 522 | (or (looking-at dabbrev--abbrev-char-regexp) |
| 523 | (forward-char 1)))) | ||
| 604 | (and dabbrev-abbrev-skip-leading-regexp | 524 | (and dabbrev-abbrev-skip-leading-regexp |
| 605 | (while (looking-at dabbrev-abbrev-skip-leading-regexp) | 525 | (while (looking-at dabbrev-abbrev-skip-leading-regexp) |
| 606 | (forward-char 1))))) | 526 | (forward-char 1))))) |
| 607 | 527 | ||
| 608 | ;;; Extract the symbol at point to serve as abbrevitation. | 528 | ;;; Extract the symbol at point to serve as abbreviation. |
| 609 | (defun dabbrev--abbrev-at-point () | 529 | (defun dabbrev--abbrev-at-point () |
| 610 | ;; Check for error | 530 | ;; Check for error |
| 611 | (save-excursion | 531 | (save-excursion |
| @@ -617,7 +537,7 @@ Also check out `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." | |||
| 617 | (or dabbrev-abbrev-char-regexp | 537 | (or dabbrev-abbrev-char-regexp |
| 618 | "\\sw\\|\\s_") | 538 | "\\sw\\|\\s_") |
| 619 | "\\)+"))))) | 539 | "\\)+"))))) |
| 620 | (error "Not positioned immediately after an abbreviation.")))) | 540 | (error "Not positioned immediately after an abbreviation")))) |
| 621 | ;; Return abbrev at point | 541 | ;; Return abbrev at point |
| 622 | (save-excursion | 542 | (save-excursion |
| 623 | (setq dabbrev--last-abbrev-location (point)) | 543 | (setq dabbrev--last-abbrev-location (point)) |
| @@ -649,37 +569,26 @@ Also check out `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." | |||
| 649 | (and (window-minibuffer-p (selected-window)) | 569 | (and (window-minibuffer-p (selected-window)) |
| 650 | (set-buffer (dabbrev--minibuffer-origin))) | 570 | (set-buffer (dabbrev--minibuffer-origin))) |
| 651 | (let ((orig-buffer (current-buffer))) | 571 | (let ((orig-buffer (current-buffer))) |
| 652 | (loop for buffer | 572 | (dabbrev-filter-elements |
| 653 | in (buffer-list) | 573 | buffer (buffer-list) |
| 654 | if (and (not (eq orig-buffer buffer)) | 574 | (and (not (eq orig-buffer buffer)) |
| 655 | (boundp 'dabbrev-friend-buffer-function) | 575 | (boundp 'dabbrev-friend-buffer-function) |
| 656 | (funcall dabbrev-friend-buffer-function buffer)) | 576 | (funcall dabbrev-friend-buffer-function buffer)))))) |
| 657 | collect buffer)))) | 577 | |
| 658 | 578 | ;;; Search for ABBREV, N times, normally looking forward, | |
| 659 | ;;; Try to find ABBREV in REVERSE direction N times. | 579 | ;;; but looking in reverse instead if REVERSE is non-nil. |
| 660 | (defun dabbrev--try-find (abbrev reverse n ignore-case) | 580 | (defun dabbrev--try-find (abbrev reverse n ignore-case) |
| 661 | (save-excursion | 581 | (save-excursion |
| 662 | (let ((case-fold-search-is-local (memq 'case-fold-search | 582 | (let ((expansion nil)) |
| 663 | (buffer-local-variables))) | ||
| 664 | (expansion nil)) | ||
| 665 | (and dabbrev--last-expansion-location | 583 | (and dabbrev--last-expansion-location |
| 666 | (goto-char dabbrev--last-expansion-location)) | 584 | (goto-char dabbrev--last-expansion-location)) |
| 667 | (unwind-protect | 585 | (let ((case-fold-search ignore-case) |
| 668 | (progn | 586 | (count n)) |
| 669 | (or case-fold-search-is-local | 587 | (while (and (> count 0) |
| 670 | (make-local-variable 'case-fold-search)) | 588 | (setq expansion (dabbrev--search abbrev |
| 671 | ;; Tricky! If `case-fold-search' isn't buffer-local, then | 589 | reverse |
| 672 | ;; this innocent let creates a buffer-local variable and | 590 | ignore-case))) |
| 673 | ;; when the let returns, it is still there! The | 591 | (setq count (1- count)))) |
| 674 | ;; unwind-protect stuff around this makes sure that there | ||
| 675 | ;; exists one before the let, and removes it afterwards. | ||
| 676 | (let ((case-fold-search ignore-case)) | ||
| 677 | (loop repeat n | ||
| 678 | while (setq expansion (dabbrev--search abbrev | ||
| 679 | reverse | ||
| 680 | ignore-case))))) | ||
| 681 | (or case-fold-search-is-local | ||
| 682 | (kill-local-variable 'case-fold-search))) | ||
| 683 | (and expansion | 592 | (and expansion |
| 684 | (setq dabbrev--last-expansion-location (point))) | 593 | (setq dabbrev--last-expansion-location (point))) |
| 685 | expansion))) | 594 | expansion))) |
| @@ -695,7 +604,7 @@ Also check out `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." | |||
| 695 | all-expansions)) | 604 | all-expansions)) |
| 696 | 605 | ||
| 697 | (defun dabbrev--scanning-message () | 606 | (defun dabbrev--scanning-message () |
| 698 | (message "Scanning '%s'" (buffer-name (current-buffer)))) | 607 | (message "Scanning `%s'" (buffer-name (current-buffer)))) |
| 699 | 608 | ||
| 700 | ;;; Find one occasion of ABBREV. | 609 | ;;; Find one occasion of ABBREV. |
| 701 | ;;; DIRECTION > 0 means look that many times backwards. | 610 | ;;; DIRECTION > 0 means look that many times backwards. |
| @@ -755,20 +664,19 @@ Also check out `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." | |||
| 755 | (not (or (eq dabbrev--check-other-buffers t) | 664 | (not (or (eq dabbrev--check-other-buffers t) |
| 756 | (progn | 665 | (progn |
| 757 | (setq dabbrev--check-other-buffers | 666 | (setq dabbrev--check-other-buffers |
| 758 | (y-or-n-p "Check in other buffers this time? "))))) | 667 | (y-or-n-p "Scan other buffers also? "))))) |
| 759 | (let* (friend-buffer-list non-friend-buffer-list) | 668 | (let* (friend-buffer-list non-friend-buffer-list) |
| 760 | (setq dabbrev--friend-buffer-list | 669 | (setq dabbrev--friend-buffer-list |
| 761 | (funcall dabbrev-select-buffers-function)) | 670 | (funcall dabbrev-select-buffers-function)) |
| 762 | (when dabbrev-check-rest-of-buffers | 671 | (if dabbrev-check-rest-of-buffers |
| 763 | (setq non-friend-buffer-list | 672 | (setq non-friend-buffer-list |
| 764 | (nreverse | 673 | (nreverse |
| 765 | (loop for buffer | 674 | (dabbrev-filter-elements |
| 766 | in (buffer-list) | 675 | buffer (buffer-list) |
| 767 | if (not (memq buffer dabbrev--friend-buffer-list)) | 676 | (not (memq buffer dabbrev--friend-buffer-list)))) |
| 768 | collect buffer))) | 677 | dabbrev--friend-buffer-list |
| 769 | (setq dabbrev--friend-buffer-list | 678 | (append dabbrev--friend-buffer-list |
| 770 | (append dabbrev--friend-buffer-list | 679 | non-friend-buffer-list))))) |
| 771 | non-friend-buffer-list))))) | ||
| 772 | ;; Walk through the buffers | 680 | ;; Walk through the buffers |
| 773 | (while (and (not expansion) dabbrev--friend-buffer-list) | 681 | (while (and (not expansion) dabbrev--friend-buffer-list) |
| 774 | (setq dabbrev--last-buffer | 682 | (setq dabbrev--last-buffer |
| @@ -781,8 +689,6 @@ Also check out `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." | |||
| 781 | (setq expansion (dabbrev--try-find abbrev nil 1 ignore-case))) | 689 | (setq expansion (dabbrev--try-find abbrev nil 1 ignore-case))) |
| 782 | expansion))))) | 690 | expansion))))) |
| 783 | 691 | ||
| 784 | (eval-when-compile (require 'picture)) | ||
| 785 | |||
| 786 | (defun dabbrev--safe-replace-match (string &optional fixedcase literal) | 692 | (defun dabbrev--safe-replace-match (string &optional fixedcase literal) |
| 787 | (if (eq major-mode 'picture-mode) | 693 | (if (eq major-mode 'picture-mode) |
| 788 | (picture-replace-match string fixedcase literal) | 694 | (picture-replace-match string fixedcase literal) |
| @@ -818,7 +724,7 @@ Also check out `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." | |||
| 818 | ;;;---------------------------------------------------------------- | 724 | ;;;---------------------------------------------------------------- |
| 819 | ;;; Search function used by dabbrevs library. | 725 | ;;; Search function used by dabbrevs library. |
| 820 | 726 | ||
| 821 | ;;; ABBREV is string to find as prefix of word. Second arg, REVERSE, | 727 | ;;; ABBREV is string to find as prefix of word. Second arg, REVERSE, |
| 822 | ;;; is t for reverse search, nil for forward. Variable dabbrev-limit | 728 | ;;; is t for reverse search, nil for forward. Variable dabbrev-limit |
| 823 | ;;; controls the maximum search region size. Third argment IGNORE-CASE | 729 | ;;; controls the maximum search region size. Third argment IGNORE-CASE |
| 824 | ;;; non-nil means treat case as insignificant while looking for a match | 730 | ;;; non-nil means treat case as insignificant while looking for a match |
| @@ -867,11 +773,10 @@ Also check out `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." | |||
| 867 | (buffer-substring (match-beginning 1) (match-end 1))) | 773 | (buffer-substring (match-beginning 1) (match-end 1))) |
| 868 | (and ignore-case (setq found-string (downcase found-string))) | 774 | (and ignore-case (setq found-string (downcase found-string))) |
| 869 | ;; Throw away if found in table | 775 | ;; Throw away if found in table |
| 870 | (when (some | 776 | (if (dabbrev-filter-elements |
| 871 | (function | 777 | table-string dabbrev--last-table |
| 872 | (lambda (table-string) (string= found-string table-string))) | 778 | (string= found-string table-string)) |
| 873 | dabbrev--last-table) | 779 | (setq found-string nil)))) |
| 874 | (setq found-string nil)))) | ||
| 875 | (if reverse | 780 | (if reverse |
| 876 | (goto-char (match-beginning 0)) | 781 | (goto-char (match-beginning 0)) |
| 877 | (goto-char (match-end 0)))) | 782 | (goto-char (match-end 0)))) |
| @@ -887,8 +792,8 @@ Also check out `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." | |||
| 887 | (downcase result) | 792 | (downcase result) |
| 888 | result)))))))) | 793 | result)))))))) |
| 889 | 794 | ||
| 890 | (provide 'new-dabbrev) | ||
| 891 | (provide 'dabbrev) | 795 | (provide 'dabbrev) |
| 892 | ;; new-dabbrev.el ends here | 796 | |
| 797 | ;; dabbrev.el ends here | ||
| 893 | 798 | ||
| 894 | 799 | ||