Provide an outward-facing function for generating tempel abbrev expansions #135
Replies: 2 comments 1 reply
-
Sorry for not answering earlier to your proposal. Does this space problem still exist? Iirc I've fixed this a while ago. |
Beta Was this translation helpful? Give feedback.
-
I just stumbled into the same issue. Upon some debugging, I found that the abbrev hook must return
Then, my current solution is just to return (define-minor-mode tempel-abbrev-mode
"Install Tempel templates as abbrevs."
:group 'tempel
:global nil
(setq-local abbrev-minor-mode-table-alist
(assq-delete-all 'tempel-abbrev-mode abbrev-minor-mode-table-alist))
(when (eq abbrev-minor-mode-table-alist
(default-value 'abbrev-minor-mode-table-alist))
(kill-local-variable 'abbrev-minor-mode-table-alist))
(when tempel-abbrev-mode
(let ((table (make-abbrev-table))
(tempel--ignore-condition t))
(dolist (template (tempel--templates))
(let* ((name (symbol-name (car template)))
(hook (make-symbol name)))
(fset hook (lambda ()
(tempel--delete-word name)
(tempel--insert (cdr template) nil)
t)) ;; <====== ADD RETURN VALUE HERE ==============================
(put hook 'no-self-insert t)
(define-abbrev table name 'Template hook :system t
:enable-function
(lambda () (assq (car template) (tempel--templates))))))
(setq-local abbrev-minor-mode-table-alist
(cons `(tempel-abbrev-mode . ,table)
abbrev-minor-mode-table-alist))))) |
Beta Was this translation helpful? Give feedback.
-
tempel-abbrev-mode
is too assumingThe solution to #69, namely the introduction of
tempel-abbrev-mode
andglobal-tempel-abbrev-mode
, is too assuming and overblown and fails to address the issue's core problem. The core problem is that binding an abbreviation to a function that expands a tempel snippet (as I show below) adds an unecessary space after the snippet is expanded. The problem is not a need to automatically generate an abbrev for every template.recommended solution
What is needed is simply a user-facing function (as shown below) that generates and returns a function that expands into the specified snippet without adding this extra space. This way the user has a convenient way to actually bind an abbrev to a snippet.
real-life example
The provided
tempel-abbrev-mode
and its counterpartglobal-tempel-abbrev-mode
do not provide a tool for the user to define their own abbrevs. Opinionated in nature, they assume how users want the abbrev snippets defined and do it for them. In contrast,tempel-abbrev-def
only facilitates defining abbrev snippets leaving it users to define their own abbrevs the way they want to–choosing the abbrev name, exactly which snippets they want to have an abbrev for, etc.Below I provide the real-life example where I had a need for this function and
tempel-abbrev-mode
did not really help at all–other than being a template from which I learned to writetempel-abbrev-def
.note about laziness
Ideally, tempel should only be loaded (assuming it is not already) when an abbrev that expands to a tempel snippet is expanded. In my example tempel is loaded upon the invocation of
tempel-abbrev-def
.Beta Was this translation helpful? Give feedback.
All reactions