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

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

[elpa] externals/cape f68a676046 1/3: Add cape-history


From: ELPA Syncer
Subject: [elpa] externals/cape f68a676046 1/3: Add cape-history
Date: Fri, 29 Apr 2022 14:57:19 -0400 (EDT)

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

    Add cape-history
---
 README.org |  3 +++
 cape.el    | 29 +++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/README.org b/README.org
index 9a15c72dc1..ffbbd4d444 100644
--- a/README.org
+++ b/README.org
@@ -40,6 +40,7 @@ are not using Company as frontend.
 
 + ~cape-dabbrev~: Complete word from current buffers
 + ~cape-file~: Complete file name
++ ~cape-history~: Complete from Eshell, Comint or minibuffer history
 + ~cape-keyword~: Complete programming language keyword
 + ~cape-symbol~: Complete Elisp symbol
 + ~cape-abbrev~: Complete abbreviation (~add-global-abbrev~, ~add-mode-abbrev~)
@@ -70,6 +71,7 @@ could be upstreamed into Emacs itself.
     :bind (("C-c p p" . completion-at-point) ;; capf
            ("C-c p t" . complete-tag)        ;; etags
            ("C-c p d" . cape-dabbrev)        ;; or dabbrev-completion
+           ("C-c p h" . cape-history)
            ("C-c p f" . cape-file)
            ("C-c p k" . cape-keyword)
            ("C-c p s" . cape-symbol)
@@ -86,6 +88,7 @@ could be upstreamed into Emacs itself.
     ;; Add `completion-at-point-functions', used by `completion-at-point'.
     (add-to-list 'completion-at-point-functions #'cape-file)
     (add-to-list 'completion-at-point-functions #'cape-dabbrev)
+    ;;(add-to-list 'completion-at-point-functions #'cape-history)
     ;;(add-to-list 'completion-at-point-functions #'cape-keyword)
     ;;(add-to-list 'completion-at-point-functions #'cape-tex)
     ;;(add-to-list 'completion-at-point-functions #'cape-sgml)
diff --git a/cape.el b/cape.el
index a216a998b6..114c55dca8 100644
--- a/cape.el
+++ b/cape.el
@@ -185,6 +185,35 @@ VALID is the input comparator, see `cape--input-valid-p'."
 
 ;;;; Capfs
 
+;;;;; cape-history
+
+(declare-function ring-elements "ring")
+
+(defvar cape--history-properties
+  (list :company-kind (lambda (_) 'text))
+  "Completion extra properties for `cape-history'.")
+
+(defun cape-history (&optional interactive)
+  "Complete from Eshell, Comint or minibuffer history.
+If INTERACTIVE is nil the function acts like a capf."
+  (interactive (list t))
+  (if interactive
+      (cape--interactive #'cape-history)
+    (let ((history
+           (cond
+            ((derived-mode-p 'eshell-mode)
+             (bound-and-true-p eshell-history-ring))
+            ((derived-mode-p 'comint-mode)
+             (bound-and-true-p comint-history-ring))
+            ((and (minibufferp) (not (eq minibuffer-history-variable t)))
+             (symbol-value minibuffer-history-variable)))))
+      (when (ring-p history)
+        (setq history (ring-elements history)))
+      (when history
+        `(,(line-beginning-position) ,(point)
+          ,(cape--table-with-properties history :sort nil)
+          :exclusive no ,@cape--history-properties)))))
+
 ;;;;; cape-file
 
 (defvar cape--file-properties



reply via email to

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