summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.org1
-rw-r--r--README.org1
-rw-r--r--cape.el12
3 files changed, 14 insertions, 0 deletions
diff --git a/CHANGELOG.org b/CHANGELOG.org
index 033c4f9..40de742 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -7,6 +7,7 @@
- =cape-emoji=: New Capf available on Emacs 29 and newer.
- =cape-wrap-debug=, =cape-capf-debug=: New Capf transformers to add debug messages
to a Capf.
+- =cape-capf-inside-faces=, =cape-wrap-inside-faces=: New transformer
- Rename =cape-super-capf= to =cape-capf-super=. Add =cape-wrap-super= for consistency
with other Capf combinators.
- Rename =cape-symbol= to =cape-elisp-symbol=.
diff --git a/README.org b/README.org
index b26f9bc..4f60e4a 100644
--- a/README.org
+++ b/README.org
@@ -265,6 +265,7 @@ the Capf transformers with =defalias= to a function symbol.
- ~cape-wrap-prefix-length~, ~cape-capf-prefix-length~: Enforce a minimal prefix length.
- ~cape-wrap-super~, ~cape-capf-super~: Merge multiple Capfs into a Super-Capf.
- ~cape-wrap-inside-comment~, ~cape-capf-inside-comment~: Ensure that Capf triggers only inside comment.
+- ~cape-wrap-inside-faces~, ~cape-capf-inside-faces~: Ensure that Capf triggers only inside text with certain faces.
- ~cape-wrap-inside-string~, ~cape-capf-inside-string~: Ensure that Capf triggers only inside a string literal.
In the following we show a few example configurations, which have come up on the
diff --git a/cape.el b/cape.el
index e666bd8..fa4b43f 100644
--- a/cape.el
+++ b/cape.el
@@ -1061,6 +1061,16 @@ If the prefix is long enough, enforce auto completion."
,@plist)))))
;;;###autoload
+(defun cape-wrap-inside-faces (capf &rest faces)
+ "Call CAPF only if inside FACES.
+This function can be used as an advice around an existing Capf."
+ (when-let ((fs (get-text-property (point) 'face))
+ ((if (listp fs)
+ (cl-loop for f in fs thereis (memq f faces))
+ (memq fs faces))))
+ (funcall capf)))
+
+;;;###autoload
(defun cape-wrap-inside-comment (capf)
"Call CAPF only if inside comment.
This function can be used as an advice around an existing Capf."
@@ -1117,6 +1127,8 @@ This function can be used as an advice around an existing Capf."
(cape--capf-wrapper debug)
;;;###autoload (autoload 'cape-capf-inside-comment "cape")
(cape--capf-wrapper inside-comment)
+;;;###autoload (autoload 'cape-capf-inside-faces "cape")
+(cape--capf-wrapper inside-faces)
;;;###autoload (autoload 'cape-capf-inside-string "cape")
(cape--capf-wrapper inside-string)
;;;###autoload (autoload 'cape-capf-super "cape")