summaryrefslogtreecommitdiff
path: root/completion-conf.el
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2021-02-08 23:36:26 +0800
committerJSDurand <mmemmew@gmail.com>2021-02-08 23:36:26 +0800
commit393604e5bf4ce15df7342fdc094900fd1be2b39f (patch)
treed7b1e77cfe27b3ffa347fa2e9db632d97dfe7dc1 /completion-conf.el
parentc8d4224e42a710b262e8ba67d720f6eff4e89fcb (diff)
Constantly growing
A lot of improvements.
Diffstat (limited to 'completion-conf.el')
-rw-r--r--completion-conf.el48
1 files changed, 47 insertions, 1 deletions
diff --git a/completion-conf.el b/completion-conf.el
index 1ae21e2..ed28b06 100644
--- a/completion-conf.el
+++ b/completion-conf.el
@@ -31,7 +31,7 @@
(require 'minibuffer)
(require 'simple)
-(setq completion-styles '(initials substring partial-completion flex))
+(setq completion-styles '(initials substring partial-completion regex flex))
(setq completion-category-defaults nil)
(setq completion-flex-nospace nil)
(setq completion-pcm-complete-word-inserts-delimiters t)
@@ -88,6 +88,52 @@ minibuffer as usual."
(remove-hook 'minibuffer-setup-hook 'durand-headlong-minibuffer-setup-hook)
(remove-hook 'minibuffer-exit-hook 'durand-headlong-minibuffer-exit-hook))
+;;;###autoload
+(defun regex-try-completion (string table pred point &optional metadata)
+ "The function that tries to complete STRING using completion table \
+TABLE for the `regex' style.
+Only the elements that satisfy the predicate PRED are considered.
+
+POINT is the position of point within STRING.
+
+The return value is nil if there is no completion, and is t if
+STRING is the only possible completion. It is a pair
+
+\(NEWSTRING . NEWPOINT)
+
+otherwise, where NEWSTRING is the completed result and NEWPOINT
+is the new position for point."
+ (let* ((completion-regexp-list (cons string completion-regexp-list))
+ (result (try-completion "" table pred)))
+ (cond
+ ;; For nil values we don't have to return nil explicitly.
+ ((null result) nil)
+ ((eq result t))
+ ((stringp result) (cons result (length result))))))
+
+;;;###autoload
+(defun regex-all-completion (string table pred point &optional metadata)
+ "List the possible completions of STRING in completion table \
+TABLE for the style `regex'.
+Only the elements of TABLE that satisfy the predicate PRED are
+considered. POINT is the position of point within STRING.
+
+The return value is a list of completions and may contain the
+base-size in the last `cdr'."
+ (let ((completion-regexp-list (cons string completion-regexp-list)))
+ (all-completions "" table pred)))
+
+(let ((style-elements
+ (list #'regex-try-completion
+ #'regex-all-completion
+ "Simple regular expression completion.
+This considers the input as the regular expression itself." ))
+ (assoc-result (assoc 'regex completion-styles-alist)))
+ (cond
+ (assoc-result (setcdr assoc-result style-elements))
+ ((setq completion-styles-alist
+ (cons (cons 'regex style-elements) completion-styles-alist)))))
+
(provide 'completion-conf)
;;; completion-conf.el ends here