branch: elpa/helm
commit 724c2cc586fc5a40893edf64c1a79a3189ecb941
Author: Thierry Volpiatto <[email protected]>
Commit: Thierry Volpiatto <[email protected]>
Add a text prop 'icon to icons #2743
This allows knowing if the leading string is an icon or not when
extracting the display part in helm-get-selection with 'noicon as
FORCE-DISPLAY-PART arg.
---
helm-core.el | 5 +++--
helm-x-icons.el | 16 +++++++++++-----
2 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/helm-core.el b/helm-core.el
index 9d01e478067..5dd33dacdfe 100644
--- a/helm-core.el
+++ b/helm-core.el
@@ -2524,7 +2524,7 @@ when you want the `display-to-real' function(s) to be
applied."
(helm-pos-header-line-p))
(let* ((beg (overlay-start helm-selection-overlay))
(end (overlay-end helm-selection-overlay))
- (disp-fn (if (eq force-display-part 'withprop)
+ (disp-fn (if (memq force-display-part '(withprop noicon))
'buffer-substring
'buffer-substring-no-properties))
;; If there is no selection at point, the
@@ -2535,7 +2535,8 @@ when you want the `display-to-real' function(s) to be
applied."
;; error message in helm-buffer when no matches.
(disp (unless (= beg end)
(helm-acase (funcall disp-fn beg (1- end))
- ((guard* (eq force-display-part 'noicon))
+ ((guard* (and (eq force-display-part 'noicon)
+ (get-text-property 0 'icon it)))
;; Remove icon if some from display see issue#2743.
(replace-regexp-in-string
"^[[:multibyte:]][ \t]+" "" it))
diff --git a/helm-x-icons.el b/helm-x-icons.el
index bc361b3b093..354ba55aef5 100644
--- a/helm-x-icons.el
+++ b/helm-x-icons.el
@@ -61,8 +61,12 @@ The returned alist is computed according to
`helm-x-icons-provider'."
"Compatibility function for `*-icon-for-file'."
(let ((fn (helm-acase helm-x-icons-provider
(all-the-icons 'all-the-icons-icon-for-file)
- (nerd-icons 'nerd-icons-icon-for-file))))
- (when fn (apply fn args))))
+ (nerd-icons 'nerd-icons-icon-for-file)))
+ icon)
+ (when fn
+ (setq icon (apply fn args))
+ (add-text-properties 0 1 '(icon t) icon)
+ icon)))
(defvar helm-x-icons-nerd-icons-compat-alist
'(("file-symlink-directory" . (nerd-icons-codicon .
"nf-cod-file_symlink_directory"))
@@ -144,7 +148,7 @@ Run an `all-the-icons' or `nerd-icons' function according to
`helm-x-icons-provider'and ICON-NAME.
Functions and icon names are found in `helm-x-icons-all-the-icons-compat-alist'
and `helm-x-icons-nerd-icons-compat-alist'."
- (let (fn)
+ (let (fn icon)
(helm-acase helm-x-icons-provider
(nerd-icons
(helm-acase (assoc-default icon-name
helm-x-icons-nerd-icons-compat-alist)
@@ -154,8 +158,10 @@ and `helm-x-icons-nerd-icons-compat-alist'."
(helm-acase (assoc-default icon-name
helm-x-icons-all-the-icons-compat-alist)
((dst* (sym . name))
(setq fn sym icon-name name)))))
- (when fn (apply fn icon-name args))))
-
+ (when fn
+ (setq icon (apply fn icon-name args))
+ (add-text-properties 0 1 '(icon t) icon)
+ icon)))
(provide 'helm-x-icons)