Skip to content

Commit

Permalink
Add migemo for bookmarks, fix match-part for migemo (#1175).
Browse files Browse the repository at this point in the history
* helm-multi-match.el (helm-mm-migemo-string-match):
Use same order of args as string-match.
(helm-mm-3-migemo-match): Reverse args in helm-mm-migemo-string-match call.
* helm-types.el (helm--setup-source): Add migemo for bmks.
* helm.el (helm-search-from-candidate-buffer): Fix match-part for migemo.
  • Loading branch information
thierryvolpiatto committed Sep 21, 2015
1 parent 4826fb7 commit 3d20b06
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
6 changes: 3 additions & 3 deletions helm-multi-match.el
Expand Up @@ -271,17 +271,17 @@ i.e the sources which have the slot :migemo with non--nil value."
(cl-assert (featurep 'migemo)
nil "No feature called migemo found, install migemo.el."))

(cl-defun helm-mm-migemo-string-match (str &optional (pattern helm-pattern))
(defun helm-mm-migemo-string-match (pattern str)
"Migemo version of `string-match'."
(unless (string= pattern (car-safe helm-mm--previous-migemo-info))
(setq helm-mm--previous-migemo-info
(cons pattern (migemo-get-pattern pattern))))
(cons pattern bt(migemo-get-pattern pattern))))
(string-match (cdr helm-mm--previous-migemo-info) str))

(cl-defun helm-mm-3-migemo-match (str &optional (pattern helm-pattern))
(and helm-migemo-mode
(cl-loop for (pred . re) in (helm-mm-3-get-patterns pattern)
always (funcall pred (helm-mm-migemo-string-match str re)))))
always (funcall pred (helm-mm-migemo-string-match re str)))))

(defun helm-mm-3-migemo-search (pattern &rest _ignore)
(and helm-migemo-mode
Expand Down
3 changes: 2 additions & 1 deletion helm-types.el
Expand Up @@ -107,7 +107,8 @@
(defmethod helm--setup-source :before ((source helm-type-bookmark))
(set-slot-value source 'action 'helm-type-bookmark-actions)
(set-slot-value source 'keymap helm-bookmark-map)
(set-slot-value source 'help-message 'helm-bookmark-help-message))
(set-slot-value source 'help-message 'helm-bookmark-help-message)
(set-slot-value source 'migemo t))


;; Buffers
Expand Down
28 changes: 17 additions & 11 deletions helm.el
Expand Up @@ -4595,14 +4595,17 @@ To customize `helm-candidates-in-buffer' behavior, use `search',
(list (point-at-bol) (point-at-eol))))
when (and (not (gethash cand helm-cib-hash))
(or
;; Always collect when cand is matched by searcher funcs
;; and match-part attr is not present.
;; Always collect when cand is matched
;; by searcher funcs and match-part attr
;; is not present.
(and (not match-part-fn)
(not (consp pos-lst)))
;; If match-part attr is present, or if SEARCHER fn
;; returns a cons cell, collect PATTERN only if it
;; match the part of CAND specified by the match-part func.
(helm-search-match-part cand pattern (or match-part-fn #'identity))))
;; match the part of CAND specified by
;; the match-part func.
(helm-search-match-part
cand pattern (or match-part-fn #'identity))))
do (helm--accumulate-candidates
cand newmatches helm-cib-hash item-count limit source))
(setq matches (append matches (nreverse newmatches))))
Expand All @@ -4611,24 +4614,27 @@ To customize `helm-candidates-in-buffer' behavior, use `search',
(defun helm-search-match-part (candidate pattern match-part-fn)
"Match PATTERN only on part of CANDIDATE returned by MATCH-PART-FN.
Because `helm-search-match-part' maybe called even if unspecified
in source (negation), MATCH-PART-FN default to `identity' to match whole candidate.
When using fuzzy matching and negation (i.e \"!\"), this function is always called."
in source (negation), MATCH-PART-FN default to `identity'
to match whole candidate.
When using fuzzy matching and negation (i.e \"!\"),
this function is always called."
(let ((part (funcall match-part-fn candidate))
(fuzzy-regexp (cadr (gethash 'helm-pattern helm--fuzzy-regexp-cache))))
(fuzzy-regexp (cadr (gethash 'helm-pattern helm--fuzzy-regexp-cache)))
(matchfn (if helm-migemo-mode
'helm-mm-migemo-string-match 'string-match)))
(if (string-match " " pattern)
(cl-loop for i in (split-string pattern) always
(if (string-match "\\`!" i)
(not (string-match (substring i 1) part))
(string-match i part)))
(not (funcall matchfn (substring i 1) part))
(funcall matchfn i part)))
(if (string-match "\\`!" pattern)
(not (string-match (if helm--in-fuzzy
;; Fuzzy regexp have already been
;; computed with substring 1.
fuzzy-regexp
(substring 1 pattern))
part))
(string-match (if helm--in-fuzzy fuzzy-regexp pattern)
part)))))
(funcall matchfn (if helm--in-fuzzy fuzzy-regexp pattern) part)))))

(defun helm-initial-candidates-from-candidate-buffer (get-line-fn limit)
(delq nil (cl-loop for i from 1 to limit
Expand Down

0 comments on commit 3d20b06

Please sign in to comment.