-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: add all-the-icons support #5
Changes from all commits
47661bc
0086005
7a21d1f
49e62a2
d2fae0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -26,14 +26,14 @@ | |||||||||
|
||||||||||
;; Places icons next to file entries in Magit buffers based on file extension. | ||||||||||
;; This is intended to improve visual clarity and ease of gleaning information. | ||||||||||
;; Currently, only the `nerd-icons' backend is supported. | ||||||||||
;; Currently, the `nerd-icons' backend is the default, but it will fallback | ||||||||||
;; to `all-the-icons' if nerd-icons is not found. | ||||||||||
|
||||||||||
;;; Code: | ||||||||||
|
||||||||||
(require 'el-patch) | ||||||||||
(require 'el-patch-template) | ||||||||||
(require 'magit) | ||||||||||
(require 'nerd-icons) | ||||||||||
|
||||||||||
(defgroup magit-file-icons nil | ||||||||||
"Show file icons in Magit buffers." | ||||||||||
|
@@ -55,12 +55,52 @@ | |||||||||
:type 'boolean | ||||||||||
:group 'magit-file-icons) | ||||||||||
|
||||||||||
(defcustom magit-file-icons-icon-backend 'nerd-icons | ||||||||||
"Icon backend for magit-file-icons. Set this to nil | ||||||||||
if you want to customize `magit-file-icons-icon-for-file-func' | ||||||||||
or `magit-file-icons-icon-for-dir-func'." | ||||||||||
:type 'symbol | ||||||||||
:group 'magit-file-icons) | ||||||||||
|
||||||||||
(if (not (require 'nerd-icons nil t)) (funcall | ||||||||||
(lambda () | ||||||||||
(require 'all-the-icons) | ||||||||||
(setq magit-file-icons-icon-backend 'all-the-icons)))) | ||||||||||
|
||||||||||
(defcustom magit-file-icons-icon-for-file-func nil | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use |
||||||||||
"Icon for file function. Automatically set if | ||||||||||
`magit-file-icons-icon-backend' is non-nil. | ||||||||||
Customize using (fset 'magit-file-icons-icon-for-file-func 'custom-function)." | ||||||||||
:type 'symbol | ||||||||||
:group 'magit-file-icons) | ||||||||||
|
||||||||||
(defcustom magit-file-icons-icon-for-dir-func nil | ||||||||||
"Icon for directory function. Automatically set if | ||||||||||
`magit-file-icons-icon-backend' is non-nil. | ||||||||||
Customize using (fset 'magit-file-icons-icon-for-file-func 'custom-function)." | ||||||||||
:type 'symbol | ||||||||||
:group 'magit-file-icons) | ||||||||||
|
||||||||||
(defun magit-file-icons-refresh-backend () | ||||||||||
"Refresh backend according to `magit-file-icons-icon-backend'. | ||||||||||
Does not refresh if `magit-file-icons-icon-backend' is nil." | ||||||||||
(if magit-file-icons-icon-backend | ||||||||||
(if (eq magit-file-icons-icon-backend 'nerd-icons) | ||||||||||
(funcall (lambda () | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't mutate customizable variables - these are only meant to be touched by the user. Instead, define an internal variable and derive its initial state from any values for custom variables set by the user. |
||||||||||
(fset 'magit-file-icons-icon-for-file-func 'nerd-icons-icon-for-file) | ||||||||||
(fset 'magit-file-icons-icon-for-dir-func 'nerd-icons-icon-for-dir))) | ||||||||||
(funcall (lambda () | ||||||||||
(fset 'magit-file-icons-icon-for-file-func 'all-the-icons-icon-for-file) | ||||||||||
(fset 'magit-file-icons-icon-for-dir-func 'all-the-icons-icon-for-dir)))))) | ||||||||||
|
||||||||||
(magit-file-icons-refresh-backend) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can get rid of this line if we call the refresh function in the minor-mode anyway
Suggested change
|
||||||||||
|
||||||||||
(el-patch-define-template | ||||||||||
(defun magit-diff-insert-file-section) | ||||||||||
(format (el-patch-swap "%-10s %s" "%-10s %s %s") status (el-patch-add (nerd-icons-icon-for-file (or orig file))) | ||||||||||
(format (el-patch-swap "%-10s %s" "%-10s %s %s") status (el-patch-add (magit-file-icons-icon-for-file-func (or orig file))) | ||||||||||
(if (or (not orig) (equal orig file)) | ||||||||||
file | ||||||||||
(format (el-patch-swap "%s -> %s" "%s -> %s %s") orig (el-patch-add (nerd-icons-icon-for-file file)) file)))) | ||||||||||
(format (el-patch-swap "%s -> %s" "%s -> %s %s") orig (el-patch-add (magit-file-icons-icon-for-file-func file)) file)))) | ||||||||||
|
||||||||||
(el-patch-define-template | ||||||||||
(defun magit-insert-untracked-files) | ||||||||||
|
@@ -69,15 +109,15 @@ | |||||||||
(el-patch-swap file | ||||||||||
(format "%s %s" | ||||||||||
(if (file-directory-p file) | ||||||||||
(nerd-icons-icon-for-dir file) | ||||||||||
(nerd-icons-icon-for-file file)) | ||||||||||
(magit-file-icons-icon-for-dir-func file) | ||||||||||
(magit-file-icons-icon-for-file-func file)) | ||||||||||
file)) | ||||||||||
'font-lock-face 'magit-filename) | ||||||||||
?\n)) | ||||||||||
|
||||||||||
(el-patch-define-template | ||||||||||
(defun magit-diff-wash-diffstat) | ||||||||||
(insert (propertize (el-patch-swap file (format "%s %s" (nerd-icons-icon-for-file file) file)) 'font-lock-face 'magit-filename) | ||||||||||
(insert (propertize (el-patch-swap file (format "%s %s" (magit-file-icons-icon-for-file-func file) file)) 'font-lock-face 'magit-filename) | ||||||||||
sep cnt " ")) | ||||||||||
|
||||||||||
;;;###autoload | ||||||||||
|
@@ -88,11 +128,17 @@ | |||||||||
(magit-file-icons-mode | ||||||||||
(when magit-file-icons-enable-diff-file-section-icons (el-patch-eval-template #'magit-diff-insert-file-section 'defun)) | ||||||||||
(when magit-file-icons-enable-untracked-icons (el-patch-eval-template #'magit-insert-untracked-files 'defun)) | ||||||||||
(when magit-file-icons-enable-diffstat-icons (el-patch-eval-template #'magit-diff-wash-diffstat 'defun))) | ||||||||||
(when magit-file-icons-enable-diffstat-icons (el-patch-eval-template #'magit-diff-wash-diffstat 'defun)) | ||||||||||
(when magit-file-icons-enable-diff-file-section-icons (magit-file-icons-refresh-backend)) | ||||||||||
(when magit-file-icons-enable-untracked-icons (magit-file-icons-refresh-backend)) | ||||||||||
(when magit-file-icons-enable-diffstat-icons (magit-file-icons-refresh-backend))) | ||||||||||
Comment on lines
+132
to
+134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's better to combine these into an
Suggested change
|
||||||||||
(add-hook 'magit-mode-hook 'magit-file-icons-refresh-backend) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can get rid of these hooks - it's probably sufficient to refresh on minor mode activation. |
||||||||||
('deactivate | ||||||||||
(el-patch-unpatch #'magit-diff-insert-file-section 'defun nil) | ||||||||||
(el-patch-unpatch #'magit-insert-untracked-files 'defun nil) | ||||||||||
(el-patch-unpatch #'magit-diff-wash-diffstat 'defun nil)))) | ||||||||||
(el-patch-unpatch #'magit-diff-wash-diffstat 'defun nil))) | ||||||||||
(remove-hook 'magit-mode-hook 'magit-file-icons-refresh-backend)) | ||||||||||
|
||||||||||
|
||||||||||
(provide 'magit-file-icons) | ||||||||||
|
||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this check is necessary if we have
nerd-icons
in thePackage-Requires
clause