Skip to content

Commit

Permalink
Require Emacs 28.1
Browse files Browse the repository at this point in the history
  • Loading branch information
minad committed Sep 8, 2024
1 parent 317c0e4 commit 650e812
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.org
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#+html: <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/38/Temple_of_Hephaestus_%28Southwest%29%2C_Athens_-_20070711b.jpg/1920px-Temple_of_Hephaestus_%28Southwest%29%2C_Athens_-_20070711b.jpg" align="right" width="30%">

Tempel is a tiny template package for Emacs, which uses the syntax of the Emacs
Tempo library. Tempo is an ancient temple of the church of Emacs. It is 27 years
Tempo library. Tempo is an ancient temple of the church of Emacs. It is 30 years
old, but still in good shape since it successfully resisted change over the
decades. However it may look a bit dusty here and there. Therefore we present
Tempel, a new implementation of Tempo with inline expansion and integration with
Expand Down
26 changes: 14 additions & 12 deletions tempel.el
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
;; Maintainer: Daniel Mendler <mail@daniel-mendler.de>
;; Created: 2022
;; Version: 1.2
;; Package-Requires: ((emacs "27.1") (compat "30"))
;; Package-Requires: ((emacs "28.1") (compat "30"))
;; Homepage: https://github.com/minad/tempel
;; Keywords: abbrev, languages, tools, text

Expand Down Expand Up @@ -76,11 +76,11 @@ trigger completion."

(defcustom tempel-insert-annotation 40
"Annotation width for `tempel-insert'."
:type '(choice (const nil natnum)))
:type '(choice (const nil) natnum))

(defcustom tempel-complete-annotation 20
"Annotation width for `tempel-complete'."
:type '(choice (const nil natnum)))
:type '(choice (const nil) natnum))

(defcustom tempel-user-elements nil
"List of user element handler functions.
Expand Down Expand Up @@ -537,14 +537,20 @@ This is meant to be a source in `tempel-template-sources'."
((and (< dir 0) (< stop pt))
(setq next (max (or next -1) stop)))))))))

(defun tempel--active-p (_sym buffer)
"Return non-nil if Tempel is active in BUFFER."
(buffer-local-value 'tempel--active buffer))

(defun tempel-beginning ()
"Move to beginning of the template."
(declare (completion tempel--active-p))
(interactive)
(when-let ((pos (tempel--beginning)))
(if (= pos (point)) (tempel-done) (goto-char pos))))

(defun tempel-end ()
"Move to end of the template."
(declare (completion tempel--active-p))
(interactive)
(when-let ((pos (tempel--end)))
(if (= pos (point)) (tempel-done) (goto-char pos))))
Expand All @@ -560,13 +566,15 @@ This is meant to be a source in `tempel-template-sources'."

(defun tempel-kill ()
"Kill the field contents."
(declare (completion tempel--active-p))
(interactive)
(if-let ((ov (tempel--field-at-point)))
(kill-region (overlay-start ov) (overlay-end ov))
(kill-sentence nil)))

(defun tempel-next (arg)
"Move ARG fields forward and quit at the end."
(declare (completion tempel--active-p))
(interactive "p")
(cl-loop for i below (abs arg) do
(if-let ((next (tempel--find arg)))
Expand All @@ -580,6 +588,7 @@ This is meant to be a source in `tempel-template-sources'."

(defun tempel-previous (arg)
"Move ARG fields backward and quit at the beginning."
(declare (completion tempel--active-p))
(interactive "p")
(tempel-next (- arg)))

Expand All @@ -595,6 +604,7 @@ This is meant to be a source in `tempel-template-sources'."

(defun tempel-abort ()
"Abort template insertion."
(declare (completion tempel--active-p))
(interactive)
;; TODO abort only the topmost template?
(while-let ((st (car tempel--active)))
Expand All @@ -615,6 +625,7 @@ This is meant to be a source in `tempel-template-sources'."

(defun tempel-done ()
"Template completion is done."
(declare (completion tempel--active-p))
(interactive)
;; TODO disable only the topmost template?
(while tempel--active (tempel--done)))
Expand Down Expand Up @@ -799,14 +810,5 @@ If called interactively, select a template with `completing-read'."
(unless (or noninteractive (eq (aref (buffer-name) 0) ?\s))
(tempel-abbrev-mode 1)))

;; Emacs 28: Do not show Tempel commands in M-X
(dolist (sym (list #'tempel-next #'tempel-previous #'tempel-beginning
#'tempel-end #'tempel-kill #'tempel-done #'tempel-abort))
(put sym 'completion-predicate #'tempel--command-p))

(defun tempel--command-p (_sym buffer)
"Return non-nil if Tempel is active in BUFFER."
(buffer-local-value 'tempel--active buffer))

(provide 'tempel)
;;; tempel.el ends here

0 comments on commit 650e812

Please sign in to comment.