1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-09 15:50:21 +00:00

(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'.
This commit is contained in:
Richard M. Stallman 1995-05-15 23:16:08 +00:00
parent 09bc9531d9
commit df6eb420bf

View File

@ -4,7 +4,7 @@
;; Author: Don Morrison ;; Author: Don Morrison
;; Maintainer: Lars Lindberg <Lars.Lindberg@sypro.cap.se> ;; Maintainer: Lars Lindberg <Lars.Lindberg@sypro.cap.se>
;; Created: 16 Mars 1992 ;; Created: 16 Mars 1992
;; Lindberg's last update version: 5.2 ;; Lindberg's last update version: 5.7
;; Keywords: abbrev expand completion ;; Keywords: abbrev expand completion
;; This program is free software; you can redistribute it and/or modify ;; This program is free software; you can redistribute it and/or modify
@ -30,17 +30,6 @@
;; To expand a word, just put the point right after the word and press ;; To expand a word, just put the point right after the word and press
;; M-/ (dabbrev-expand) or M-C-/ (dabbrev-completion). ;; M-/ (dabbrev-expand) or M-C-/ (dabbrev-completion).
;; ;;
;; There are powerful things in this package that aren't turned on by
;; default. I recommend you to do the following.
;;
;; Put the following 2 lines in your .emacs file:
;; (setq dabbrev-always-check-other-buffers t)
;; (setq dabbrev-abbrev-char-regexp "\\sw\\|\\s_")
;;
;; Dabbrev will now search in all buffers with the same major mode for
;; your expansions. It will also search for complete symbols, the old
;; dabbrev package only looked half-heartedly for symbols.
;;
;; Check out the customizable variables below to learn about all the ;; Check out the customizable variables below to learn about all the
;; features of this package. ;; features of this package.
@ -85,7 +74,7 @@
;; - Check the kill-ring when everything else fails. (Maybe something ;; - Check the kill-ring when everything else fails. (Maybe something
;; for hippie-expand?). [Bng] <boris@cs.rochester.edu> ;; for hippie-expand?). [Bng] <boris@cs.rochester.edu>
;;; Thanks goes to ;;; These people gave suggestions:
;; [hymie] Hyman Rosen <marks!hymie@jyacc.jyacc.com> ;; [hymie] Hyman Rosen <marks!hymie@jyacc.jyacc.com>
;; [burgett] Steve Burgett <burgett@bizet.eecs.berkeley.edu> ;; [burgett] Steve Burgett <burgett@bizet.eecs.berkeley.edu>
;; [jules] Julian Gosnell <jules@x.co.uk> ;; [jules] Julian Gosnell <jules@x.co.uk>
@ -149,20 +138,20 @@ variable to see if its value is t or nil.
This variable has an effect only when the value of This variable has an effect only when the value of
`dabbrev-case-fold-search' evaluates to t.") `dabbrev-case-fold-search' evaluates to t.")
(defvar dabbrev-abbrev-char-regexp "\\sw\\|\\s_" (defvar dabbrev-abbrev-char-regexp nil
"*Regexp to recognize a character in an abbreviation or expansion. "*Regexp to recognize a character in an abbreviation or expansion.
This regexp will be surrounded with \\\\( ... \\\\) when actually used. This regexp will be surrounded with \\\\( ... \\\\) when actually used.
Set this variable to \"\\\\sw\" if you want ordinary words or Set this variable to \"\\\\sw\" if you want ordinary words or
\"\\\\sw\\\\|\\\\s_\" if you want symbols. \"\\\\sw\\\\|\\\\s_\" if you want symbols (including characters whose
syntax is \"symbol\" as well as those whose syntax is \"word\".
You can also set it to nil if you want old-style dabbrev searching The value nil has a special meaning: the abbreviation is from point to
\(the abbreviation is from point to previous word-start, the previous word-start, but the search is for symbols.
search is for symbols).
For instance, if you are programming in Lisp, `yes-or-no-p' is a symbol, For instance, if you are programming in Lisp, `yes-or-no-p' is a symbol,
while `yes', `or', `no' and `p' are considered words. If you set this while `yes', `or', `no' and `p' are considered words. If this
variable to nil, then expanding `yes-or-no-' looks for a symbol variable is nil, then expanding `yes-or-no-' looks for a symbol
starting with or containing `no-'. If you set this variable to starting with or containing `no-'. If you set this variable to
\"\\\\sw\\\\|\\\\s_\", that expansion looks for a symbol starting with \"\\\\sw\\\\|\\\\s_\", that expansion looks for a symbol starting with
`yes-or-no-'. Finally, if you set this variable to \"\\\\sw\", then `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'.
The recommended value is \"\\\\sw\\\\|\\\\s_\".") The recommended value is \"\\\\sw\\\\|\\\\s_\".")
(defvar dabbrev-check-rest-of-buffers t (defvar dabbrev-check-all-buffers t
"*Non-nil means dabbrev package should search in all buffers. "*Non-nil means dabbrev package should search *all* buffers.
It searches the buffers pointed out by `dabbrev-select-buffers-function'
first; afterward it looks in the rest of the buffers.")
Dabbrev always searches the current buffer first. Then, if
`dabbrev-check-other-buffers' says so, it searches the buffers
designated by `dabbrev-select-buffers-function'.
;; I recommend that you set this to t. Then, if `dabbrev-check-all-buffers' is non-nil, dabbrev searches
(defvar dabbrev-always-check-other-buffers nil all the other buffers.")
(defvar dabbrev-check-other-buffers t
"*Should \\[dabbrev-expand] look in other buffers?\ "*Should \\[dabbrev-expand] look in other buffers?\
nil = Don't look in other buffers.\n\
t = Look in other buffers.\n\
Value other than nil and t = ask the user if he want's to look in
other buffers.
The recommended value is t.") nil: Don't look in other buffers.
t: Also look for expansions in the buffers pointed out by
`dabbrev-select-buffers-function'.
Anything else: When we can't find any more expansions in
the current buffer, then ask the user whether to look in other
buffers too.
The default value is t.")
;; I guess setting this to a function that selects all C- or C++- ;; I guess setting this to a function that selects all C- or C++-
;; mode buffers would be a good choice for a debugging buffer, ;; mode buffers would be a good choice for a debugging buffer,
;; when debugging C- or C++-code. ;; when debugging C- or C++-code.
(defvar dabbrev-select-buffers-function 'dabbrev--select-buffers (defvar dabbrev-select-buffers-function 'dabbrev--select-buffers
"A function that selects buffers that should be searched by dabbrev. "A function that selects buffers that should be searched by dabbrev.
The function should take no arguments and return a list of buffers to The function should take no arguments and return a list of buffers to
search for expansions. Have a look at `dabbrev--select-buffers' for search for expansions. Have a look at `dabbrev--select-buffers' for
an example. an example.
@ -200,8 +194,7 @@ an example.
A mode setting this variable should make it buffer local.") A mode setting this variable should make it buffer local.")
(defvar dabbrev-friend-buffer-function 'dabbrev--same-major-mode-p (defvar dabbrev-friend-buffer-function 'dabbrev--same-major-mode-p
"*A function to check if OTHER-BUFFER should be searched by dabbrev. "*A function to decide whether dabbrev should search OTHER-BUFFER.
The function should take one argument, OTHER-BUFFER, and return The function should take one argument, OTHER-BUFFER, and return
non-nil if that buffer should be searched. Have a look at non-nil if that buffer should be searched. Have a look at
`dabbrev--same-major-mode-p' for an example. `dabbrev--same-major-mode-p' for an example.
@ -257,8 +250,8 @@ this list.")
;; The buffer we last did a completion in. ;; The buffer we last did a completion in.
(defvar dabbrev--last-completion-buffer nil) (defvar dabbrev--last-completion-buffer nil)
;; Same as dabbrev-always-check-other-buffers, but is set for every expand. ;; Same as dabbrev-check-other-buffers, but is set for every expand.
(defvar dabbrev--check-other-buffers dabbrev-always-check-other-buffers) (defvar dabbrev--check-other-buffers dabbrev-check-other-buffers)
;; The regexp for recognizing a character in an abbreviation. ;; The regexp for recognizing a character in an abbreviation.
(defvar dabbrev--abbrev-char-regexp nil) (defvar dabbrev--abbrev-char-regexp nil)
@ -316,8 +309,9 @@ With no prefix argument, it reuses an old completion list
if there is a suitable one already." if there is a suitable one already."
(interactive "*P") (interactive "*P")
(let* ((dabbrev-always-check-other-buffers (and arg t)) (dabbrev--reset-global-variables)
(dabbrev-check-rest-of-buffers (let* ((dabbrev-check-other-buffers (and arg t))
(dabbrev-check-all-buffers
(and arg (= (prefix-numeric-value arg) 16))) (and arg (= (prefix-numeric-value arg) 16)))
(abbrev (dabbrev--abbrev-at-point)) (abbrev (dabbrev--abbrev-at-point))
(ignore-case-p (and (eval dabbrev-case-fold-search) (ignore-case-p (and (eval dabbrev-case-fold-search)
@ -343,7 +337,6 @@ if there is a suitable one already."
;;-------------------------------- ;;--------------------------------
;; New abbreviation to expand. ;; New abbreviation to expand.
;;-------------------------------- ;;--------------------------------
(dabbrev--reset-global-variables)
(setq dabbrev--last-abbreviation abbrev) (setq dabbrev--last-abbreviation abbrev)
;; Find all expansion ;; Find all expansion
(let ((completion-list (let ((completion-list
@ -357,22 +350,22 @@ if there is a suitable one already."
(cond (cond
((or (not ignore-case-p) ((or (not ignore-case-p)
(not dabbrev-case-replace)) (not dabbrev-case-replace))
(mapc (function (lambda (string) (mapcar (function (lambda (string)
(intern string my-obarray))) (intern string my-obarray)))
completion-list)) completion-list))
((string= abbrev (upcase abbrev)) ((string= abbrev (upcase abbrev))
(mapc (function (lambda (string) (mapcar (function (lambda (string)
(intern (upcase string) my-obarray))) (intern (upcase string) my-obarray)))
completion-list)) completion-list))
((string= (substring abbrev 0 1) ((string= (substring abbrev 0 1)
(upcase (substring abbrev 0 1))) (upcase (substring abbrev 0 1)))
(mapc (function (lambda (string) (mapcar (function (lambda (string)
(intern (dabbrev--capitalize string) my-obarray))) (intern (capitalize string) my-obarray)))
completion-list)) completion-list))
(t (t
(mapc (function (lambda (string) (mapcar (function (lambda (string)
(intern (downcase string) my-obarray))) (intern (downcase string) my-obarray)))
completion-list))) completion-list)))
(setq dabbrev--last-obarray my-obarray) (setq dabbrev--last-obarray my-obarray)
(setq dabbrev--last-completion-buffer (current-buffer)) (setq dabbrev--last-completion-buffer (current-buffer))
;; Find the longest common string. ;; Find the longest common string.
@ -420,10 +413,6 @@ with the next possible expansion not yet tried.
The variable `dabbrev-backward-only' may be used to limit the The variable `dabbrev-backward-only' may be used to limit the
direction of search to backward if set non-nil. direction of search to backward if set non-nil.
???
To make it more powerful, make sure that
`dabbrev-always-check-other-buffers' is set to t.
See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
(interactive "*P") (interactive "*P")
(let (abbrev expansion old direction) (let (abbrev expansion old direction)
@ -433,7 +422,8 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
;; (the abbrev, or the previously-made expansion) ;; (the abbrev, or the previously-made expansion)
(save-excursion (save-excursion
(if (and (null arg) (if (and (null arg)
dabbrev--last-abbrev-location (markerp dabbrev--last-abbrev-location)
(marker-position dabbrev--last-abbrev-location)
(or (eq last-command this-command) (or (eq last-command this-command)
(and (window-minibuffer-p (selected-window)) (and (window-minibuffer-p (selected-window))
(= dabbrev--last-abbrev-location (= dabbrev--last-abbrev-location
@ -488,22 +478,6 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
;;;---------------------------------------------------------------- ;;;----------------------------------------------------------------
;;;---------------------------------------------------------------- ;;;----------------------------------------------------------------
(defun dabbrev--capitalize (string)
;; Capitalize STRING (See capitalize-word)
(let ((new-string ""))
(save-match-data
(while (string-match "\\w+" string)
(let* ((mb (match-beginning 0))
(me (match-end 0))
(ms (substring string mb me)))
(setq new-string
(concat new-string
(substring string 0 mb)
(upcase (substring ms 0 1))
(downcase (substring ms 1))))
(setq string (substring string me)))))
new-string))
;;; Checks if OTHER-BUFFER has the same major mode as current buffer. ;;; Checks if OTHER-BUFFER has the same major mode as current buffer.
(defun dabbrev--same-major-mode-p (other-buffer) (defun dabbrev--same-major-mode-p (other-buffer)
(eq major-mode (eq major-mode
@ -563,7 +537,7 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
dabbrev--last-buffer-found nil dabbrev--last-buffer-found nil
dabbrev--abbrev-char-regexp (or dabbrev-abbrev-char-regexp dabbrev--abbrev-char-regexp (or dabbrev-abbrev-char-regexp
"\\sw\\|\\s_") "\\sw\\|\\s_")
dabbrev--check-other-buffers dabbrev-always-check-other-buffers)) dabbrev--check-other-buffers dabbrev-check-other-buffers))
;;; Find all buffers that are considered "friends" according to the ;;; Find all buffers that are considered "friends" according to the
;;; function pointed out by dabbrev-friend-buffer-function. ;;; function pointed out by dabbrev-friend-buffer-function.
@ -582,19 +556,21 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
;;; but looking in reverse instead if REVERSE is non-nil. ;;; but looking in reverse instead if REVERSE is non-nil.
(defun dabbrev--try-find (abbrev reverse n ignore-case) (defun dabbrev--try-find (abbrev reverse n ignore-case)
(save-excursion (save-excursion
(let ((expansion nil)) (save-restriction
(and dabbrev--last-expansion-location (widen)
(goto-char dabbrev--last-expansion-location)) (let ((expansion nil))
(let ((case-fold-search ignore-case) (and dabbrev--last-expansion-location
(count n)) (goto-char dabbrev--last-expansion-location))
(while (and (> count 0) (let ((case-fold-search ignore-case)
(setq expansion (dabbrev--search abbrev (count n))
reverse (while (and (> count 0)
ignore-case))) (setq expansion (dabbrev--search abbrev
(setq count (1- count)))) reverse
(and expansion ignore-case)))
(setq dabbrev--last-expansion-location (point))) (setq count (1- count))))
expansion))) (and expansion
(setq dabbrev--last-expansion-location (point)))
expansion))))
;;; Find all expansions of ABBREV ;;; Find all expansions of ABBREV
(defun dabbrev--find-all-expansions (abbrev ignore-case) (defun dabbrev--find-all-expansions (abbrev ignore-case)
@ -603,7 +579,7 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
(save-excursion (save-excursion
(goto-char (point-min)) (goto-char (point-min))
(while (setq expansion (dabbrev--find-expansion abbrev -1 ignore-case)) (while (setq expansion (dabbrev--find-expansion abbrev -1 ignore-case))
(push expansion all-expansions))) (setq all-expansions (cons expansion all-expansions))))
all-expansions)) all-expansions))
(defun dabbrev--scanning-message () (defun dabbrev--scanning-message ()
@ -671,7 +647,7 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
(let* (friend-buffer-list non-friend-buffer-list) (let* (friend-buffer-list non-friend-buffer-list)
(setq dabbrev--friend-buffer-list (setq dabbrev--friend-buffer-list
(funcall dabbrev-select-buffers-function)) (funcall dabbrev-select-buffers-function))
(if dabbrev-check-rest-of-buffers (if dabbrev-check-all-buffers
(setq non-friend-buffer-list (setq non-friend-buffer-list
(nreverse (nreverse
(dabbrev-filter-elements (dabbrev-filter-elements
@ -789,7 +765,7 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
;; Put in `dabbrev--last-table' and decide if we should return ;; Put in `dabbrev--last-table' and decide if we should return
;; result or (downcase result) ;; result or (downcase result)
;;-------------------------------- ;;--------------------------------
(push found-string dabbrev--last-table) (setq dabbrev--last-table (cons found-string dabbrev--last-table))
(let ((result (buffer-substring (match-beginning 0) (match-end 0)))) (let ((result (buffer-substring (match-beginning 0) (match-end 0))))
(if (and ignore-case (eval dabbrev-case-replace)) (if (and ignore-case (eval dabbrev-case-replace))
(downcase result) (downcase result)