From 393604e5bf4ce15df7342fdc094900fd1be2b39f Mon Sep 17 00:00:00 2001 From: JSDurand Date: Mon, 8 Feb 2021 23:36:26 +0800 Subject: Constantly growing A lot of improvements. --- completion-conf.el | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'completion-conf.el') 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 -- cgit v1.2.3-18-g5258