branch: elpa/adoc-mode
commit 799c7fc41c0a80b069214d2cf3bd1e5906bb51ea
Author: Bozhidar Batsov <[email protected]>
Commit: Bozhidar Batsov <[email protected]>
[Fix #26] Fix tempo template failure with prefix argument
When tempo-insert-region is nil (the default), tempo-define-template
passes the raw prefix arg as on-region to tempo-insert-template.
A truthy prefix arg like (4) from C-u causes tempo-insert-template
to call (mark) which errors when no mark is set.
Add around-advice on tempo-insert-template that checks (mark t)
before allowing on-region to be truthy.
---
CHANGELOG.md | 1 +
adoc-mode.el | 9 +++++++++
2 files changed, 10 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cb19e7fee8..b52d3e77fc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -28,6 +28,7 @@
- [#54](https://github.com/bbatsov/adoc-mode/issues/54): Fix multiline
font-lock for inline formatting by extending fontification region to paragraph
boundaries.
- [#52](https://github.com/bbatsov/adoc-mode/issues/52): Prevent
`auto-fill-mode` from breaking section title lines.
- [#36](https://github.com/bbatsov/adoc-mode/issues/36): Remove `unichars.el`
dependency; use built-in `sgml-char-names` instead.
+- [#26](https://github.com/bbatsov/adoc-mode/issues/26): Fix `Wrong type
argument: number-or-marker-p` when calling tempo templates with a prefix
argument.
## 0.7.0 (2023-03-09)
diff --git a/adoc-mode.el b/adoc-mode.el
index b90b900d0c..a92e772a53 100644
--- a/adoc-mode.el
+++ b/adoc-mode.el
@@ -2758,6 +2758,15 @@ new customization demands."
(require 'tempo-snippets)
(require 'tempo))
+(defun adoc-tempo-insert-template-fix (orig-fn template on-region)
+ "Work around `tempo-insert-template' failing when ON-REGION is
+non-nil but no mark is set. When `tempo-insert-region' is nil,
+`tempo-define-template' passes the raw prefix arg as ON-REGION,
+which can be truthy even without an active region."
+ (funcall orig-fn template (and on-region (mark t) on-region)))
+
+(advice-add 'tempo-insert-template :around #'adoc-tempo-insert-template-fix)
+
(defun adoc-tempo-define (&rest args)
(if (eq adoc-tempo-frwk 'tempo-snippets)
(apply 'tempo-define-snippet args)