Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helm-Icons: Add central file to manage icon support #2701

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 42 additions & 37 deletions helm-bookmark.el
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
(require 'bookmark)
(require 'helm)
(require 'helm-lib)
(require 'helm-icons)
(require 'helm-help)
(require 'helm-types)
(require 'helm-utils)
Expand All @@ -29,14 +30,8 @@

(declare-function helm-browse-project "helm-files" (arg))
(declare-function addressbook-bookmark-edit "ext:addressbook-bookmark.el" (bookmark))
(declare-function all-the-icons-fileicon "ext:all-the-icons.el")
(declare-function all-the-icons-icon-for-file"ext:all-the-icons.el")
(declare-function all-the-icons-octicon "ext:all-the-icons.el")
(declare-function all-the-icons-match-to-alist "ext:all-the-icons.el")
(declare-function all-the-icons-faicon "ext:all-the-icons.el")
(declare-function eww-read-bookmarks "eww")

(defvar all-the-icons-dir-icon-alist)
(defvar eww-bookmarks)


Expand All @@ -63,14 +58,9 @@
"List of sources to use in `helm-filtered-bookmarks'."
:type '(repeat (choice symbol)))

(defcustom helm-bookmark-use-icon nil
"Display candidates with an icon with `all-the-icons' when non nil.
Don't use `setq' to set this."
:type 'boolean
:set (lambda (var val)
(if (require 'all-the-icons nil t)
(set var val)
(set var nil))))
(defcustom helm-bookmark-use-icon t
"Display candidates with an icon with `helm-icons-provider' when non nil."
:type 'boolean)

(defcustom helm-bookmark-default-sort-method 'adaptive
"Sort method for `helm-filtered-bookmarks'.
Expand Down Expand Up @@ -175,7 +165,7 @@ will be honored."
(mapcar 'bookmark-name-from-full-record
(bookmark-maybe-sort-alist))
(bookmark-all-names)))))
(filtered-candidate-transformer :initform 'helm-bookmark-transformer)
(filtered-candidate-transformer :initform 'helm-highlight-bookmark)
(find-file-target :initform #'helm-bookmarks-quit-an-find-file-fn)))

(defvar helm-source-bookmarks
Expand Down Expand Up @@ -241,7 +231,10 @@ will be honored."
(lambda (_candidates _source)
(list (or (and (not (string= helm-pattern ""))
helm-pattern)
"Enter a bookmark name to record")))
(concat (if helm-bookmark-use-icon
(concat (helm-icons-action-icon 'new-file)
" "))
"Enter a bookmark name to record"))))
:action '(("Set bookmark" . (lambda (candidate)
(if (string= helm-pattern "")
(message "No bookmark name given for record")
Expand Down Expand Up @@ -644,20 +637,27 @@ If `browse-url-browser-function' is set to something else than
for handlerp = (and (fboundp 'bookmark-get-handler)
(bookmark-get-handler i))
for isw3m = (and (fboundp 'helm-bookmark-w3m-bookmark-p)
(helm-bookmark-w3m-bookmark-p i))
(helm-bookmark-w3m-bookmark-p i)
'w3m-mode)
for isgnus = (and (fboundp 'helm-bookmark-gnus-bookmark-p)
(helm-bookmark-gnus-bookmark-p i))
(helm-bookmark-gnus-bookmark-p i)
'gnus-article-mode)
for ismu4e = (and (fboundp 'helm-bookmark-mu4e-bookmark-p)
(helm-bookmark-mu4e-bookmark-p i))
(helm-bookmark-mu4e-bookmark-p i)
'mu4e-view-mode)
for isman = (and (fboundp 'helm-bookmark-man-bookmark-p) ; Man
(helm-bookmark-man-bookmark-p i))
(helm-bookmark-man-bookmark-p i)
'man-common)
for iswoman = (and (fboundp 'helm-bookmark-woman-bookmark-p) ; Woman
(helm-bookmark-woman-bookmark-p i))
(helm-bookmark-woman-bookmark-p i)
'man-common)
for isannotation = (bookmark-get-annotation i)
for isabook = (string= (bookmark-prop-get i 'type)
"addressbook")
for isinfo = (eq handlerp 'Info-bookmark-jump)
for iseww = (eq handlerp 'eww-bookmark-jump)
for iseww = (and (eq handlerp 'eww-bookmark-jump)
'eww-mode)
for isinfo = (and (eq handlerp 'Info-bookmark-jump)
'Info-mode)
for loc = (bookmark-location i)
for len = (string-width i)
for trunc = (if (and helm-bookmark-show-location
Expand All @@ -667,22 +667,27 @@ If `browse-url-browser-function' is set to something else than
i)
for icon = (when helm-bookmark-use-icon
(cond ((and isfile hff)
(helm-aif (or (all-the-icons-match-to-alist
(helm-basename (helm-basedir isfile t))
all-the-icons-dir-icon-alist)
(all-the-icons-match-to-alist
(helm-basename isfile)
all-the-icons-dir-icon-alist))
(apply (car it) (cdr it))
(all-the-icons-octicon "file-directory")))
((or isw3m iseww)
(all-the-icons-faicon "firefox"))
((and isfile isinfo) (all-the-icons-octicon "info"))
;; (helm-aif (or (all-the-icons-match-to-alist
;; (helm-basename (helm-basedir isfile t))
;; all-the-icons-dir-icon-alist)
;; (all-the-icons-match-to-alist
;; (helm-basename isfile)
;; all-the-icons-dir-icon-alist))
;; (apply (car it) (cdr it))
;; (all-the-icons-octicon "file-directory")))
;; ((or isw3m iseww)
;; (all-the-icons-faicon "firefox"))
;; ((and isfile isinfo) (all-the-icons-octicon "info"))
(helm-icons-directory-icon isfile))
(isw3m (helm-icons-mode-icon isw3m))
(iseww (helm-icons-mode-icon iseww))
((and isfile isinfo) (helm-icons-mode-icon isinfo))
((or iswoman isman)
(all-the-icons-fileicon "man-page"))
(helm-icons-mode-icon isman))
((or isgnus ismu4e)
(all-the-icons-octicon "mail-read"))
(isfile (all-the-icons-icon-for-file (helm-basename isfile)))))
(helm-icons-mode-icon (or isgnus
ismu4e)))
(isfile (helm-icons-file-icon (helm-basename isfile)))))
;; Add a * if bookmark have annotation
if (and isannotation (not (string-equal isannotation "")))
do (setq trunc (concat helm-bookmark-annotation-sign
Expand Down
29 changes: 11 additions & 18 deletions helm-buffers.el
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
(require 'helm)
(require 'helm-types)
(require 'helm-utils)
(require 'helm-icons)
(require 'helm-grep)
(require 'helm-regexp)
(require 'helm-help)
Expand All @@ -29,10 +30,9 @@
(declare-function helm-comp-read "helm-mode")
(declare-function helm-browse-project "helm-files")
(declare-function helm-ff-switch-to-shell "helm-files")
(declare-function all-the-icons-icon-for-file "ext:all-the-icons.el")
(declare-function all-the-icons-octicon "ext:all-the-icons.el")

(defvar all-the-icons-mode-icon-alist)

(defvar helm-icons-provider)
(defvar dired-buffers)
(defvar org-directory)
(defvar helm-ff-default-directory)
Expand Down Expand Up @@ -173,14 +173,9 @@ Default to `helm-fuzzy-sort-fn' you can use
you want to keep the recentest order when narrowing candidates."
:type 'function)

(defcustom helm-buffers-show-icons nil
"Prefix buffer names with an icon when non nil.
Don't use `setq' to set this."
:type 'boolean
:set (lambda (var val)
(if (require 'all-the-icons nil t)
(set var val)
(set var nil))))
(defcustom helm-buffers-show-icons t
"Prefix buffer names with an icon when non nil."
:type 'boolean)


;;; Faces
Expand Down Expand Up @@ -460,13 +455,11 @@ The list is reordered with `helm-buffer-list-reorder-fn'."
(ext (if buf-fname (helm-file-name-extension buf-fname) ""))
(bmode (with-current-buffer buf-name major-mode))
(icon (when helm-buffers-show-icons
(helm-aif (assq bmode all-the-icons-mode-icon-alist)
(apply (cadr it) (cddr it))
(cond ((eq type 'dired)
(all-the-icons-octicon "file-directory"))
(buf-fname
(all-the-icons-icon-for-file buf-name))
(t (all-the-icons-octicon "star" :v-adjust 0.0))))))
(cond ((eq type 'dired)
(helm-icons-mode-icon 'dired-mode))
(buf-fname
(helm-icons-file-icon buf-name))
(t (helm-icons-mode-icon bmode)))))
(buf-name (propertize buf-name 'face face1
'help-echo help-echo
'type type)))
Expand Down
51 changes: 15 additions & 36 deletions helm-files.el
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
(require 'helm-locate)
(require 'helm-tags)
(require 'helm-buffers)
(require 'helm-icons)
(require 'tramp)
(eval-when-compile
(require 'thingatpt)
Expand Down Expand Up @@ -87,16 +88,11 @@
(declare-function dired-async-processes "ext:dired-async.el")
(declare-function dired-async-mode-line-message "ext:dired-async.el")
(declare-function dired-async--modeline-mode "ext:dired-async.el")
(declare-function all-the-icons-icon-for-file "ext:all-the-icons.el")
(declare-function all-the-icons-octicon "ext:all-the-icons.el")
(declare-function all-the-icons-match-to-alist "ext:all-the-icons.el")
(declare-function all-the-icons-material "ext:all-the-icons.el")
(declare-function helm-adaptive-sort "ext:helm-adaptive.el")
(declare-function wfnames-setup-buffer "ext:wfnames.el")
(declare-function svg-lib-progress-bar "ext:svg-lib")
(declare-function svg-lib-tag "ext:svg-lib")

(defvar all-the-icons-dir-icon-alist)
(defvar term-char-mode-point-at-process-mark)
(defvar term-char-mode-buffer-read-only)
(defvar recentf-list)
Expand Down Expand Up @@ -4142,8 +4138,8 @@ returned prefixed with its icon or unchanged."
(if helm-ff-icon-mode
(helm-acase (match-string 1 disp)
("mailto:"
(all-the-icons-octicon "mail"))
(t (all-the-icons-octicon "link-external")))
(helm-icons-octicon-icon "mail"))
(t (helm-icons-octicon-icon "link-external")))
(propertize
" " 'display
(propertize "[@]" 'face 'helm-ff-prefix))))
Expand All @@ -4153,8 +4149,8 @@ returned prefixed with its icon or unchanged."
(setq prefix-new
(if helm-ff-icon-mode
(if (string-match "/\\'" disp)
(all-the-icons-material "create_new_folder")
(all-the-icons-material "note_add"))
(helm-icons-action-icon 'new-folder)
(helm-icons-action-icon 'new-file))
(propertize
" " 'display
(propertize "[+]" 'face 'helm-ff-prefix))))
Expand Down Expand Up @@ -4427,29 +4423,17 @@ If SKIP-BORING-CHECK is non nil don't filter boring files."
file))))))))

(defun helm-ff-get-icon (disp file)
"Get icon from all-the-icons for FILE.
"Get icon from `helm-icons-provider' for FILE.
Arg DISP is the display part of the candidate.
Arg FILE is the real part of candidate, a filename with no props."
(when helm-ff-icon-mode
(let ((icon (helm-acond (;; Non symlink directories.
(helm-ff--is-dir-from-disp disp)
(helm-aif (all-the-icons-match-to-alist
(helm-basename file)
all-the-icons-dir-icon-alist)
(apply (car it) (cdr it))
(all-the-icons-octicon "file-directory")))
(;; All files, symlinks may be symlink directories.
(helm-ff--is-file-from-disp disp)
;; Detect symlink directories. We must call
;; `file-directory-p' here but it is
;; limited to symlinks, so it should not
;; degrade too much performances.
(if (and (memq it '(helm-ff-symlink
helm-ff-dotted-symlink-directory))
(file-directory-p file))
(all-the-icons-octicon "file-symlink-directory")
(all-the-icons-icon-for-file (helm-basename file)))))))
(when icon (concat icon " ")))))
(when-let* ((icon (cond ((helm-ff--is-dir-from-disp disp)
(helm-icons-directory-icon (helm-basename file)))
((helm-ff--is-file-from-disp disp)
(helm-icons-file-icon (helm-basename file))))))
(concat icon " "))))



(defun helm-ff--is-dir-from-disp (disp)
"Return the face used for candidate when candidate is a directory."
Expand All @@ -4476,10 +4460,6 @@ Arg FILE is the real part of candidate, a filename with no props."
"Display icons from `all-the-icons' package in HFF when enabled."
:global t
:group 'helm-files
(when helm-ff-icon-mode
(unless (require 'all-the-icons nil t)
(setq helm-ff-icon-mode nil)
(message "All The Icons package is not installed")))
(clrhash helm-ff--list-directory-cache))

(defun helm-find-files-action-transformer (actions candidate)
Expand Down Expand Up @@ -6710,10 +6690,9 @@ be existing directories."
(propertize c 'face 'helm-history-deleted))))
when disp
collect (cons (if helm-ff-icon-mode
(concat (all-the-icons-icon-for-file
(concat (helm-icons-file-icon
(helm-basename elm))
" " disp)
disp)
" " disp) disp)
elm)))

(defun helm-ff-file-name-history-ff (candidate)
Expand Down
36 changes: 22 additions & 14 deletions helm-for-files.el
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,30 @@ Colorize only symlinks, directories and files."
collect
(cond ((and (null type) isremote) (cons disp i))
((stringp type)
(cons (propertize disp
'face 'helm-ff-symlink
'match-part (funcall mp-fn disp)
'help-echo (expand-file-name i))
i))
(cons (concat
(cond (helm-ff-icon-mode
(concat (helm-icons-file-icon i) " ")))
(propertize disp
'face 'helm-ff-symlink
'match-part (funcall mp-fn disp)
'help-echo (expand-file-name i))) i))
((eq type t)
(cons (propertize disp
'face 'helm-ff-directory
'match-part (funcall mp-fn disp)
'help-echo (expand-file-name i))
i))
(cons (concat
(cond (helm-ff-icon-mode
(concat (helm-icons-directory-icon i) " ")))
(propertize disp
'face 'helm-ff-directory
'match-part (funcall mp-fn disp)
'help-echo (expand-file-name i))) i))
(t (let* ((ext (helm-file-name-extension disp))
(disp (propertize disp
'face 'helm-ff-file
'match-part (funcall mp-fn disp)
'help-echo (expand-file-name i))))
(disp (concat
(cond (helm-ff-icon-mode
(concat (helm-icons-file-icon i)
" ")))
(propertize disp
'face 'helm-ff-file
'match-part (funcall mp-fn disp)
'help-echo (expand-file-name i)))))
(when (condition-case _err
(string-match (format "\\.\\(%s\\)$" ext) disp)
(invalid-regexp nil))
Expand Down
2 changes: 1 addition & 1 deletion helm-help.el
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ you will have to refresh manually directories when needed with `\\<helm-map>\\[h

*** Prefix file candidates with icons

If `all-the-icons' package is installed, turning on
If `helm-icons-provider' package is installed, turning on
`helm-ff-icon-mode' will show icons before files and directories.

** Commands
Expand Down
Loading