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

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

[elpa] externals/capf-autosuggest a5f0de5 19/63: Rearrange functions


From: ELPA Syncer
Subject: [elpa] externals/capf-autosuggest a5f0de5 19/63: Rearrange functions
Date: Wed, 27 Oct 2021 14:57:56 -0400 (EDT)

branch: externals/capf-autosuggest
commit a5f0de57d432b30d53487258790572c0d2f3035f
Author: jakanakaevangeli <jakanakaevangeli@chiru.no>
Commit: jakanakaevangeli <jakanakaevangeli@chiru.no>

    Rearrange functions
---
 capf-autosuggest.el | 102 ++++++++++++++++++++++++++--------------------------
 1 file changed, 51 insertions(+), 51 deletions(-)

diff --git a/capf-autosuggest.el b/capf-autosuggest.el
index 1f26387..4a2c275 100644
--- a/capf-autosuggest.el
+++ b/capf-autosuggest.el
@@ -56,47 +56,6 @@ hint to only return a list of one element for optimization.")
 (defvar-local capf-autosuggest--region '(nil)
   "Region of `completion-at-point'.")
 
-;;;###autoload
-(defmacro capf-autosuggest-define-partial-accept-cmd (name command)
-  "Define a command NAME.
-It will call COMMAND interactively, allowing it to move point
-into an auto-suggested overlay.  COMMAND must not modify buffer.
-NAME must not be called if variable
-`capf-autosuggest-active-mode' is inactive.  NAME is suitable for
-binding in `capf-autosuggest-active-mode-map'."
-  `(defun ,name ()
-     ,(format "`%s', possibly moving point into an auto-suggested overlay."
-              command)
-     (interactive)
-     (capf-autosuggest-call-partial-accept-cmd #',command)))
-
-(defun capf-autosuggest-call-partial-accept-cmd (command)
-  "Call COMMAND interactively, stepping into auto-suggested overlay.
-Temporarily convert the overlay to buffer text and call COMMAND
-interactively.  Afterwards, the added text is deleted, but only
-the portion after point.  Additionally, if point is outside of
-the added text, the whole text is deleted."
-  (let (beg end text)
-    (with-silent-modifications
-      (catch 'cancel-atomic-change
-        (atomic-change-group
-          (save-excursion
-            (goto-char (overlay-start capf-autosuggest--overlay))
-            (setq beg (point))
-            (insert capf-autosuggest--str)
-            (setq end (point)))
-          (call-interactively command)
-          (and (> (point) beg)
-               (<= (point) end)
-               (setq text (buffer-substring beg (point))))
-          (throw 'cancel-atomic-change nil))))
-    (when text
-      (if (= (point) beg)
-          (insert text)
-        (save-excursion
-          (goto-char beg)
-          (insert text))))))
-
 (defvar capf-autosuggest-active-mode)
 
 (defun capf-autosuggest--post-h ()
@@ -156,6 +115,47 @@ the added text, the whole text is deleted."
     (remove-hook 'completion-in-region-mode-hook #'capf-autosuggest--post-h t)
     (capf-autosuggest-active-mode -1)))
 
+;;;###autoload
+(defmacro capf-autosuggest-define-partial-accept-cmd (name command)
+  "Define a command NAME.
+It will call COMMAND interactively, allowing it to move point
+into an auto-suggested overlay.  COMMAND must not modify buffer.
+NAME must not be called if variable
+`capf-autosuggest-active-mode' is inactive.  NAME is suitable for
+binding in `capf-autosuggest-active-mode-map'."
+  `(defun ,name ()
+     ,(format "`%s', possibly moving point into an auto-suggested overlay."
+              command)
+     (interactive)
+     (capf-autosuggest-call-partial-accept-cmd #',command)))
+
+(defun capf-autosuggest-call-partial-accept-cmd (command)
+  "Call COMMAND interactively, stepping into auto-suggested overlay.
+Temporarily convert the overlay to buffer text and call COMMAND
+interactively.  Afterwards, the added text is deleted, but only
+the portion after point.  Additionally, if point is outside of
+the added text, the whole text is deleted."
+  (let (beg end text)
+    (with-silent-modifications
+      (catch 'cancel-atomic-change
+        (atomic-change-group
+          (save-excursion
+            (goto-char (overlay-start capf-autosuggest--overlay))
+            (setq beg (point))
+            (insert capf-autosuggest--str)
+            (setq end (point)))
+          (call-interactively command)
+          (and (> (point) beg)
+               (<= (point) end)
+               (setq text (buffer-substring beg (point))))
+          (throw 'cancel-atomic-change nil))))
+    (when text
+      (if (= (point) beg)
+          (insert text)
+        (save-excursion
+          (goto-char beg)
+          (insert text))))))
+
 (declare-function evil-forward-char "ext:evil-commands" nil t)
 (declare-function evil-end-of-line "ext:evil-commands" nil t)
 (declare-function evil-end-of-visual-line "ext:evil-commands" nil t)
@@ -183,6 +183,16 @@ the added text, the whole text is deleted."
 (capf-autosuggest-define-partial-accept-cmd 
capf-autosuggest-evil-forward-WORD-begin evil-forward-WORD-begin)
 (capf-autosuggest-define-partial-accept-cmd 
capf-autosuggest-evil-forward-WORD-end evil-forward-WORD-end)
 
+(defun capf-autosuggest-accept ()
+  "Accept current auto-suggestion.
+Do not call this command if variable `capf-autosuggest-active-mode' is
+inactive."
+  (interactive)
+  (capf-autosuggest-call-partial-accept-cmd
+   (lambda ()
+     (interactive)
+     (goto-char (overlay-start capf-autosuggest--overlay)))))
+
 (defvar capf-autosuggest-active-mode-map
   (let ((map (make-sparse-keymap)))
     (define-key map [remap forward-word] #'capf-autosuggest-forward-word)
@@ -203,16 +213,6 @@ the added text, the whole text is deleted."
     map)
   "Keymap active when an auto-suggestion is shown.")
 
-(defun capf-autosuggest-accept ()
-  "Accept current auto-suggestion.
-Do not call this command if variable `capf-autosuggest-active-mode' is
-inactive."
-  (interactive)
-  (capf-autosuggest-call-partial-accept-cmd
-   (lambda ()
-     (interactive)
-     (goto-char (overlay-start capf-autosuggest--overlay)))))
-
 (defun capf-autosuggest--active-acf (beg end _length)
   "Deactivate auto-suggestion on completion region modifications.
 BEG and END denote the changed region."



reply via email to

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