Skip to content

Commit

Permalink
Add cape-wrap-inside-code and cape-capf-inside-code
Browse files Browse the repository at this point in the history
  • Loading branch information
minad committed Jan 30, 2024
1 parent a687fbe commit 833efc5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#+author: Daniel Mendler
#+language: en

* Development

- Add =cape-wrap-inside-code= and =cape-capf-inside-code=.

* Version 1.2 (2024-01-23)

- =cape-capf-super=: Bugfixes.
Expand Down
1 change: 1 addition & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ the Capf transformers with =defalias= to a function symbol.
- ~cape-capf-accept-all~, ~cape-wrap-accept-all~: Create a Capf which accepts every input as valid.
- ~cape-capf-case-fold~, ~cape-wrap-case-fold~: Create a Capf which is case insensitive.
- ~cape-capf-debug~, ~cape-wrap-debug~: Create a Capf which prints debugging messages.
- ~cape-capf-inside-code~, ~cape-wrap-inside-code~: Ensure that Capf triggers only inside code (not comments).
- ~cape-capf-inside-comment~, ~cape-wrap-inside-comment~: Ensure that Capf triggers only inside comment.
- ~cape-capf-inside-faces~, ~cape-wrap-inside-faces~: Ensure that Capf triggers only inside text with certain faces.
- ~cape-capf-inside-string~, ~cape-wrap-inside-string~: Ensure that Capf triggers only inside a string literal.
Expand Down
19 changes: 13 additions & 6 deletions cape.el
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,12 @@ This function can be used as an advice around an existing Capf."
(memq fs faces))))
(funcall capf)))

;;;###autoload
(defun cape-wrap-inside-code (capf)
"Call CAPF only if inside not inside a comment.
This function can be used as an advice around an existing Capf."
(and (not (nth 4 (syntax-ppss))) (funcall capf)))

;;;###autoload
(defun cape-wrap-inside-comment (capf)
"Call CAPF only if inside comment.
Expand Down Expand Up @@ -1161,6 +1167,7 @@ This function can be used as an advice around an existing Capf."
;;;###autoload (autoload 'cape-capf-buster "cape")
;;;###autoload (autoload 'cape-capf-case-fold "cape")
;;;###autoload (autoload 'cape-capf-debug "cape")
;;;###autoload (autoload 'cape-capf-inside-code "cape")
;;;###autoload (autoload 'cape-capf-inside-comment "cape")
;;;###autoload (autoload 'cape-capf-inside-faces "cape")
;;;###autoload (autoload 'cape-capf-inside-string "cape")
Expand All @@ -1176,12 +1183,12 @@ This function can be used as an advice around an existing Capf."

(dolist (wrapper (list #'cape-wrap-accept-all #'cape-wrap-buster
#'cape-wrap-case-fold #'cape-wrap-debug
#'cape-wrap-inside-comment #'cape-wrap-inside-faces
#'cape-wrap-inside-string #'cape-wrap-nonexclusive
#'cape-wrap-noninterruptible #'cape-wrap-passthrough
#'cape-wrap-predicate #'cape-wrap-prefix-length
#'cape-wrap-properties #'cape-wrap-purify
#'cape-wrap-silent #'cape-wrap-super))
#'cape-wrap-inside-code #'cape-wrap-inside-comment
#'cape-wrap-inside-faces #'cape-wrap-inside-string
#'cape-wrap-nonexclusive #'cape-wrap-noninterruptible
#'cape-wrap-passthrough #'cape-wrap-predicate
#'cape-wrap-prefix-length #'cape-wrap-properties
#'cape-wrap-purify #'cape-wrap-silent #'cape-wrap-super))
(let ((name (string-remove-prefix "cape-wrap-" (symbol-name wrapper))))
(defalias (intern (format "cape-capf-%s" name))
(lambda (capf &rest args) (lambda () (apply wrapper capf args)))
Expand Down

0 comments on commit 833efc5

Please sign in to comment.