summary refs log tree commit diff stats
path: root/lisp/+tempo.el
blob: 2c81e54bdeead9deb7e960a902fa7165ab1c3715 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
;;; +tempo.el --- easier tempo definition -*- lexical-binding: t -*-

(require 'tempo)
(declare-function derived-mode-abbrev-table-name "tempo")

;; TODO: I need to figure out where this function goes.
(defun delete2 (list &rest elems)
  "Delete each element of ELEMS, and the next item, from LIST."
  (let ((r nil))
    (while (consp list)
      (if (member (car list) elems)
          (setf list (cdr list))
        (setf r (cons (car list) r)))
      (setf list (cdr list)))
    (reverse r)))

(defmacro define-tempo (tag doc &rest elements)
  "Define a template and add its tag to MODE's abbrev-table.
TAG, DOC, and ELEMENTS are passed to `tempo-define-template', which see.
ABBREV, if given, is the abbrev string to use for template expansion
under MODE's abbrev-table.  If ABBREV isn't given, TAG will be used."
  (declare (indent 1))
  (let* ((template (gensym))
         (tag (cond ((stringp tag) tag)
                    ((symbolp tag) (symbol-name tag))
                    (t (user-error "TAG must be a string or symbol: %S" tag))))
         (mode (or (plist-get elements :mode) nil))
         (abbrev (or (plist-get elements :abbrev) tag))
         (taglist (or (plist-get elements :taglist) nil))
         (table (let ((tname (and mode (derived-mode-abbrev-table-name mode))))
                  (while (and tname (not (memq tname abbrev-table-name-list)))
                    (setq tname (and (get mode 'derived-mode-parent)
                                     (derived-mode-abbrev-table-name
                                      (get mode 'derived-mode-parent)))))
                  (or tname 'global-abbrev-table)))
         (elements (delete2 elements :mode :abbrev :taglist)))
    `(let ((,template (tempo-define-template ,tag
                                             ',elements
                                             ,(or abbrev tag)
                                             ,doc
                                             ,taglist)))
       (define-abbrev ,table ,tag "" ,template :system t)
       (put ,template 'no-self-insert t))))

(provide '+tempo)