Add `tempo' tags to abbreviation tables
This commit is contained in:
parent
1876d151d6
commit
bc38c4bbe1
89
README.org
89
README.org
@ -4336,26 +4336,48 @@ adaptation to =lexical-binding=:
|
|||||||
1. [[https://www.emacswiki.org/emacs/TempoMode][Tempo (Emacs Wiki)]]
|
1. [[https://www.emacswiki.org/emacs/TempoMode][Tempo (Emacs Wiki)]]
|
||||||
2. [[https://www.lysator.liu.se/~davidk/elisp/][David Kågedal’s elisp]]
|
2. [[https://www.lysator.liu.se/~davidk/elisp/][David Kågedal’s elisp]]
|
||||||
3. [[https://github.com/yilkalargaw/emacs-native-snippets][Emacs's Native Snippets]], [[https://www.reddit.com/r/emacs/comments/wdbk34/emacss_native_templating_and_snippet_fuctionality/][Emacs's native templating and snippet functionality]]
|
3. [[https://github.com/yilkalargaw/emacs-native-snippets][Emacs's Native Snippets]], [[https://www.reddit.com/r/emacs/comments/wdbk34/emacss_native_templating_and_snippet_fuctionality/][Emacs's native templating and snippet functionality]]
|
||||||
Listing [[lst:configure-completing-read-tempo]] shows how to combine =tempo= and
|
Listing [[lst:configure-tempo-abbrev-mode]] provide the tools to add =tempo-tags= to
|
||||||
=completing-read= for the builtin =tempo= package that is part of Emacs-28.1 and
|
abbreviation tables. Listing [[lst:configure-tempo-latex-completing-read]] shows how
|
||||||
later.
|
to combine =tempo=, =latex= and =completing-read= for the builtin =tempo=
|
||||||
|
package that is part of Emacs-28.1 and later.
|
||||||
|
|
||||||
#+caption[Configure =tempo= with =completing-read=]:
|
#+caption[Configure =tempo with =abbrev-mode=]:
|
||||||
#+caption: Configure =tempo= with =completing-read=.
|
#+caption: Configure =tempo= with =abbrev-mode=.
|
||||||
#+name: lst:configure-completing-read-tempo
|
#+name: lst:configure-tempo-abbrev-mode
|
||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
(with-eval-after-load 'tempo
|
(with-eval-after-load 'tempo
|
||||||
(custom-set-variables
|
(custom-set-variables
|
||||||
'(tempo-interactive t))
|
'(tempo-interactive t))
|
||||||
|
|
||||||
(defun setup-tempo-map ()
|
(defun abbrev-tempo-expand-if-complete ()
|
||||||
"Initialize a local map for `tempo' key bindings."
|
"Hook function for `define-abbrev' with `no-self-insert' property `t'."
|
||||||
|
(tempo-expand-if-complete))
|
||||||
|
|
||||||
|
(put 'abbrev-tempo-expand-if-complete 'no-self-insert t)
|
||||||
|
|
||||||
|
(defun add-tempo-tags-to-abbrev-table (tempo-tags abbrev-table)
|
||||||
|
"Add the tags in TEMPO-TAGS to ABBREV-TABLE."
|
||||||
|
(dolist (tag tempo-tags)
|
||||||
|
(unless (abbrev-symbol (car tag) abbrev-table)
|
||||||
|
(define-abbrev abbrev-table
|
||||||
|
(car tag) 1 'abbrev-tempo-expand-if-complete))))
|
||||||
|
|
||||||
|
(defun setup-local-tempo-key-bindings ()
|
||||||
|
"Initialize local `tempo' key bindings."
|
||||||
(define-prefix-command 'tempo-map)
|
(define-prefix-command 'tempo-map)
|
||||||
(local-set-key (kbd "C-c t") 'tempo-map)
|
(local-set-key (kbd "C-c t") 'tempo-map)
|
||||||
;; define keys for complete-tag and movement through stops
|
|
||||||
(define-key tempo-map (kbd "c") #'tempo-complete-tag)
|
(define-key tempo-map (kbd "c") #'tempo-complete-tag)
|
||||||
(define-key tempo-map (kbd "f") #'tempo-forward-mark)
|
(define-key tempo-map (kbd "f") #'tempo-forward-mark)
|
||||||
(define-key tempo-map (kbd "b") #'tempo-backward-mark))
|
(define-key tempo-map (kbd "b") #'tempo-backward-mark)))
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+caption[Configure =tempo= for =latex= with =completing-read=]:
|
||||||
|
#+caption: Configure =tempo= for =latex= with =completing-read=.
|
||||||
|
#+name: lst:configure-tempo-latex-completing-read
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(with-eval-after-load 'latex
|
||||||
|
(unless (featurep 'tempo)
|
||||||
|
(require 'tempo))
|
||||||
|
|
||||||
(defun tempo-latex-environment-handler (element)
|
(defun tempo-latex-environment-handler (element)
|
||||||
(when-let ((ok (eq element 'latex-environment))
|
(when-let ((ok (eq element 'latex-environment))
|
||||||
@ -4365,14 +4387,49 @@ later.
|
|||||||
#'always 'require-match)))
|
#'always 'require-match)))
|
||||||
`(l "\\begin{" ,environment "}" > n > r n "\\end{" ,environment "}" >)))
|
`(l "\\begin{" ,environment "}" > n > r n "\\end{" ,environment "}" >)))
|
||||||
|
|
||||||
(setq tempo-user-elements 'nil)
|
|
||||||
(cl-pushnew 'tempo-latex-environment-handler tempo-user-elements)
|
(cl-pushnew 'tempo-latex-environment-handler tempo-user-elements)
|
||||||
|
|
||||||
(tempo-define-template
|
(defun setup-tempo-latex ()
|
||||||
"LaTeX-environment"
|
(setup-local-tempo-key-bindings)
|
||||||
'('latex-environment)
|
(defvar latex-tempo-tags nil)
|
||||||
"latex-environment"
|
|
||||||
"Insert a LaTeX environment"))
|
(tempo-define-template
|
||||||
|
"LaTeX-environment"
|
||||||
|
'('latex-environment)
|
||||||
|
"env"
|
||||||
|
"Insert a LaTeX environment"
|
||||||
|
'latex-tempo-tags)
|
||||||
|
|
||||||
|
(tempo-use-tag-list 'latex-tempo-tags)
|
||||||
|
(add-tempo-tags-to-abbrev-table latex-tempo-tags latex-mode-abbrev-table))
|
||||||
|
|
||||||
|
(add-hook 'LaTeX-mode-hook 'setup-tempo-latex))
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+caption[Configure =tempo= for =python-mode=]:
|
||||||
|
#+caption: Configure =tempo= for =python-mode=.
|
||||||
|
#+name: lst:setup-python-tempo
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(with-eval-after-load 'python
|
||||||
|
(unless (featurep 'tempo)
|
||||||
|
(require 'tempo))
|
||||||
|
|
||||||
|
(defun setup-tempo-python ()
|
||||||
|
(setup-local-tempo-key-bindings)
|
||||||
|
|
||||||
|
(defvar python-tempo-tags nil)
|
||||||
|
|
||||||
|
(tempo-define-template
|
||||||
|
"python-class"
|
||||||
|
'("class " p ":" n >)
|
||||||
|
"cls"
|
||||||
|
"Insert a class"
|
||||||
|
'python-tempo-tags)
|
||||||
|
|
||||||
|
(tempo-use-tag-list 'python-tempo-tags)
|
||||||
|
(add-tempo-tags-to-abbrev-table python-tempo-tags python-mode-abbrev-table))
|
||||||
|
|
||||||
|
(add-hook 'python-mode-hook 'setup-tempo-python))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
* [[info:emacs#Display][Display (info)]]
|
* [[info:emacs#Display][Display (info)]]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user