Skip to content

Commit

Permalink
Allow using add-face-text-property.
Browse files Browse the repository at this point in the history
* helm-lib.el (helm-add-face-text-properties): New
* helm-grep.el (helm-grep-highlight-match):     Use it.
* helm.el (helm-fuzzy-default-highlight-match): Use it.
  • Loading branch information
Thierry Volpiatto committed Jun 12, 2016
1 parent a383aea commit 9ff4abf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion helm-grep.el
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ in recurse, and ignore EXTS, search being made recursively on files matching
(while (and (re-search-forward reg nil t)
(> (- (setq end (match-end 0))
(setq beg (match-beginning 0))) 0))
(add-text-properties beg end '(face helm-grep-match)))
(helm-add-face-text-properties beg end 'helm-grep-match))
do (goto-char (point-min)))
(buffer-string))
(error nil))))
Expand Down
12 changes: 12 additions & 0 deletions helm-lib.el
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ much more convenient to use a simple boolean value here."
(defvar helm-suspend-update-flag nil)
(defvar helm-action-buffer "*helm action*"
"Buffer showing actions.")


;;; Compatibility
;;
(defun helm-add-face-text-properties (beg end face &optional append object)
"Add the face property to the text from START to END.
It is a compatibility function which behave exactly like
`add-face-text-property' is available otherwise like `add-text-properties'.
When only `add-text-properties' is available APPEND is ignored."
(if (fboundp 'add-face-text-property)
(add-face-text-property beg end face append object)
(add-text-properties beg end `(face ,face) object)))

;;; Macros helper.
;;
Expand Down
12 changes: 6 additions & 6 deletions helm.el
Original file line number Diff line number Diff line change
Expand Up @@ -3083,8 +3083,8 @@ to the matching method in use."
;; Try first matching against whole pattern.
(while (re-search-forward regex nil t)
(cl-incf count)
(add-text-properties
(match-beginning 0) (match-end 0) '(face helm-match)))
(helm-add-face-text-properties
(match-beginning 0) (match-end 0) 'helm-match))
;; If no matches start matching against multiples or fuzzy matches.
(when (zerop count)
(cl-loop with multi-match = (string-match-p " " helm-pattern)
Expand All @@ -3097,16 +3097,16 @@ to the matching method in use."
if multi-match do
(progn
(while (re-search-forward p nil t)
(add-text-properties
(helm-add-face-text-properties
(match-beginning 0) (match-end 0)
'(face helm-match)))
'helm-match))
(goto-char (point-min)))
;; Fuzzy matches (literal patterns).
else do
(when (search-forward p nil t)
(add-text-properties
(helm-add-face-text-properties
(match-beginning 0) (match-end 0)
'(face helm-match))))))
'helm-match)))))
(invalid-regexp nil))
;; Now replace the original match-part with the part
;; with face properties added.
Expand Down

0 comments on commit 9ff4abf

Please sign in to comment.