aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1995-05-15 23:16:08 +0000
committerRichard M. Stallman1995-05-15 23:16:08 +0000
commitdf6eb420bf10e4fd45a19a2a3d451eeafc98d20b (patch)
tree4d78220aaedca7028567a229592acc1ece58b1c2
parent09bc9531d918220dabff9d1f2ffddd0df81e08b6 (diff)
downloademacs-df6eb420bf10e4fd45a19a2a3d451eeafc98d20b.tar.gz
emacs-df6eb420bf10e4fd45a19a2a3d451eeafc98d20b.zip
(dabbrev-completion): Use mapcar, not mapc.
Call dabbrev--reset-global-variables as the first thing. (dabbrev-abbrev-char-regexp): Default value is nil again. (dabbrev--find-all-expansions): Don't use push. (dabbrev--search): Likewise. (dabbrev-check-other-buffers): Renamed from dabbrev-always-check-other-buffers. (dabbrev-check-all-buffers): Renamed frm dabbrev-check-rest-of-buffers. (dabbrev-expand): Now checks for marker. (dabbrev--try-find): Now does a protected call to `widen'. (dabbrev-always-check-other-buffers): Default now t. (dabbrev--capitalize): Function deleted. (dabbrev-completion): Use `capitalize'.
-rw-r--r--lisp/dabbrev.el154
1 files changed, 65 insertions, 89 deletions
diff --git a/lisp/dabbrev.el b/lisp/dabbrev.el
index 430824de8eb..2d14fbb07e7 100644
--- a/lisp/dabbrev.el
+++ b/lisp/dabbrev.el
@@ -4,7 +4,7 @@
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>
6;; Created: 16 Mars 1992 6;; Created: 16 Mars 1992
7;; Lindberg's last update version: 5.2 7;; Lindberg's last update version: 5.7
8;; Keywords: abbrev expand completion 8;; Keywords: abbrev expand completion
9 9
10;; This program is free software; you can redistribute it and/or modify 10;; This program is free software; you can redistribute it and/or modify
@@ -30,17 +30,6 @@
30;; To expand a word, just put the point right after the word and press 30;; To expand a word, just put the point right after the word and press
31;; M-/ (dabbrev-expand) or M-C-/ (dabbrev-completion). 31;; M-/ (dabbrev-expand) or M-C-/ (dabbrev-completion).
32;; 32;;
33;; There are powerful things in this package that aren't turned on by
34;; default. I recommend you to do the following.
35;;
36;; Put the following 2 lines in your .emacs file:
37;; (setq dabbrev-always-check-other-buffers t)
38;; (setq dabbrev-abbrev-char-regexp "\\sw\\|\\s_")
39;;
40;; Dabbrev will now search in all buffers with the same major mode for
41;; your expansions. It will also search for complete symbols, the old
42;; dabbrev package only looked half-heartedly for symbols.
43;;
44;; Check out the customizable variables below to learn about all the 33;; Check out the customizable variables below to learn about all the
45;; features of this package. 34;; features of this package.
46 35
@@ -85,7 +74,7 @@
85;; - Check the kill-ring when everything else fails. (Maybe something 74;; - Check the kill-ring when everything else fails. (Maybe something
86;; for hippie-expand?). [Bng] <boris@cs.rochester.edu> 75;; for hippie-expand?). [Bng] <boris@cs.rochester.edu>
87 76
88;;; Thanks goes to 77;;; These people gave suggestions:
89;; [hymie] Hyman Rosen <marks!hymie@jyacc.jyacc.com> 78;; [hymie] Hyman Rosen <marks!hymie@jyacc.jyacc.com>
90;; [burgett] Steve Burgett <burgett@bizet.eecs.berkeley.edu> 79;; [burgett] Steve Burgett <burgett@bizet.eecs.berkeley.edu>
91;; [jules] Julian Gosnell <jules@x.co.uk> 80;; [jules] Julian Gosnell <jules@x.co.uk>
@@ -149,20 +138,20 @@ variable to see if its value is t or nil.
149This variable has an effect only when the value of 138This variable has an effect only when the value of
150`dabbrev-case-fold-search' evaluates to t.") 139`dabbrev-case-fold-search' evaluates to t.")
151 140
152(defvar dabbrev-abbrev-char-regexp "\\sw\\|\\s_" 141(defvar dabbrev-abbrev-char-regexp nil
153 "*Regexp to recognize a character in an abbreviation or expansion. 142 "*Regexp to recognize a character in an abbreviation or expansion.
154This regexp will be surrounded with \\\\( ... \\\\) when actually used. 143This regexp will be surrounded with \\\\( ... \\\\) when actually used.
155 144
156Set this variable to \"\\\\sw\" if you want ordinary words or 145Set this variable to \"\\\\sw\" if you want ordinary words or
157\"\\\\sw\\\\|\\\\s_\" if you want symbols. 146\"\\\\sw\\\\|\\\\s_\" if you want symbols (including characters whose
147syntax is \"symbol\" as well as those whose syntax is \"word\".
158 148
159You can also set it to nil if you want old-style dabbrev searching 149The value nil has a special meaning: the abbreviation is from point to
160\(the abbreviation is from point to previous word-start, the 150previous word-start, but the search is for symbols.
161search is for symbols).
162 151
163For instance, if you are programming in Lisp, `yes-or-no-p' is a symbol, 152For instance, if you are programming in Lisp, `yes-or-no-p' is a symbol,
164while `yes', `or', `no' and `p' are considered words. If you set this 153while `yes', `or', `no' and `p' are considered words. If this
165variable to nil, then expanding `yes-or-no-' looks for a symbol 154variable is nil, then expanding `yes-or-no-' looks for a symbol
166starting with or containing `no-'. If you set this variable to 155starting with or containing `no-'. If you set this variable to
167\"\\\\sw\\\\|\\\\s_\", that expansion looks for a symbol starting with 156\"\\\\sw\\\\|\\\\s_\", that expansion looks for a symbol starting with
168`yes-or-no-'. Finally, if you set this variable to \"\\\\sw\", then 157`yes-or-no-'. Finally, if you set this variable to \"\\\\sw\", then
@@ -171,28 +160,33 @@ but expanding `yes-or-no' looks for a word starting with `no'.
171 160
172The recommended value is \"\\\\sw\\\\|\\\\s_\".") 161The recommended value is \"\\\\sw\\\\|\\\\s_\".")
173 162
174(defvar dabbrev-check-rest-of-buffers t 163(defvar dabbrev-check-all-buffers t
175 "*Non-nil means dabbrev package should search in all buffers. 164 "*Non-nil means dabbrev package should search *all* buffers.
176It searches the buffers pointed out by `dabbrev-select-buffers-function'
177first; afterward it looks in the rest of the buffers.")
178 165
166Dabbrev always searches the current buffer first. Then, if
167`dabbrev-check-other-buffers' says so, it searches the buffers
168designated by `dabbrev-select-buffers-function'.
179 169
180;; I recommend that you set this to t. 170Then, if `dabbrev-check-all-buffers' is non-nil, dabbrev searches
181(defvar dabbrev-always-check-other-buffers nil 171all the other buffers.")
172
173(defvar dabbrev-check-other-buffers t
182 "*Should \\[dabbrev-expand] look in other buffers?\ 174 "*Should \\[dabbrev-expand] look in other buffers?\
183nil = Don't look in other buffers.\n\
184t = Look in other buffers.\n\
185Value other than nil and t = ask the user if he want's to look in
186other buffers.
187 175
188The recommended value is t.") 176nil: Don't look in other buffers.
177t: Also look for expansions in the buffers pointed out by
178 `dabbrev-select-buffers-function'.
179Anything else: When we can't find any more expansions in
180the current buffer, then ask the user whether to look in other
181buffers too.
182
183The default value is t.")
189 184
190;; I guess setting this to a function that selects all C- or C++- 185;; I guess setting this to a function that selects all C- or C++-
191;; mode buffers would be a good choice for a debugging buffer, 186;; mode buffers would be a good choice for a debugging buffer,
192;; when debugging C- or C++-code. 187;; when debugging C- or C++-code.
193(defvar dabbrev-select-buffers-function 'dabbrev--select-buffers 188(defvar dabbrev-select-buffers-function 'dabbrev--select-buffers
194 "A function that selects buffers that should be searched by dabbrev. 189 "A function that selects buffers that should be searched by dabbrev.
195
196The function should take no arguments and return a list of buffers to 190The function should take no arguments and return a list of buffers to
197search for expansions. Have a look at `dabbrev--select-buffers' for 191search for expansions. Have a look at `dabbrev--select-buffers' for
198an example. 192an example.
@@ -200,8 +194,7 @@ an example.
200A mode setting this variable should make it buffer local.") 194A mode setting this variable should make it buffer local.")
201 195
202(defvar dabbrev-friend-buffer-function 'dabbrev--same-major-mode-p 196(defvar dabbrev-friend-buffer-function 'dabbrev--same-major-mode-p
203 "*A function to check if OTHER-BUFFER should be searched by dabbrev. 197 "*A function to decide whether dabbrev should search OTHER-BUFFER.
204
205The function should take one argument, OTHER-BUFFER, and return 198The function should take one argument, OTHER-BUFFER, and return
206non-nil if that buffer should be searched. Have a look at 199non-nil if that buffer should be searched. Have a look at
207`dabbrev--same-major-mode-p' for an example. 200`dabbrev--same-major-mode-p' for an example.
@@ -257,8 +250,8 @@ this list.")
257;; The buffer we last did a completion in. 250;; The buffer we last did a completion in.
258(defvar dabbrev--last-completion-buffer nil) 251(defvar dabbrev--last-completion-buffer nil)
259 252
260;; Same as dabbrev-always-check-other-buffers, but is set for every expand. 253;; Same as dabbrev-check-other-buffers, but is set for every expand.
261(defvar dabbrev--check-other-buffers dabbrev-always-check-other-buffers) 254(defvar dabbrev--check-other-buffers dabbrev-check-other-buffers)
262 255
263;; The regexp for recognizing a character in an abbreviation. 256;; The regexp for recognizing a character in an abbreviation.
264(defvar dabbrev--abbrev-char-regexp nil) 257(defvar dabbrev--abbrev-char-regexp nil)
@@ -316,8 +309,9 @@ With no prefix argument, it reuses an old completion list
316if there is a suitable one already." 309if there is a suitable one already."
317 310
318 (interactive "*P") 311 (interactive "*P")
319 (let* ((dabbrev-always-check-other-buffers (and arg t)) 312 (dabbrev--reset-global-variables)
320 (dabbrev-check-rest-of-buffers 313 (let* ((dabbrev-check-other-buffers (and arg t))
314 (dabbrev-check-all-buffers
321 (and arg (= (prefix-numeric-value arg) 16))) 315 (and arg (= (prefix-numeric-value arg) 16)))
322 (abbrev (dabbrev--abbrev-at-point)) 316 (abbrev (dabbrev--abbrev-at-point))
323 (ignore-case-p (and (eval dabbrev-case-fold-search) 317 (ignore-case-p (and (eval dabbrev-case-fold-search)
@@ -343,7 +337,6 @@ if there is a suitable one already."
343 ;;-------------------------------- 337 ;;--------------------------------
344 ;; New abbreviation to expand. 338 ;; New abbreviation to expand.
345 ;;-------------------------------- 339 ;;--------------------------------
346 (dabbrev--reset-global-variables)
347 (setq dabbrev--last-abbreviation abbrev) 340 (setq dabbrev--last-abbreviation abbrev)
348 ;; Find all expansion 341 ;; Find all expansion
349 (let ((completion-list 342 (let ((completion-list
@@ -357,22 +350,22 @@ if there is a suitable one already."
357 (cond 350 (cond
358 ((or (not ignore-case-p) 351 ((or (not ignore-case-p)
359 (not dabbrev-case-replace)) 352 (not dabbrev-case-replace))
360 (mapc (function (lambda (string) 353 (mapcar (function (lambda (string)
361 (intern string my-obarray))) 354 (intern string my-obarray)))
362 completion-list)) 355 completion-list))
363 ((string= abbrev (upcase abbrev)) 356 ((string= abbrev (upcase abbrev))
364 (mapc (function (lambda (string) 357 (mapcar (function (lambda (string)
365 (intern (upcase string) my-obarray))) 358 (intern (upcase string) my-obarray)))
366 completion-list)) 359 completion-list))
367 ((string= (substring abbrev 0 1) 360 ((string= (substring abbrev 0 1)
368 (upcase (substring abbrev 0 1))) 361 (upcase (substring abbrev 0 1)))
369 (mapc (function (lambda (string) 362 (mapcar (function (lambda (string)
370 (intern (dabbrev--capitalize string) my-obarray))) 363 (intern (capitalize string) my-obarray)))
371 completion-list)) 364 completion-list))
372 (t 365 (t
373 (mapc (function (lambda (string) 366 (mapcar (function (lambda (string)
374 (intern (downcase string) my-obarray))) 367 (intern (downcase string) my-obarray)))
375 completion-list))) 368 completion-list)))
376 (setq dabbrev--last-obarray my-obarray) 369 (setq dabbrev--last-obarray my-obarray)
377 (setq dabbrev--last-completion-buffer (current-buffer)) 370 (setq dabbrev--last-completion-buffer (current-buffer))
378 ;; Find the longest common string. 371 ;; Find the longest common string.
@@ -420,10 +413,6 @@ with the next possible expansion not yet tried.
420The variable `dabbrev-backward-only' may be used to limit the 413The variable `dabbrev-backward-only' may be used to limit the
421direction of search to backward if set non-nil. 414direction of search to backward if set non-nil.
422 415
423???
424To make it more powerful, make sure that
425`dabbrev-always-check-other-buffers' is set to t.
426
427See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." 416See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
428 (interactive "*P") 417 (interactive "*P")
429 (let (abbrev expansion old direction) 418 (let (abbrev expansion old direction)
@@ -433,7 +422,8 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
433 ;; (the abbrev, or the previously-made expansion) 422 ;; (the abbrev, or the previously-made expansion)
434 (save-excursion 423 (save-excursion
435 (if (and (null arg) 424 (if (and (null arg)
436 dabbrev--last-abbrev-location 425 (markerp dabbrev--last-abbrev-location)
426 (marker-position dabbrev--last-abbrev-location)
437 (or (eq last-command this-command) 427 (or (eq last-command this-command)
438 (and (window-minibuffer-p (selected-window)) 428 (and (window-minibuffer-p (selected-window))
439 (= dabbrev--last-abbrev-location 429 (= dabbrev--last-abbrev-location
@@ -488,22 +478,6 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
488;;;---------------------------------------------------------------- 478;;;----------------------------------------------------------------
489;;;---------------------------------------------------------------- 479;;;----------------------------------------------------------------
490 480
491(defun dabbrev--capitalize (string)
492 ;; Capitalize STRING (See capitalize-word)
493 (let ((new-string ""))
494 (save-match-data
495 (while (string-match "\\w+" string)
496 (let* ((mb (match-beginning 0))
497 (me (match-end 0))
498 (ms (substring string mb me)))
499 (setq new-string
500 (concat new-string
501 (substring string 0 mb)
502 (upcase (substring ms 0 1))
503 (downcase (substring ms 1))))
504 (setq string (substring string me)))))
505 new-string))
506
507;;; Checks if OTHER-BUFFER has the same major mode as current buffer. 481;;; Checks if OTHER-BUFFER has the same major mode as current buffer.
508(defun dabbrev--same-major-mode-p (other-buffer) 482(defun dabbrev--same-major-mode-p (other-buffer)
509 (eq major-mode 483 (eq major-mode
@@ -563,7 +537,7 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
563 dabbrev--last-buffer-found nil 537 dabbrev--last-buffer-found nil
564 dabbrev--abbrev-char-regexp (or dabbrev-abbrev-char-regexp 538 dabbrev--abbrev-char-regexp (or dabbrev-abbrev-char-regexp
565 "\\sw\\|\\s_") 539 "\\sw\\|\\s_")
566 dabbrev--check-other-buffers dabbrev-always-check-other-buffers)) 540 dabbrev--check-other-buffers dabbrev-check-other-buffers))
567 541
568;;; Find all buffers that are considered "friends" according to the 542;;; Find all buffers that are considered "friends" according to the
569;;; function pointed out by dabbrev-friend-buffer-function. 543;;; function pointed out by dabbrev-friend-buffer-function.
@@ -582,19 +556,21 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
582;;; but looking in reverse instead if REVERSE is non-nil. 556;;; but looking in reverse instead if REVERSE is non-nil.
583(defun dabbrev--try-find (abbrev reverse n ignore-case) 557(defun dabbrev--try-find (abbrev reverse n ignore-case)
584 (save-excursion 558 (save-excursion
585 (let ((expansion nil)) 559 (save-restriction
586 (and dabbrev--last-expansion-location 560 (widen)
587 (goto-char dabbrev--last-expansion-location)) 561 (let ((expansion nil))
588 (let ((case-fold-search ignore-case) 562 (and dabbrev--last-expansion-location
589 (count n)) 563 (goto-char dabbrev--last-expansion-location))
590 (while (and (> count 0) 564 (let ((case-fold-search ignore-case)
591 (setq expansion (dabbrev--search abbrev 565 (count n))
592 reverse 566 (while (and (> count 0)
593 ignore-case))) 567 (setq expansion (dabbrev--search abbrev
594 (setq count (1- count)))) 568 reverse
595 (and expansion 569 ignore-case)))
596 (setq dabbrev--last-expansion-location (point))) 570 (setq count (1- count))))
597 expansion))) 571 (and expansion
572 (setq dabbrev--last-expansion-location (point)))
573 expansion))))
598 574
599;;; Find all expansions of ABBREV 575;;; Find all expansions of ABBREV
600(defun dabbrev--find-all-expansions (abbrev ignore-case) 576(defun dabbrev--find-all-expansions (abbrev ignore-case)
@@ -603,7 +579,7 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
603 (save-excursion 579 (save-excursion
604 (goto-char (point-min)) 580 (goto-char (point-min))
605 (while (setq expansion (dabbrev--find-expansion abbrev -1 ignore-case)) 581 (while (setq expansion (dabbrev--find-expansion abbrev -1 ignore-case))
606 (push expansion all-expansions))) 582 (setq all-expansions (cons expansion all-expansions))))
607 all-expansions)) 583 all-expansions))
608 584
609(defun dabbrev--scanning-message () 585(defun dabbrev--scanning-message ()
@@ -671,7 +647,7 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
671 (let* (friend-buffer-list non-friend-buffer-list) 647 (let* (friend-buffer-list non-friend-buffer-list)
672 (setq dabbrev--friend-buffer-list 648 (setq dabbrev--friend-buffer-list
673 (funcall dabbrev-select-buffers-function)) 649 (funcall dabbrev-select-buffers-function))
674 (if dabbrev-check-rest-of-buffers 650 (if dabbrev-check-all-buffers
675 (setq non-friend-buffer-list 651 (setq non-friend-buffer-list
676 (nreverse 652 (nreverse
677 (dabbrev-filter-elements 653 (dabbrev-filter-elements
@@ -789,7 +765,7 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
789 ;; Put in `dabbrev--last-table' and decide if we should return 765 ;; Put in `dabbrev--last-table' and decide if we should return
790 ;; result or (downcase result) 766 ;; result or (downcase result)
791 ;;-------------------------------- 767 ;;--------------------------------
792 (push found-string dabbrev--last-table) 768 (setq dabbrev--last-table (cons found-string dabbrev--last-table))
793 (let ((result (buffer-substring (match-beginning 0) (match-end 0)))) 769 (let ((result (buffer-substring (match-beginning 0) (match-end 0))))
794 (if (and ignore-case (eval dabbrev-case-replace)) 770 (if (and ignore-case (eval dabbrev-case-replace))
795 (downcase result) 771 (downcase result)