summaryrefslogtreecommitdiff
path: root/helm-mode.el
diff options
context:
space:
mode:
Diffstat (limited to 'helm-mode.el')
-rw-r--r--helm-mode.el134
1 files changed, 79 insertions, 55 deletions
diff --git a/helm-mode.el b/helm-mode.el
index bcf02d5a..42198e68 100644
--- a/helm-mode.el
+++ b/helm-mode.el
@@ -1,6 +1,6 @@
;;; helm-mode.el --- Enable helm completion everywhere. -*- lexical-binding: t -*-
-;; Copyright (C) 2012 ~ 2019 Thierry Volpiatto <thierry.volpiatto@gmail.com>
+;; Copyright (C) 2012 ~ 2020 Thierry Volpiatto <thierry.volpiatto@gmail.com>
;; 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
@@ -241,7 +241,7 @@ Second call deletes backward char in current-buffer and quits helm completion,
letting the user start a new completion with a new prefix."
'(helm-mode-delete-char-backward-1 helm-mode-delete-char-backward-2) 1)
-(defcustom helm-completion-style 'emacs
+(defcustom helm-completion-style 'helm
"Style of completion to use in `completion-in-region'.
This affects only `completion-at-point' and friends, and
@@ -394,13 +394,17 @@ data would not be fully collected at init time.
If COLLECTION is an `obarray', a TEST should be needed. See `obarray'."
;; Ensure COLLECTION is computed from `helm-current-buffer'
;; because some functions used as COLLECTION work
- ;; only in the context of current-buffer (Issue #1030) .
+ ;; only in the context of current-buffer (Bug#1030) .
(with-helm-current-buffer
(let ((cands
- (cond ((vectorp collection)
+ (cond ((and alistp (hash-table-p collection))
+ (cl-loop for k being the hash-keys of collection
+ using (hash-values v)
+ collect (cons k v)))
+ ((vectorp collection)
(all-completions input collection test))
((and (symbolp collection) (boundp collection)
- ;; Issue #324 history is let-bounded and given
+ ;; Bug#324 history is let-bounded and given
;; quoted as hist argument of completing-read.
;; See example in `rcirc-browse-url'.
(symbolp (symbol-value collection)))
@@ -446,7 +450,7 @@ If COLLECTION is an `obarray', a TEST should be needed. See `obarray'."
(funcall collection input test t))
((and alistp (null test)) collection)
;; Next test ensure circular objects are removed
- ;; with `all-completions' (Issue #1530).
+ ;; with `all-completions' (Bug#1530).
(t (all-completions input collection test)))))
(if sort-fn (sort cands sort-fn) cands))))
@@ -459,7 +463,7 @@ If COLLECTION is an `obarray', a TEST should be needed. See `obarray'."
(defun helm-cr-default-transformer (candidates source)
"Default filter candidate function for `helm-comp-read'."
- (let ((must-match (helm-attr 'must-match source))
+ (let ((must-match (helm-get-attr 'must-match source))
unknown-pattern)
(unless (or (eq must-match t)
(string= helm-pattern "")
@@ -468,7 +472,7 @@ If COLLECTION is an `obarray', a TEST should be needed. See `obarray'."
(setq candidates (append (list
;; Unquote helm-pattern
;; when it is added
- ;; as candidate: Why? #2015
+ ;; as candidate: Why? (Bug#2015)
;; (replace-regexp-in-string
;; "\\s\\" "" helm-pattern)
helm-pattern)
@@ -498,7 +502,7 @@ If COLLECTION is an `obarray', a TEST should be needed. See `obarray'."
(defun helm-comp-read--move-to-first-real-candidate ()
(helm-aif (helm-get-selection nil 'withprop)
- ;; Avoid error with candidates with an image as display (#2296).
+ ;; Avoid error with candidates with an image as display (Bug#2296).
(when (equal (get-text-property 0 'display it) "[?]")
(helm-next-line))))
@@ -566,7 +570,9 @@ It is helm `completing-read' equivalent.
- PROMPT is the prompt name to use.
-- COLLECTION can be a list, vector, obarray or hash-table.
+- COLLECTION can be a list, alist, vector, obarray or hash-table.
+ For alists and hash-tables their car are use as real value of
+ candidate unless ALISTP is non-nil.
It can be also a function that receives three arguments:
the values string, predicate and t. See `all-completions' for more details.
@@ -640,7 +646,12 @@ Keys description:
- NOMARK: When non--nil don't allow marking candidates.
-- ALISTP: (default is non--nil) See `helm-comp-read-get-candidates'.
+- ALISTP:
+ When non-nil (default) pass the value of (DISPLAY . REAL)
+ candidate in COLLECTION to action when COLLECTION is an alist or a
+ hash-table, otherwise DISPLAY is always returned as result on exit,
+ which is the default when using `completing-read'.
+ See `helm-comp-read-get-candidates'.
- CANDIDATES-IN-BUFFER: when non--nil use a source build with
`helm-source-in-buffer' which is much faster.
@@ -687,7 +698,7 @@ that use `helm-comp-read'. See `helm-M-x' for example."
;; and :alistp is nil INPUT is passed to
;; `all-completions' which defeat helm
;; matching functions (multi match, fuzzy
- ;; etc...) issue #2134.
+ ;; etc...) Bug#2134.
collection test sort alistp
(if (and match-dynamic (null candidates-in-buffer))
helm-pattern ""))))
@@ -709,7 +720,7 @@ that use `helm-comp-read'. See `helm-M-x' for example."
;; Input is added to history in completing-read's
;; and may be regexp-quoted, so unquote it
;; but check if cand is a string (it may be at this stage
- ;; a symbol or nil) Issue #1553.
+ ;; a symbol or nil) Bug#1553.
when (stringp i)
collect (replace-regexp-in-string "\\s\\" "" i))))
(and hist-fc-transformer (helm-mklist hist-fc-transformer)))
@@ -793,7 +804,7 @@ that use `helm-comp-read'. See `helm-M-x' for example."
;; Avoid adding an incomplete input to history.
(when (and result history del-input)
(cond ((and (symbolp history) ; History is a symbol.
- (not (symbolp (symbol-value history)))) ; Fix Issue #324.
+ (not (symbolp (symbol-value history)))) ; Fix Bug#324.
;; Be sure history is not a symbol with a nil value.
(helm-aif (symbol-value history) (setcar it result)))
((consp history) ; A list with a non--nil value.
@@ -1041,15 +1052,17 @@ This handler uses dynamic matching which allows honouring `completion-styles'."
init hist default inherit-input-method
name buffer)
"Default `helm-mode' handler for all `completing-read'."
- (let* ((standard (memq helm-completion-style '(helm helm-fuzzy)))
+ (let* (;; Standard will be used as CANDS-IN-BUFFER arg.
+ (standard (and (memq helm-completion-style '(helm helm-fuzzy)) t))
(fn (if standard
#'helm-completing-read-default-1
#'helm-completing-read-default-2))
(helm-mode-fuzzy-match (eq helm-completion-style 'helm-fuzzy)))
- (apply fn
- prompt collection test require-match
- init hist default inherit-input-method
- name buffer standard)))
+ (funcall fn
+ prompt collection test require-match
+ init hist default inherit-input-method name buffer
+ ;; CANDS-IN-BUFFER
+ standard)))
(defun helm-mode--read-buffer-to-switch (prompt)
"[INTERNAL] This is used to advice `read-buffer-to-switch'.
@@ -1100,13 +1113,13 @@ See documentation of `completing-read' and `all-completions' for details."
;; Note: `minibuffer-with-setup-hook' may setup a lambda
;; calling `minibuffer-completion-help' or other minibuffer
;; functions we DONT WANT here, in these cases removing the hook
- ;; (a symbol) have no effect. Issue #448.
+ ;; (a symbol) have no effect. Bug#448.
;; Because `minibuffer-completion-table' and
;; `minibuffer-completion-predicate' are not bound
;; anymore here, these functions should have no effect now,
;; except in some rare cases like in `woman-file-name',
;; so remove all incompatible functions
- ;; from `minibuffer-setup-hook' (Issue #1205, #1240).
+ ;; from `minibuffer-setup-hook' (Bug#1205, Bug#1240).
;; otherwise helm have not the time to close its initial session.
(minibuffer-setup-hook
(cl-loop for h in minibuffer-setup-hook
@@ -1330,7 +1343,9 @@ Keys description:
(result (helm
:sources (if helm-mode-reverse-history
(reverse src-list) src-list)
- :input (expand-file-name initial-input)
+ :input (if (string-match helm-ff-url-regexp initial-input)
+ initial-input
+ (expand-file-name initial-input))
:prompt prompt
:candidate-number-limit candidate-number-limit
:resume 'noresume
@@ -1466,8 +1481,12 @@ Don't use it directly, use instead `helm-read-file-name' in your programs."
:buffer buf-name
:default default-filename
;; Helm handlers should always have a non nil INITIAL arg.
- :initial-input (expand-file-name init dir)
+ :initial-input (if (string-match helm-ff-url-regexp init)
+ init
+ (expand-file-name init dir))
:alistp nil
+ :nomark (null helm-comp-read-use-marked)
+ :marked-candidates helm-comp-read-use-marked
:must-match mustmatch
:test predicate
:noret reading-directory))))
@@ -1487,7 +1506,7 @@ Don't use it directly, use instead `helm-read-file-name' in your programs."
(file-name-as-directory fname)
fname)))
-;; Read file name handler with history (issue #1652)
+;; Read file name handler with history (Bug#1652)
(defun helm-read-file-name-handler-1 (prompt dir default-filename
mustmatch initial predicate
name buffer)
@@ -1579,8 +1598,9 @@ Actually does nothing."
(defun helm-completion-all-completions (string table pred point)
"The all completions function for `completing-styles-alist'."
;; FIXME: No need to bind all these value.
- (cl-multiple-value-bind (all _pattern prefix _suffix _carbounds)
- (helm-completion--multi-all-completions string table pred point)
+ ;; (cl-multiple-value-bind (all _pattern prefix _suffix _carbounds)
+ (pcase-let ((`(,all ,_pattern ,prefix ,_suffix ,_carbounds)
+ (helm-completion--multi-all-completions string table pred point)))
(when all (nconc all (length prefix)))))
(defun helm-completion--multi-all-completions-1 (string collection &optional predicate)
@@ -1620,11 +1640,11 @@ Actually does nothing."
(all-completions "" (or all collection)
(lambda (x &optional _y)
;; Second arg _y is needed when
- ;; COLLECTION is a hash-table issue
- ;; #2231 (C-x 8 RET).
+ ;; COLLECTION is a hash-table (Bug#2231)
+ ;; (C-x 8 RET).
;; Elements of COLLECTION may be
;; lists or alists, in this case consider the
- ;; car of element (issue #2219 org-refile).
+ ;; car of element (Bug#2219 org-refile).
(let ((elm (if (listp x) (car x) x)))
;; PREDICATE have been already called in
;; initial all-completions, no need to call
@@ -1647,7 +1667,12 @@ Actually does nothing."
(prefix (substring beforepoint 0 (car bounds)))
(suffix (substring afterpoint (cdr bounds)))
(all (helm-completion--multi-all-completions-1
- (regexp-quote string) table pred)))
+ ;; Using `regexp-quote' on STRING fixes bug#2355 but
+ ;; breaks regexp matching in multi match, actually with
+ ;; Helm-3.7.1 and emacs-27+ it seems using plain STRING
+ ;; works for both so use it.
+ ;;(regexp-quote string)
+ string table pred)))
(list all string prefix suffix point)))
;; The adjust-metadata functions run only in emacs-27, they are NOT
@@ -1673,8 +1698,8 @@ Actually does nothing."
;; It is needed here to make minibuffer-complete work in emacs-26,
;; e.g. with regular M-x.
(unless (string-match-p " " string)
- (cl-multiple-value-bind (all pattern prefix suffix _carbounds)
- (helm-completion--flex-all-completions string table pred point)
+ (pcase-let ((`(,all ,pattern ,prefix ,suffix ,_carbounds)
+ (helm-completion--flex-all-completions string table pred point)))
(when minibuffer-completing-file-name
(setq all (completion-pcm--filename-try-filter all)))
(completion-pcm--merge-try pattern all prefix suffix))))
@@ -1683,10 +1708,10 @@ Actually does nothing."
"The all completions function for `completing-styles-alist'."
;; FIXME: No need to bind all these value.
(unless (string-match-p " " string)
- (cl-multiple-value-bind (all pattern prefix _suffix _carbounds)
- (helm-completion--flex-all-completions
- string table pred point
- #'helm-completion--flex-transform-pattern)
+ (pcase-let ((`(,all ,pattern ,prefix ,_suffix ,_carbounds)
+ (helm-completion--flex-all-completions
+ string table pred point
+ #'helm-completion--flex-transform-pattern)))
(let ((regexp (completion-pcm--pattern->regex pattern 'group)))
(when all (nconc (helm-flex-add-score-as-prop all regexp)
(length prefix)))))))
@@ -1758,7 +1783,7 @@ Can be used for `completion-in-region-function' by advicing it with an
(if (cdr-safe it) (car it) it)))
;; This hook force usage of the display part of candidate with
;; its properties, this is needed for lsp-mode in its
- ;; :exit-function see issue #2265.
+ ;; :exit-function see Bug#2265.
(add-hook 'helm-before-action-hook 'helm-completion-in-region--selection)
(unwind-protect
(let* ((enable-recursive-minibuffers t)
@@ -1792,7 +1817,7 @@ Can be used for `completion-in-region-function' by advicing it with an
;; `afun' is a closure to call against each string in `data'.
;; it provide the annotation info for each string.
;; e.g "foo" => "foo <f>" where foo is a function.
- ;; See Issue #407.
+ ;; See Bug#407.
(afun (or (plist-get completion-extra-properties :annotation-function)
(completion-metadata-get metadata 'annotation-function)))
(init-space-suffix (unless (or (memq helm-completion-style '(helm-fuzzy emacs))
@@ -1910,14 +1935,19 @@ Can be used for `completion-in-region-function' by advicing it with an
(setq string (copy-sequence result))
(helm-completion-in-region--insert-result
result start point end base-size))
- ;; Allow running extra property `:exit-function' (Issues #2265,
- ;; #2356). Function is called with 'exact if for a unique
+ ;; Allow running extra property `:exit-function' (Bug#2265,
+ ;; Bug#2356). Function is called with 'exact if for a unique
;; match which is exact, the return value of `try-completion'
- ;; is t, otherwise it is called with 'finished.
+ ;; is t or a string ending with "/" i.e. possibly a directory
+ ;; (Bug#2274),
+ ;; otherwise it is called with 'finished.
(when (and (stringp string) exit-fun)
- (funcall exit-fun string
- (if (eq (try-completion initial-input collection) t)
- 'exact 'finished)))
+ (let ((tcomp (try-completion initial-input collection)))
+ (funcall exit-fun string
+ (if (or (eq tcomp t) ; Unique.
+ (and (stringp tcomp)
+ (string-match "/\\'" tcomp))) ; A directory.
+ 'exact 'finished))))
(remove-hook 'helm-before-action-hook 'helm-completion-in-region--selection)
(customize-set-variable 'helm-completion-style old--helm-completion-style)
(setq helm-completion--sorting-done nil)
@@ -1939,7 +1969,7 @@ Be sure to know what you are doing when modifying this.")
;; When RESULT have annotation, annotation is displayed
;; in it with a display property attached to a space
;; added at end of string, take care of removing this
- ;; space (issue #2360). However keep RESULT intact to
+ ;; space (Bug#2360). However keep RESULT intact to
;; pass it to `:exit-function' i.e. Don't store the
;; modified string in STRING.
(choose-completion-string
@@ -1958,7 +1988,7 @@ Be sure to know what you are doing when modifying this.")
(let ((beg (+ start base-size))
(sep (or (and
;; If `crm-separator' is a string of length 1
- ;; assume it can be used as separator (#2298),
+ ;; assume it can be used as separator (Bug#2298),
;; otherwise it is a regexp and use the value
;; it matches or default to "," if no match.
(eq (length crm-separator) 1)
@@ -1968,7 +1998,7 @@ Be sure to know what you are doing when modifying this.")
;; regexp use the string the regexp is matching.
;; If SEP is not a string, it have been probably bound to a
;; symbol or nil through `helm-crm-default-separator' that serve
- ;; as a flag to say "Please no separator" (Issue #2353 with
+ ;; as a flag to say "Please no separator" (Bug#2353 with
;; `magit-completing-read-multiple').
(if (stringp sep)
(save-excursion
@@ -2038,11 +2068,11 @@ Note: This mode is incompatible with Emacs23."
#'helm--completion-in-region))
;; If user have enabled ido-everywhere BEFORE enabling
;; helm-mode disable it and warn user about its
- ;; incompatibility with helm-mode (issue #2085).
+ ;; incompatibility with helm-mode (Bug#2085).
(helm-mode--disable-ido-maybe)
;; If ido-everywhere is not enabled yet anticipate and
;; disable it if user attempt to enable it while helm-mode
- ;; is running (issue #2085).
+ ;; is running (Bug#2085).
(add-hook 'ido-everywhere-hook #'helm-mode--ido-everywhere-hook)
(when (fboundp 'ffap-read-file-or-url-internal)
;; `ffap-read-file-or-url-internal' have been removed in
@@ -2062,10 +2092,4 @@ Note: This mode is incompatible with Emacs23."
(provide 'helm-mode)
-;; Local Variables:
-;; byte-compile-warnings: (not obsolete)
-;; coding: utf-8
-;; indent-tabs-mode: nil
-;; End:
-
;;; helm-mode.el ends here