Skip to content

Commit

Permalink
Fix redisplaying buffer in multiples sources.
Browse files Browse the repository at this point in the history
* helm-files.el (helm-multi-files): helm-redisplay-buffer takes no arg.
* helm-locate.el (helm-locate-init): Same.
(helm-locate-source): Add the redisplay slot.
(helm-locate): helm-redisplay-buffer takes no arg.
* helm-source.el (helm-source): New slot redisplay.
* helm.el (helm-redisplay-buffer): Not all sources may be displayed after narrowing
so calculate first the sources actually displayed.

Fix setting locate basename in multifiles.

Fix also docstring of helm-redisplay-buffer and redisplay slot in helm-source.

* helm-files.el (helm-multi-files): Do it.
  • Loading branch information
thierryvolpiatto committed Jan 9, 2017
1 parent b7aab62 commit 61ef910
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 24 deletions.
8 changes: 4 additions & 4 deletions helm-files.el
Expand Up @@ -3759,13 +3759,13 @@ locate."
(when (and helm-locate-fuzzy-match
(not (string-match-p
"\\s-" helm-pattern)))
(helm-redisplay-buffer
helm-locate-fuzzy-sort-fn)))))
(helm-redisplay-buffer)))))
(let ((sources (remove 'helm-source-locate helm-for-files-preferred-list))
(helm-locate-command
(if helm-locate-fuzzy-match
(replace-regexp-in-string
"locate" "locate -b" helm-locate-command)
(unless (string-match-p "\\`locate -b" helm-locate-command)
(replace-regexp-in-string
"\\`locate" "locate -b" helm-locate-command))
helm-locate-command))
(old-key (lookup-key
helm-map
Expand Down
8 changes: 4 additions & 4 deletions helm-locate.el
Expand Up @@ -309,7 +309,7 @@ See also `helm-locate'."
((string= event "finished\n")
(when (and helm-locate-fuzzy-match
(not (string-match-p "\\s-" helm-pattern)))
(helm-redisplay-buffer helm-locate-fuzzy-sort-fn))
(helm-redisplay-buffer))
(with-helm-window
(setq mode-line-format
'(" " mode-line-buffer-identification " "
Expand All @@ -331,7 +331,8 @@ See also `helm-locate'."
(requires-pattern :initform 3)
(history :initform 'helm-file-name-history)
(persistent-action :initform 'helm-ff-kill-or-find-buffer-fname)
(candidate-number-limit :initform 9999)))
(candidate-number-limit :initform 9999)
(redisplay :initform (progn helm-locate-fuzzy-sort-fn))))

(defvar helm-source-locate
(helm-make-source "Locate" 'helm-locate-source
Expand Down Expand Up @@ -437,8 +438,7 @@ Where db_path is a filename matched by
(when (and helm-locate-fuzzy-match
(not (string-match-p
"\\s-" helm-pattern)))
(helm-redisplay-buffer
helm-locate-fuzzy-sort-fn)))))
(helm-redisplay-buffer)))))
(setq helm-ff-default-directory default-directory)
(helm-locate-1 arg nil nil (thing-at-point 'filename)))

Expand Down
13 changes: 13 additions & 0 deletions helm-source.el
Expand Up @@ -386,6 +386,19 @@
This attribute is not supported for asynchronous sources
since they perform pattern matching themselves.")

(redisplay
:initarg :redisplay
:initform 'identity
:custom (choice list function)
:documentation
" A function or a list of functions to apply to current list
of candidates when redisplaying buffer with `helm-redisplay-buffer'.
This is only interesting for modifying and redisplaying the whole list
of candidates in async sources.
It uses `identity' by default for when async sources are mixed with
normal sources, in this case these normal sources are not modified and
redisplayed as they are.")

(nomark
:initarg :nomark
:initform nil
Expand Down
51 changes: 35 additions & 16 deletions helm.el
Expand Up @@ -3351,22 +3351,25 @@ PRESELECT, if specified."
(helm-funcall-with-source source it)))
(helm-remove-candidate-cache source))

(defun helm-redisplay-buffer (functions)
"Modify candidates in `helm-buffer' with FUNCTIONS and redisplay them.
(defun helm-redisplay-buffer ()
"Redisplay candidates in `helm-buffer'.
Candidates are not recomputed, only redisplayed after modifying the
whole list of candidates in each source with FUNCTIONS. Note that
candidates are redisplayed with their display part with all properties
included only.
This function is used in async sources to transform the whole list of candidates
from the sentinel functions (i.e when all candidates have been computed) because
other filters like `candidate-transformer' are modifying only each chunk of candidates
from process-filter as they come in and not the whole list.
Use this for e.g sorting the whole list of async candidates once computed."
whole list of candidates in each source with functions found in
`redisplay' attribute of current source. Note that candidates are
redisplayed with their display part with all properties included only.
This function is used in async sources to transform the whole list of
candidates from the sentinel functions (i.e when all candidates have
been computed) because other filters like `candidate-transformer' are
modifying only each chunk of candidates from process-filter as they
come in and not the whole list. Use this for e.g sorting the whole
list of async candidates once computed."
(with-helm-buffer
(goto-char (point-min))
(let ((get-cands (lambda (source fns)
(let (candidates helm-move-to-line-cycle-in-source)
(let ((get-cands (lambda (source)
(let ((fns (assoc-default 'redisplay source))
candidates helm-move-to-line-cycle-in-source)
(helm-goto-source source)
(helm-next-line)
(helm-awhile (condition-case-unless-debug nil
(helm-get-selection nil 'withprop source)
(error nil))
Expand All @@ -3376,10 +3379,26 @@ Use this for e.g sorting the whole list of async candidates once computed."
(cl-return nil))
(helm-next-line))
(helm-funcall-with-source
source fns (nreverse candidates))))))
source fns (nreverse candidates)))))
(get-sources (lambda ()
(let (sources helm-move-to-line-cycle-in-source)
(helm-awhile (helm-get-current-source)
(push it sources)
(when (save-excursion
(helm-move--end-of-source)
(forward-line 1) (eobp))
(cl-return nil))
(helm-next-source))
(nreverse sources)))))
(goto-char (point-min))
(helm-update nil (helm-get-current-source)
(cl-loop for s in (helm-get-sources)
collect (funcall get-cands s functions))))))
(cl-loop with sources = (funcall get-sources)
for s in (helm-get-sources)
for name = (assoc-default 'name s) collect
(when (cl-loop for src in sources thereis
(string= name
(assoc-default 'name src)))
(funcall get-cands s)))))))

(defun helm-remove-candidate-cache (source)
"Remove SOURCE from `helm-candidate-cache'."
Expand Down

0 comments on commit 61ef910

Please sign in to comment.