mirror of
https://github.com/protesilaos/dotfiles.git
synced 2026-09-10 07:16:20 -04:00
emacs: refine the prot-emacs-abbrev macro; delete prot-emacs-abbrev-function
This commit is contained in:
parent
d64a552374
commit
ae461d028f
|
|
@ -397,39 +397,23 @@ DEFINITIONS is a sequence of string and command pairs."
|
|||
|
||||
(defmacro prot-emacs-abbrev (table &rest definitions)
|
||||
"Expand abbrev DEFINITIONS for the given TABLE.
|
||||
DEFINITIONS is a sequence of string pairs mapping the
|
||||
abbreviation to its expansion.
|
||||
|
||||
Also see `prot-emacs-abbrev-function'."
|
||||
DEFINITIONS is a sequence of (i) string pairs mapping the
|
||||
abbreviation to its expansion or (ii) a string and symbol pair
|
||||
making an abbreviation to a function."
|
||||
(declare (indent 1))
|
||||
(unless (zerop (% (length definitions) 2))
|
||||
(error "Uneven number of key+command pairs"))
|
||||
`(when-let (((abbrev-table-p ,table))
|
||||
(table ,table))
|
||||
,@(mapcar
|
||||
(lambda (pair)
|
||||
(when-let ((abbrev (car pair))
|
||||
(expansion (cadr pair)))
|
||||
`(define-abbrev table ,abbrev ,expansion)))
|
||||
(seq-split definitions 2))))
|
||||
|
||||
(defmacro prot-emacs-abbrev-function (table &rest definitions)
|
||||
"Expand abbrev DEFINITIONS for the given TABLE.
|
||||
DEFINITIONS is a sequence of string and function symbol pairs
|
||||
mapping the abbreviation to its expansion.
|
||||
|
||||
Also see `prot-emacs-abbrev'."
|
||||
(declare (indent 1))
|
||||
(unless (zerop (% (length definitions) 2))
|
||||
(error "Uneven number of key+command pairs"))
|
||||
`(when-let (((abbrev-table-p ,table))
|
||||
(table ,table))
|
||||
,@(mapcar
|
||||
(lambda (pair)
|
||||
(when-let ((abbrev (car pair))
|
||||
(expansion (cadr pair)))
|
||||
`(define-abbrev table ,abbrev "" ,expansion)))
|
||||
(seq-split definitions 2))))
|
||||
`(if (abbrev-table-p ,table)
|
||||
(progn
|
||||
,@(mapcar
|
||||
(lambda (pair)
|
||||
(when-let ((abbrev (car pair))
|
||||
(expansion (cadr pair)))
|
||||
(if (functionp expansion)
|
||||
`(define-abbrev table ,abbrev "" ,expansion)
|
||||
`(define-abbrev table ,abbrev ,expansion))))
|
||||
(seq-split definitions 2)))
|
||||
(error "%s is not an abbrev table" ,table)))
|
||||
|
||||
(defun prot-emacs-return-loaded-packages ()
|
||||
"Return a list of all loaded packages.
|
||||
|
|
|
|||
|
|
@ -215,7 +215,7 @@ Development continues on GitHub with GitLab as a mirror."))
|
|||
;; expand a static text, but calls a function which dynamically
|
||||
;; expands into the requisite form.
|
||||
(require 'prot-abbrev)
|
||||
(prot-emacs-abbrev-function global-abbrev-table
|
||||
(prot-emacs-abbrev global-abbrev-table
|
||||
"metime" #'prot-abbrev-current-time
|
||||
"medate" #'prot-abbrev-current-date
|
||||
"mejitsi" #'prot-abbrev-jitsi-link
|
||||
|
|
|
|||
|
|
@ -1377,39 +1377,23 @@ abbreviations. Though it is good to practice some programming.
|
|||
#+begin_src emacs-lisp :tangle "init.el"
|
||||
(defmacro prot-emacs-abbrev (table &rest definitions)
|
||||
"Expand abbrev DEFINITIONS for the given TABLE.
|
||||
DEFINITIONS is a sequence of string pairs mapping the
|
||||
abbreviation to its expansion.
|
||||
|
||||
Also see `prot-emacs-abbrev-function'."
|
||||
DEFINITIONS is a sequence of (i) string pairs mapping the
|
||||
abbreviation to its expansion or (ii) a string and symbol pair
|
||||
making an abbreviation to a function."
|
||||
(declare (indent 1))
|
||||
(unless (zerop (% (length definitions) 2))
|
||||
(error "Uneven number of key+command pairs"))
|
||||
`(when-let (((abbrev-table-p ,table))
|
||||
(table ,table))
|
||||
,@(mapcar
|
||||
(lambda (pair)
|
||||
(when-let ((abbrev (car pair))
|
||||
(expansion (cadr pair)))
|
||||
`(define-abbrev table ,abbrev ,expansion)))
|
||||
(seq-split definitions 2))))
|
||||
|
||||
(defmacro prot-emacs-abbrev-function (table &rest definitions)
|
||||
"Expand abbrev DEFINITIONS for the given TABLE.
|
||||
DEFINITIONS is a sequence of string and function symbol pairs
|
||||
mapping the abbreviation to its expansion.
|
||||
|
||||
Also see `prot-emacs-abbrev'."
|
||||
(declare (indent 1))
|
||||
(unless (zerop (% (length definitions) 2))
|
||||
(error "Uneven number of key+command pairs"))
|
||||
`(when-let (((abbrev-table-p ,table))
|
||||
(table ,table))
|
||||
,@(mapcar
|
||||
(lambda (pair)
|
||||
(when-let ((abbrev (car pair))
|
||||
(expansion (cadr pair)))
|
||||
`(define-abbrev table ,abbrev "" ,expansion)))
|
||||
(seq-split definitions 2))))
|
||||
`(if (abbrev-table-p ,table)
|
||||
(progn
|
||||
,@(mapcar
|
||||
(lambda (pair)
|
||||
(when-let ((abbrev (car pair))
|
||||
(expansion (cadr pair)))
|
||||
(if (functionp expansion)
|
||||
`(define-abbrev table ,abbrev "" ,expansion)
|
||||
`(define-abbrev table ,abbrev ,expansion))))
|
||||
(seq-split definitions 2)))
|
||||
(error "%s is not an abbrev table" ,table)))
|
||||
#+end_src
|
||||
|
||||
** The =init.el= to find which packages have been loaded
|
||||
|
|
@ -4261,7 +4245,7 @@ Development continues on GitHub with GitLab as a mirror."))
|
|||
;; expand a static text, but calls a function which dynamically
|
||||
;; expands into the requisite form.
|
||||
(require 'prot-abbrev)
|
||||
(prot-emacs-abbrev-function global-abbrev-table
|
||||
(prot-emacs-abbrev global-abbrev-table
|
||||
"metime" #'prot-abbrev-current-time
|
||||
"medate" #'prot-abbrev-current-date
|
||||
"mejitsi" #'prot-abbrev-jitsi-link
|
||||
|
|
|
|||
Loading…
Reference in a new issue