branch: externals/cape
commit 80ca6abfd50196608b81e6a25ad372b50ee5f409
Author: Daniel Mendler <[email protected]>
Commit: Daniel Mendler <[email protected]>
Add cape-line
---
README.org | 1 +
cape.el | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/README.org b/README.org
index eef1a87b08..607ffc1d60 100644
--- a/README.org
+++ b/README.org
@@ -50,6 +50,7 @@ this package should be upstreamed into Emacs itself.
("C-c p s" . cape-symbol)
("C-c p a" . cape-abbrev)
("C-c p i" . cape-ispell)
+ ("C-c p l" . cape-line)
("C-c p w" . cape-dict))
:init
;; Add `completion-at-point-functions', used by `completion-at-point'.
diff --git a/cape.el b/cape.el
index e6600fe145..4c7d1f2dc9 100644
--- a/cape.el
+++ b/cape.el
@@ -710,6 +710,27 @@ VALID is the input comparator, see `cape--input-valid-p'."
(complete-with-action action table str pred)))
,@plist)))))
+;;;###autoload
+(defun cape-line ()
+ "Complete current line from other lines in buffer."
+ (interactive)
+ (let ((beg (point-min))
+ (max (point-max))
+ (pt (point))
+ (ht (make-hash-table :test #'equal))
+ end lines)
+ (save-excursion
+ (while (< beg max)
+ (goto-char beg)
+ (setq end (line-end-position))
+ (unless (<= beg pt end)
+ (let ((line (buffer-substring-no-properties beg end)))
+ (unless (or (string-blank-p line) (gethash line ht))
+ (puthash line t ht)
+ (push line lines))))
+ (setq beg (1+ end))))
+ (completion-in-region (line-beginning-position) (point) lines)))
+
;;;###autoload
(defun cape-capf-with-properties (capf &rest properties)
"Return a new CAPF with additional completion PROPERTIES.