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 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)
	      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 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))))
       ;; 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)))))