Elisp: Abbrev Table
What is Abbrev Table
Abbrev Table lets you set up abbrevations.
e.g.
type bg and it becomes background.
See
Emacs: Abbrev Mode
Define Abbrev Table
There are two ways to setup abbrevs.
- Use
define-abbrev-table. - Create a abbrev table by
make-abbrev-table, then usedefine-abbrevfor each abbrev.
define-abbrev-table-
(define-abbrev-table TABLENAME DEFINITIONS &optional DOCSTRING &rest PROPS)Create a abbrev table and define a list of abbrevs. With Abbrev Properties.
DEFINITIONS is a list. Each element is a list of the form
(abbrevStr expandStr ?hook ?props)Each element is passed to
define-abbrev.;; -*- coding: utf-8; lexical-binding: t; -*- ;; sample mode xx with abbrevs (setq xx-abbrev-table nil) (define-abbrev-table 'xx-abbrev-table '( ("fn" "function") ("function" "function name (x) { return x; }")) "Abbrev table for `xx'" :case-fixed t :system t ) (define-derived-mode xx prog-mode "xx" "A major mode for xx." :abbrev-table xx-abbrev-table (abbrev-mode 1) )
make-abbrev-table-
(make-abbrev-table &optional PROPS)Create an abbrev table. With Abbrev Properties.
(setq xx-abbrev-table (make-abbrev-table ))
Buffer Local Abbrev Table
Each buffer can have its own abbrev table.
- local-abbrev-table
-
Variable. Local abbrev table of current buffer.
;; set local abbrev table (setq local-abbrev-table xx-abbrev-table)
Adding Abbrev
define-abbrev-
(define-abbrev TABLE ABBREV EXPANSION &optional HOOK &rest PROPS)Adds one abbrev definition to a existing abbrev table. optionally with Abbrev Hook and Abbrev Properties.
(setq xx-abbrev-table (make-abbrev-table)) (define-abbrev xx-abbrev-table "fn" "function") (define-abbrev xx-abbrev-table "function" "function name (x) { return x; }" )