Elisp: Abbrev Enable Function

By Xah Lee. Date: . Last updated: .

Abbrev Enable Function

when an abbrev expansion is triggered, the :enable-function property for the abbrev table is checked to decide whether to expand.

The value should be a function that returns true or false. If it returns true, do expand, else do nothing.

;; example of defining abbrev property :enable-function

(defun xx-abbrev-enable ()
  "Return t if not in string or comment. Else nil."
  (let ((xsyntax-state (syntax-ppss)))
    (not (or (nth 3 xsyntax-state) (nth 4 xsyntax-state)))))

;; add to a abbrev table
(abbrev-table-put xx-abbrev-table :enable-function 'xx-abbrev-enable)

Elisp, creating abbrev