Skip to content

Commit 882e0b7

Browse files
committed
Improve getting helm pattern.
1 parent 566256e commit 882e0b7

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

helm-fuzzy.el

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,33 @@
4949
:group 'helm-fuzzy)
5050

5151

52+
53+
(defun helm-fuzzy--flatten-list (l)
54+
"Flatten the multiple dimensional array, L to one dimensonal array."
55+
(cond ((null l) nil)
56+
((atom l) (list l))
57+
(t (loop for a in l appending (helm-fuzzy--flatten-list a)))))
58+
59+
(defun helm-fuzzy--get-faces (pos)
60+
"Get the font faces at POS."
61+
(helm-fuzzy--flatten-list
62+
(remq nil
63+
(list
64+
(get-char-property pos 'read-face-name)
65+
(get-char-property pos 'face)
66+
(plist-get (text-properties-at pos) 'face)))))
67+
68+
(defun helm-fuzzy--is-current-point-face (in-face)
69+
"Check if current face the same face as IN-FACE."
70+
(let ((faces (helm-fuzzy--get-faces (point))))
71+
(if (listp faces)
72+
(if (equal (cl-position in-face faces :test 'string=) nil)
73+
;; If return nil, mean not found in the `faces' list.
74+
nil
75+
;; If have position, meaning the face exists.
76+
t)
77+
(string= in-face faces))))
78+
5279
(defun helm-fuzzy--is-contain-list-string (in-list in-str)
5380
"Check if a string IN-STR contain in any string in the string list IN-LIST."
5481
(cl-some #'(lambda (lb-sub-str) (string-match-p (regexp-quote lb-sub-str) in-str)) in-list))
@@ -62,7 +89,13 @@
6289
(save-selected-window
6390
(select-window (active-minibuffer-window))
6491
(setq pattern (buffer-string))
65-
(setq pos (string-match-p helm-pattern pattern))
92+
(save-excursion
93+
(goto-char (point-min))
94+
(while (and (< (point) (length pattern))
95+
(= pos -1))
96+
(forward-char 1)
97+
(unless (helm-fuzzy--is-current-point-face "helm-minibuffer-prompt")
98+
(setq pos (1- (point))))))
6699
(setq pattern (substring pattern pos (length pattern)))))
67100
pattern))
68101

0 commit comments

Comments
 (0)