Function: dabbrev--search

dabbrev--search is a byte-compiled function defined in dabbrev.el.gz.

Signature

(dabbrev--search ABBREV REVERSE IGNORE-CASE)

Documentation

Search for something that could be used to expand ABBREV.

Second arg, REVERSE, is t for reverse search, nil for forward. The variable dabbrev-limit controls the maximum search region size. Third argument IGNORE-CASE non-nil means treat case as insignificant while looking for a match and when comparing with previous matches. Also if that's non-nil and the match is found at the beginning of a sentence and is in lower case except for the initial then it is converted to all lower case for return.

Table of expansions already seen is examined in buffer dabbrev--last-table so that only distinct possibilities are found by dabbrev-re-expand.

Returns the expansion found, or nil if not found. Leaves point at the location of the start of the expansion.

Source Code

;; Defined in /usr/src/emacs/lisp/dabbrev.el.gz
;;;----------------------------------------------------------------
;;; Search function used by dabbrevs library.


(defun dabbrev--search (abbrev reverse ignore-case)
  "Search for something that could be used to expand ABBREV.

Second arg, REVERSE, is t for reverse search, nil for forward.
The variable `dabbrev-limit' controls the maximum search region size.
Third argument IGNORE-CASE non-nil means treat case as insignificant while
looking for a match and when comparing with previous matches.  Also if
that's non-nil and the match is found at the beginning of a sentence
and is in lower case except for the initial then it is converted to
all lower case for return.

Table of expansions already seen is examined in buffer
`dabbrev--last-table' so that only distinct possibilities are found
by dabbrev-re-expand.

Returns the expansion found, or nil if not found.
Leaves point at the location of the start of the expansion."
  (save-match-data
    (let ((pattern1 (concat (regexp-quote abbrev)
			    "\\(" dabbrev--abbrev-char-regexp "\\)"))
	  (pattern2 (concat (regexp-quote abbrev)
			   "\\(\\(" dabbrev--abbrev-char-regexp "\\)+\\)"))
	  found-string result)
      ;; Limited search.
      (save-restriction
	(and dabbrev-limit
	     (narrow-to-region
              dabbrev--last-expansion-location
              (+ (point) (if reverse (- dabbrev-limit) dabbrev-limit))))
	;;--------------------------------
	;; Look for a distinct expansion, using dabbrev--last-table.
	;;--------------------------------
	(while (and (not found-string)
		    (if reverse
			(re-search-backward pattern1 nil t)
		      (re-search-forward pattern1 nil t)))
	  (goto-char (match-beginning 0))
	  ;; In case we matched in the middle of a word,
	  ;; back up to start of word and verify we still match.
	  (dabbrev--goto-start-of-abbrev)

	  (if (not (looking-at pattern1))
	      nil
	    ;; We have a truly valid match.  Find the end.
	    (re-search-forward pattern2)
	    (setq found-string (match-string-no-properties 0))
	    (setq result found-string)
	    (and ignore-case (setq found-string (downcase found-string)))
	    ;; Ignore this match if it's already in the table.
	    (if (dabbrev-filter-elements
		 table-string dabbrev--last-table
		 (string= found-string table-string))
		(setq found-string nil)))
	  ;; Prepare to continue searching.
	  (goto-char (if reverse (match-beginning 0) (match-end 0))))
	;; If we found something, use it.
	(when found-string
	  ;; Put it into `dabbrev--last-table'
	  ;; and return it (either downcased, or as is).
	  (setq dabbrev--last-table
		(cons found-string dabbrev--last-table))
	  result)))))