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

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

[elpa] externals/capf-autosuggest 82c6851 25/63: Merge into one file


From: ELPA Syncer
Subject: [elpa] externals/capf-autosuggest 82c6851 25/63: Merge into one file
Date: Wed, 27 Oct 2021 14:57:58 -0400 (EDT)

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

    Merge into one file
---
 capf-autosuggest.el | 123 ++++++++++++++++++++++++++++++++++++++++-
 history-capf.el     | 156 ----------------------------------------------------
 2 files changed, 122 insertions(+), 157 deletions(-)

diff --git a/capf-autosuggest.el b/capf-autosuggest.el
index 888d492..c1cb88e 100644
--- a/capf-autosuggest.el
+++ b/capf-autosuggest.el
@@ -33,7 +33,19 @@
 
 ;;; Code:
 
-(eval-when-compile (require 'subr-x))
+(require 'ring)
+(eval-when-compile
+  (require 'subr-x)
+  (require 'cl-lib))
+
+(defvar comint-input-ring)
+(defvar comint-accum-marker)
+(defvar comint-use-prompt-regexp)
+(defvar eshell-history-ring)
+(defvar eshell-last-output-end)
+(declare-function eshell-bol "esh-mode")
+(declare-function comint-previous-matching-input-from-input "comint")
+(declare-function eshell-previous-matching-input-from-input "em-hist")
 
 (defface capf-autosuggest-face '((t :inherit file-name-shadow))
   "Face used for auto suggestions."
@@ -216,6 +228,7 @@ inactive."
     (define-key map [remap end-of-line] #'capf-autosuggest-end-of-line)
     (define-key map [remap move-end-of-line] 
#'capf-autosuggest-move-end-of-line)
     (define-key map [remap end-of-visual-line] 
#'capf-autosuggest-end-of-visual-line)
+
     (define-key map [remap evil-forward-char] 
#'capf-autosuggest-evil-forward-char)
     (define-key map [remap evil-end-of-line] 
#'capf-autosuggest-evil-end-of-line)
     (define-key map [remap evil-end-of-visual-line] 
#'capf-autosuggest-evil-end-of-visual-line)
@@ -226,6 +239,11 @@ inactive."
     (define-key map [remap evil-forward-word-end] 
#'capf-autosuggest-evil-forward-word-end)
     (define-key map [remap evil-forward-WORD-begin] 
#'capf-autosuggest-evil-forward-WORD-begin)
     (define-key map [remap evil-forward-WORD-end] 
#'capf-autosuggest-evil-forward-WORD-end)
+
+    (define-key map [remap eshell-previous-matching-input-from-input]
+      #'capf-autosuggest-eshell-previous-matching-input-from-input)
+    (define-key map [remap comint-previous-matching-input-from-input]
+      #'capf-autosuggest-comint-previous-matching-input-from-input)
     map)
   "Keymap active when an auto-suggestion is shown.")
 
@@ -247,5 +265,108 @@ BEG and END denote the changed region."
     (remove-hook 'after-change-functions #'capf-autosuggest--active-acf t)
     (delete-overlay capf-autosuggest--overlay)))
 
+;;;###autoload
+(defun capf-autosuggest-comint-capf ()
+  "Completion-at-point function for comint input history.
+Is only applicable if point is after the last prompt."
+  (let ((ring comint-input-ring)
+        (beg nil))
+    (and ring (ring-p ring) (not (ring-empty-p ring))
+         (or (and (setq beg comint-accum-marker)
+                  (setq beg (marker-position beg)))
+             (and (setq beg (get-buffer-process (current-buffer)))
+                  (setq beg (marker-position (process-mark beg)))))
+         (>= (point) beg)
+         (list beg (if comint-use-prompt-regexp
+                       (line-end-position)
+                     (field-end))
+               (capf-autosuggest--completion-table ring)
+               :exclusive 'no))))
+
+;;;###autoload
+(defun capf-autosuggest-eshell-capf ()
+  "Completion-at-point function for eshell input history.
+Is only applicable if point is after the last prompt."
+  (let ((ring eshell-history-ring)
+        (beg nil))
+    (and ring (ring-p ring) (not (ring-empty-p ring))
+         (setq beg eshell-last-output-end)
+         (setq beg (marker-position beg))
+         (>= (point) beg)
+         (list (save-excursion (eshell-bol) (point)) (point-max)
+               (capf-autosuggest--completion-table ring)
+               :exclusive 'no))))
+
+(defun capf-autosuggest--completion-table (ring)
+  "Return a completion table to complete on RING."
+  (let (self)
+    (setq
+     self
+     (lambda (input predicate action)
+       (cond
+        ((eq action t)
+         (cl-loop
+          with only-one = capf-autosuggest-all-completions-only-one
+          with regexps = completion-regexp-list
+          for i below (ring-size ring)
+          for elem = (ring-ref ring i)
+          if (string-prefix-p input elem)
+          if (cl-loop for regex in regexps
+                      always (string-match-p regex elem))
+          if (or (null predicate)
+                 (funcall predicate elem))
+          if only-one
+          return (list elem)
+          else collect elem))
+        ((eq action nil)
+         (complete-with-action
+          nil (let ((capf-autosuggest-all-completions-only-one nil))
+                (funcall self input predicate t))
+          input predicate))
+        ((eq action 'lambda)
+         (and (ring-member ring input)
+              (or (null predicate)
+                  (funcall predicate input))
+              (cl-loop for regex in completion-regexp-list
+                       always (string-match-p regex input))))
+        (t (complete-with-action
+            action (ring-elements ring) input predicate)))))))
+
+;;;###autoload
+(defun capf-autosuggest-setup-comint ()
+  "Setup capf-autosuggest for history suggestion in comint."
+  (capf-autosuggest-mode)
+  (add-hook 'capf-autosuggest-capf-functions #'capf-autosuggest-comint-capf 
nil t))
+
+;;;###autoload
+(defun capf-autosuggest-setup-eshell ()
+  "Setup capf-autosuggest for history suggestion in eshell."
+  (capf-autosuggest-mode)
+  (add-hook 'capf-autosuggest-capf-functions #'capf-autosuggest-eshell-capf 
nil t))
+
+(defun capf-autosuggest-comint-previous-matching-input-from-input (n)
+  "Like `comint-previous-matching-input-from-input'.
+But increase arument N by 1, if positive, but not on command
+repetition."
+  (interactive "p")
+  (and (not (memq last-command '(comint-previous-matching-input-from-input
+                                 comint-next-matching-input-from-input)))
+       (> n 0)
+       (setq n (1+ n)))
+  (comint-previous-matching-input-from-input n)
+  (setq this-command #'comint-previous-matching-input-from-input))
+
+(defun capf-autosuggest-eshell-previous-matching-input-from-input (n)
+  "Like `eshell-previous-matching-input-from-input'.
+But increase arument N by 1, if positive, but not on command
+repetition."
+  (interactive "p")
+  (and (not (memq last-command '(eshell-previous-matching-input-from-input
+                                 eshell-next-matching-input-from-input)))
+       (> n 0)
+       (setq n (1+ n)))
+  (eshell-previous-matching-input-from-input n)
+  (setq this-command #'eshell-previous-matching-input-from-input))
+
 (provide 'capf-autosuggest)
 ;;; capf-autosuggest.el ends here
diff --git a/history-capf.el b/history-capf.el
deleted file mode 100644
index 9312ff0..0000000
--- a/history-capf.el
+++ /dev/null
@@ -1,156 +0,0 @@
-;;; history-capf.el --- Completion-at-point function for comint and eshell 
history -*- lexical-binding: t; -*-
-
-;; Filename: history-capf.el
-;; Description: Completion-at-point function for comint and eshell history
-;; Author: jakanakaevangeli <jakanakaevangeli@chiru.no>
-;; Created: 2021-07-14
-;; Version: 1.0
-;; URL: https://github.com/jakanakaevangeli/emacs-capf-autosuggest
-
-;; This file is not part of GNU Emacs.
-
-;; This program is free software: you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or
-;; (at your option) any later version.
-
-;; This program is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-;; GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;;; Code:
-
-(require 'ring)
-(eval-when-compile (require 'cl-lib))
-
-(defvar capf-autosuggest-all-completions-only-one)
-(defvar capf-autosuggest-active-mode-map)
-(defvar comint-input-ring)
-(defvar comint-accum-marker)
-(defvar comint-use-prompt-regexp)
-(defvar eshell-history-ring)
-(defvar eshell-last-output-end)
-(autoload 'capf-autosuggest-mode "capf-autosuggest")
-(declare-function eshell-bol "esh-mode")
-(declare-function comint-previous-matching-input-from-input "comint")
-(declare-function eshell-previous-matching-input-from-input "em-hist")
-
-;;;###autoload
-(defun history-capf-comint ()
-  "Completion-at-point function for comint input history.
-Is only applicable if point is after the last prompt."
-  (let ((ring comint-input-ring)
-        (beg nil))
-    (and ring (ring-p ring) (not (ring-empty-p ring))
-         (or (and (setq beg comint-accum-marker)
-                  (setq beg (marker-position beg)))
-             (and (setq beg (get-buffer-process (current-buffer)))
-                  (setq beg (marker-position (process-mark beg)))))
-         (>= (point) beg)
-         (list beg (if comint-use-prompt-regexp
-                       (line-end-position)
-                     (field-end))
-               (hisotry-capf--completion-table ring)
-               :exclusive 'no))))
-
-;;;###autoload
-(defun history-capf-eshell ()
-  "Completion-at-point function for eshell input history.
-Is only applicable if point is after the last prompt."
-  (let ((ring eshell-history-ring)
-        (beg nil))
-    (and ring (ring-p ring) (not (ring-empty-p ring))
-         (setq beg eshell-last-output-end)
-         (setq beg (marker-position beg))
-         (>= (point) beg)
-         (list (save-excursion (eshell-bol) (point)) (point-max)
-               (hisotry-capf--completion-table ring)
-               :exclusive 'no))))
-
-(defun hisotry-capf--completion-table (ring)
-  "Return a completion table to complete on RING."
-  (let (self)
-    (setq
-     self
-     (lambda (input predicate action)
-       (cond
-        ((eq action t)
-         (cl-loop
-          with only-one = capf-autosuggest-all-completions-only-one
-          with regexps = completion-regexp-list
-          for i below (ring-size ring)
-          for elem = (ring-ref ring i)
-          if (string-prefix-p input elem)
-          if (cl-loop for regex in regexps
-                      always (string-match-p regex elem))
-          if (or (null predicate)
-                 (funcall predicate elem))
-          if only-one
-          return (list elem)
-          else collect elem))
-        ((eq action nil)
-         (complete-with-action
-          nil (let ((capf-autosuggest-all-completions-only-one nil))
-                (funcall self input predicate t))
-          input predicate))
-        ((eq action 'lambda)
-         (and (ring-member ring input)
-              (or (null predicate)
-                  (funcall predicate input))
-              (cl-loop for regex in completion-regexp-list
-                       always (string-match-p regex input))))
-        (t (complete-with-action
-            action (ring-elements ring) input predicate)))))))
-
-;;;###autoload
-(defun history-capf-setup-autosuggest-comint ()
-  "Setup capf-autosuggest for history suggestion in comint."
-  (capf-autosuggest-mode)
-  (add-hook 'capf-autosuggest-capf-functions #'history-capf-comint nil t))
-
-;;;###autoload
-(defun history-capf-setup-autosuggest-eshell ()
-  "Setup capf-autosuggest for history suggestion in eshell."
-  (capf-autosuggest-mode)
-  (add-hook 'capf-autosuggest-capf-functions #'history-capf-eshell nil t))
-
-(with-eval-after-load 'capf-autosuggest
-  (define-key capf-autosuggest-active-mode-map
-    [remap comint-previous-matching-input-from-input]
-    #'history-capf-comint-previous-matching-input-from-input)
-  (define-key capf-autosuggest-active-mode-map
-    [remap eshell-previous-matching-input-from-input]
-    #'history-capf-eshell-previous-matching-input-from-input))
-
-(defun history-capf-comint-previous-matching-input-from-input (n)
-  "Like `comint-previous-matching-input-from-input'.
-But increase arument N by 1, if positive, but not on command
-repetition."
-  (interactive "p")
-  (and (not (memq last-command '(comint-previous-matching-input-from-input
-                                 comint-next-matching-input-from-input)))
-       (> n 0)
-       (setq n (1+ n)))
-  (comint-previous-matching-input-from-input n)
-  (setq this-command #'comint-previous-matching-input-from-input))
-
-(defun history-capf-eshell-previous-matching-input-from-input (n)
-  "Like `eshell-previous-matching-input-from-input'.
-But increase arument N by 1, if positive, but not on command
-repetition."
-  (interactive "p")
-  (and (not (memq last-command '(eshell-previous-matching-input-from-input
-                                 eshell-next-matching-input-from-input)))
-       (> n 0)
-       (setq n (1+ n)))
-  (eshell-previous-matching-input-from-input n)
-  (setq this-command #'eshell-previous-matching-input-from-input))
-
-(provide 'history-capf)
-;;; history-capf.el ends here



reply via email to

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