emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/cape a57cc31f42: Add cape-wrap-purify and cape-capf-pur


From: ELPA Syncer
Subject: [elpa] externals/cape a57cc31f42: Add cape-wrap-purify and cape-capf-purify
Date: Wed, 19 Jan 2022 15:57:18 -0500 (EST)

branch: externals/cape
commit a57cc31f42a86cdaaee027daafad814a08ffbdcc
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    Add cape-wrap-purify and cape-capf-purify
---
 README.org |  1 +
 cape.el    | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/README.org b/README.org
index 987a1b823b..cf8ef729e1 100644
--- a/README.org
+++ b/README.org
@@ -214,6 +214,7 @@ achieve a similarly refreshing strategy.
 
 - ~cape-interactive-capf~: Create a Capf which can be called interactively.
 - ~cape-wrap-silent~, ~cape-capf-silent~: Wrap a chatty Capf and silence it.
+- ~cape-wrap-purify~, ~cape-capf-purify~: Purify a broken Capf and ensure that 
it does not modify the buffer.
 - ~cape-wrap-noninterruptible~, ~cape-capf-noninterruptible:~ Protect a Capf 
which does not like to be interrupted.
 - ~cape-wrap-case-fold~, ~cape-capf-case-fold~: Create a Capf which is case 
insensitive.
 - ~cape-wrap-properties~, ~cape-capf-properties~: Add completion properties to 
a Capf.
diff --git a/cape.el b/cape.el
index ebe8c26e0b..73fde312f3 100644
--- a/cape.el
+++ b/cape.el
@@ -1034,6 +1034,24 @@ If DONT-FOLD is non-nil return a case sensitive table 
instead."
     (`(,beg ,end ,table . ,plist)
      `(,beg ,end ,(cape--noninterruptible-table table) ,@plist))))
 
+;;;###autoload
+(defun cape-wrap-purify (capf)
+  "Call CAPF and ensure that it does not modify the buffer."
+  ;; bug#50470: Fix Capfs which illegally modify the buffer or which
+  ;; illegally call `completion-in-region'. The workaround here has been
+  ;; proposed @jakanakaevangeli in bug#50470 and is used in
+  ;; @jakanakaevangeli's capf-autosuggest package.
+  (catch 'cape--illegal-completion-in-region
+    (condition-case nil
+        (let ((buffer-read-only t)
+              (inhibit-read-only nil)
+              (completion-in-region-function
+               (lambda (beg end coll pred)
+                 (throw 'cape--illegal-completion-in-region
+                        (list beg end coll :predicate pred)))))
+          (funcall capf))
+      (buffer-read-only nil))))
+
 (defmacro cape--capf-wrapper (wrapper)
   "Create a capf transformer for WRAPPER."
   `(defun ,(intern (format "cape-capf-%s" wrapper)) (&rest args)
@@ -1051,6 +1069,7 @@ If DONT-FOLD is non-nil return a case sensitive table 
instead."
 (cape--capf-wrapper predicate)
 (cape--capf-wrapper properties)
 (cape--capf-wrapper buster)
+(cape--capf-wrapper purify)
 
 (provide 'cape)
 ;;; cape.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]