Skip to content

Commit

Permalink
* helm.el: Issue #337 Introduce new attribute allow-dups.
Browse files Browse the repository at this point in the history
* helm-semantic.el: Use it.
* helm-imenu.el: idem.
* helm-help.el: Document it.
  • Loading branch information
thierryvolpiatto committed Nov 27, 2013
1 parent a53495d commit e91e2e3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
6 changes: 6 additions & 0 deletions helm-help.el
Expand Up @@ -1196,6 +1196,9 @@ HELM-ATTRIBUTE should be a symbol."
(helm-document-attribute 'nohighlight "optional"
" Disable highlight match in this source.")

(helm-document-attribute 'no-matchplugin "optional"
" Disable matchplugin for this source.")

(helm-document-attribute 'no-delay-on-input "optional"
" Don't use `while-no-input' when computing candidates.")

Expand All @@ -1211,6 +1214,9 @@ HELM-ATTRIBUTE should be a symbol."
See `helm-follow-mode' for more infos")

(helm-document-attribute 'allow-dups "optional"
" Allow helm collecting duplicates candidates.")

(provide 'helm-help)

;; Local Variables:
Expand Down
1 change: 1 addition & 0 deletions helm-imenu.el
Expand Up @@ -65,6 +65,7 @@
(defvar helm-source-imenu
'((name . "Imenu")
(candidates . helm-imenu-candidates)
(allow-dups)
(persistent-action . (lambda (elm)
(helm-imenu-default-action elm)
(unless (fboundp 'semantic-imenu-tag-overlay)
Expand Down
1 change: 1 addition & 0 deletions helm-semantic.el
Expand Up @@ -72,6 +72,7 @@
(with-current-buffer (helm-candidate-buffer 'global)
(helm-semantic-init-candidates tags 0)))))
(candidates-in-buffer)
(allow-dups)
(get-line . buffer-substring)
(persistent-action . (lambda (elm)
(helm-semantic-default-action elm)
Expand Down
18 changes: 10 additions & 8 deletions helm.el
Expand Up @@ -2381,12 +2381,13 @@ Default function to match candidates according to `helm-pattern'."
(if (listp matchfns) matchfns (list matchfns))))

(defmacro helm--accumulate-candidates (cand newmatches
hash item-count limit)
hash item-count limit source)
"Add CAND into NEWMATCHES and use HASH to uniq NEWMATCHES.
Argument ITEM-COUNT count the matches.
if ITEM-COUNT reaches LIMIT, exit from inner loop."
`(unless (gethash ,cand ,hash)
(puthash ,cand t ,hash)
(unless (assq 'allow-dups ,source)
(puthash ,cand t ,hash))
(push ,cand ,newmatches)
(cl-incf ,item-count)
(when (= ,item-count ,limit) (cl-return))))
Expand Down Expand Up @@ -2432,7 +2433,7 @@ and `helm-pattern'."
(cl-dolist (candidate cands)
(when (funcall match (helm-candidate-get-display candidate))
(helm--accumulate-candidates
candidate newmatches helm-match-hash item-count limit)))
candidate newmatches helm-match-hash item-count limit source)))
(setq matches (append matches (reverse newmatches)))
;; Don't recompute matches already found by this match function
;; with the next match function.
Expand Down Expand Up @@ -3496,7 +3497,8 @@ See also `helm-sources' docstring."
'(helm-candidates-in-buffer-search-from-start)))
(helm-candidate-number-limit source)
(assoc 'search-from-end source)
(helm-attr 'match-part)))
(helm-attr 'match-part)
source))

(defun helm-candidates-in-buffer-search-from-start (pattern)
"Search PATTERN with `re-search-forward' with bound and noerror args."
Expand All @@ -3508,7 +3510,7 @@ See also `helm-sources' docstring."

(defun helm-candidates-in-buffer-1 (buffer pattern get-line-fn
search-fns limit search-from-end
match-part-fn)
match-part-fn source)
"Return the list of candidates inserted in BUFFER matching PATTERN."
;; buffer == nil when candidates buffer does not exist.
(when buffer
Expand All @@ -3523,15 +3525,15 @@ See also `helm-sources' docstring."
endp get-line-fn limit search-from-end)
(helm-search-from-candidate-buffer
pattern get-line-fn search-fns limit search-from-end
start-point match-part-fn))))))
start-point match-part-fn source))))))

(defun helm-point-is-moved (proc)
"If point is moved after executing PROC, return t, otherwise nil."
(/= (point) (save-excursion (funcall proc) (point))))

(defun helm-search-from-candidate-buffer (pattern get-line-fn search-fns
limit search-from-end
start-point match-part-fn)
start-point match-part-fn source)
(let (buffer-read-only
matches
newmatches
Expand All @@ -3553,7 +3555,7 @@ See also `helm-sources' docstring."
;; match the part of CAND specified by the match-part func.
(helm-search-match-part cand pattern match-part-fn))
do (helm--accumulate-candidates
cand newmatches helm-cib-hash item-count limit)
cand newmatches helm-cib-hash item-count limit source)
unless (helm-point-is-moved
(lambda ()
(if search-from-end
Expand Down

0 comments on commit e91e2e3

Please sign in to comment.