Function: dabbrev--find-expansion
dabbrev--find-expansion is a byte-compiled function defined in
dabbrev.el.gz.
Signature
(dabbrev--find-expansion ABBREV DIRECTION IGNORE-CASE)
Documentation
Find one occurrence of ABBREV, and return the expansion.
DIRECTION > 0 means look that many times backwards.
DIRECTION < 0 means look that many times forward.
DIRECTION = 0 means try both backward and forward.
IGNORE-CASE non-nil means ignore case when searching.
This sets dabbrev--last-direction to 1 or -1 according
to the direction in which the occurrence was actually found.
It sets dabbrev--last-expansion-location to the location
of the start of the occurrence.
Source Code
;; Defined in /usr/src/emacs/lisp/dabbrev.el.gz
(defun dabbrev--find-expansion (abbrev direction ignore-case)
"Find one occurrence of ABBREV, and return the expansion.
DIRECTION > 0 means look that many times backwards.
DIRECTION < 0 means look that many times forward.
DIRECTION = 0 means try both backward and forward.
IGNORE-CASE non-nil means ignore case when searching.
This sets `dabbrev--last-direction' to 1 or -1 according
to the direction in which the occurrence was actually found.
It sets `dabbrev--last-expansion-location' to the location
of the start of the occurrence."
(save-excursion
;; If we were scanning something other than the current buffer,
;; continue scanning there.
(when (buffer-live-p dabbrev--last-buffer)
(set-buffer dabbrev--last-buffer))
(or
;; ------------------------------------------
;; Look backward in current buffer.
;; ------------------------------------------
(and (not dabbrev-search-these-buffers-only)
(>= direction 0)
(setq dabbrev--last-direction (min 1 direction))
(dabbrev--try-find abbrev t
(max 1 direction)
ignore-case))
;; ------------------------------------------
;; Look forward in current buffer
;; or whatever buffer we were last scanning.
;; ------------------------------------------
(and (or (not dabbrev-search-these-buffers-only)
(buffer-live-p dabbrev--last-buffer))
(<= direction 0)
(setq dabbrev--last-direction -1)
(dabbrev--try-find abbrev nil
(max 1 (- direction))
ignore-case))
;; ------------------------------------------
;; Look in other buffers.
;; Always start at (point-min) and look forward.
;; ------------------------------------------
(progn
(setq dabbrev--last-direction -1)
(unless (buffer-live-p dabbrev--last-buffer)
;; If we have just now begun to search other buffers,
;; determine which other buffers we should check.
;; Put that list in dabbrev--friend-buffer-list.
(unless dabbrev--friend-buffer-list
(setq dabbrev--friend-buffer-list
(dabbrev--make-friend-buffer-list))
(setq dabbrev--progress-reporter
(make-progress-reporter
"Scanning for dabbrevs..."
(- (length dabbrev--friend-buffer-list)) 0 0 1 1.5))))
(let ((file-name (buffer-file-name))
file-name-buffer)
(unwind-protect
(progn
;; Include the file name components into the abbrev
;; list (because if you have a file name "foobar", it's
;; somewhat likely that you'll be talking about foobar
;; stuff in the file itself).
(when file-name
(setq file-name-buffer (generate-new-buffer " *abbrev-file*"))
(with-current-buffer file-name-buffer
(dolist (part (file-name-split file-name))
(insert part "\n")))
(setq dabbrev--friend-buffer-list
(append dabbrev--friend-buffer-list
(list file-name-buffer))))
;; Walk through the buffers till we find a match.
(let (expansion)
(while (and (not expansion) dabbrev--friend-buffer-list)
(setq dabbrev--last-buffer
(pop dabbrev--friend-buffer-list))
(set-buffer dabbrev--last-buffer)
(progress-reporter-update
dabbrev--progress-reporter
(- (length dabbrev--friend-buffer-list)))
(setq dabbrev--last-expansion-location (point-min))
(setq expansion (dabbrev--try-find
abbrev nil 1 ignore-case)))
(progress-reporter-done dabbrev--progress-reporter)
expansion))
(when (buffer-live-p file-name-buffer)
(kill-buffer file-name-buffer))
(setq dabbrev--friend-buffer-list
(seq-filter #'buffer-live-p
dabbrev--friend-buffer-list))))))))