Function: abbrev--before-point
abbrev--before-point is a byte-compiled function defined in
abbrev.el.gz.
Signature
(abbrev--before-point)
Documentation
Try and find an abbrev before point. Return it if found, nil otherwise.
Source Code
;; Defined in /usr/src/emacs/lisp/abbrev.el.gz
(defun abbrev--before-point ()
"Try and find an abbrev before point. Return it if found, nil otherwise."
(unless (eq abbrev-start-location-buffer (current-buffer))
(setq abbrev-start-location nil))
(let ((tables (abbrev--active-tables))
(pos (point))
start end name res)
(if abbrev-start-location
(progn
(setq start abbrev-start-location)
(setq abbrev-start-location nil)
;; Remove the hyphen inserted by `abbrev-prefix-mark'.
(when (and (< start (point-max))
(eq (char-after start) ?-))
(delete-region start (1+ start))
(setq pos (1- pos)))
(skip-syntax-backward " ")
(setq end (point))
(when (> end start)
(setq name (buffer-substring start end))
(goto-char pos) ; Restore point.
(list (abbrev-symbol name tables) name start end)))
(while (and tables (not (car res)))
(let* ((table (pop tables))
(enable-fun (abbrev-table-get table :enable-function)))
(setq tables (append (abbrev-table-get table :parents) tables))
(setq res
(and (or (not enable-fun) (funcall enable-fun))
(let ((re (abbrev-table-get table :regexp)))
(if (null re)
;; We used to default `re' to "\\<\\(\\w+\\)\\W*"
;; but when words-include-escapes is set, that
;; is not right and fixing it is boring.
(let ((lim (point)))
(backward-word 1)
(setq start (point))
(forward-word 1)
(setq end (min (point) lim)))
(when (looking-back re (line-beginning-position))
(setq start (match-beginning 1))
(setq end (match-end 1)))))
(setq name (buffer-substring start end))
(let ((abbrev (abbrev--symbol name table)))
(when abbrev
(setq enable-fun (abbrev-get abbrev :enable-function))
(and (or (not enable-fun) (funcall enable-fun))
;; This will also look it up in parent tables.
;; This is not on purpose, but it seems harmless.
(list abbrev name start end))))))
;; Restore point.
(goto-char pos)))
res)))