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

Add a customize variable for lighter #57

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
8e8fcc9
make icons use same color as the text
wyuenho Mar 28, 2020
9d568c1
Refresh icons after directory creation
gexplorer Nov 26, 2020
ea89557
Refresh icons after rename
gexplorer Nov 26, 2020
785cf50
Display icons in find-dired output
eigengrau Jan 9, 2021
25396c3
Merge remote-tracking branch 'gexplorer/master'
wyuenho Feb 11, 2021
de07052
Merge remote-tracking branch 'eigengrau/master'
wyuenho Feb 11, 2021
c95dfd9
Remove check to detect display
wyuenho Feb 11, 2021
2123f78
Refactor advices
wyuenho Feb 11, 2021
dd68516
Fork notice
wyuenho Feb 27, 2021
6d43406
kill-local-variable takes symbol causing deactivating of all-the-icon…
lordpretzel Mar 2, 2021
f401fe2
Merge pull request #2 from lordpretzel/master
wyuenho Mar 2, 2021
0b929d2
Update URL and copyright notice
wyuenho Apr 8, 2021
07f035d
Fix #3 ensure case-fold-search under dired
wyuenho Apr 11, 2021
5408e17
Update issue templates
wyuenho Apr 12, 2021
dd7dd27
Add note on how to get backtrace
wyuenho Apr 12, 2021
82d09a3
Fix void var file error
wyuenho Apr 16, 2021
65e15ec
Refresh icons when aborting wdired
jacobilsoe Apr 21, 2021
f0bad10
Fixed typo
jacobilsoe Apr 21, 2021
a294f45
Merge pull request #5 from jacobilsoe/refresh-on-wdired-abort
wyuenho Apr 22, 2021
a758766
Version 2.0
wyuenho Jun 14, 2021
42d8d28
Add support for `dired-subtree`
nagy Jul 31, 2021
7c42693
Refresh on dired-kill-subdir
pkulev Oct 1, 2021
9eb119e
Merge pull request #7 from nagy/dired-subtree
wyuenho Oct 1, 2021
8374033
Merge pull request #8 from pkulev/refresh-on-dired-kill-subdir
wyuenho Oct 7, 2021
46ca704
Return result of adviced functions
wyuenho Oct 7, 2021
5e9b097
Use prog1
wyuenho Oct 7, 2021
de9b14c
Fix #10 put icon before file name during redisplay
wyuenho Mar 4, 2022
147ed0d
Fix #14 dired-do-redisplay is in dired-aux
wyuenho Mar 4, 2022
ed9d34f
Use text properties instead of overlays
Jun 2, 2022
0dfb59f
Only add icons after `dired-subdir-alist` is set
Jun 20, 2022
37578ab
Fix docstring
wyuenho Jun 20, 2022
b5d3af1
Merge pull request #17 from aikrahguzar/master
wyuenho Jun 20, 2022
385fcbc
Experimental SVG icon support
wyuenho Sep 4, 2022
8adb5fa
use font lock to set icons
wyuenho Sep 29, 2022
78096c2
Refontify after setup and teardown
wyuenho Sep 29, 2022
ef84300
fix docstrings
wyuenho Sep 29, 2022
bcaed35
add requires
wyuenho Sep 29, 2022
4564bec
add cask file
wyuenho Sep 29, 2022
4b8ed87
Add a customize variable for lighter
Jan 3, 2023
c8fedda
Merge branch 'master' into customize-lighter
Jan 12, 2023
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
30 changes: 30 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is. Set `debug-on-error` to `t` to capture a backtrace.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**System**
If you think this is important, please also tell me about which version and which port of emacs you are running.

**Additional context**
Add any other context about the problem here.
4 changes: 4 additions & 0 deletions Cask
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(source gnu)
(source melpa)

(package-file "all-the-icons-dired.el")
3 changes: 3 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#+TITLE: all-the-icons-dired
#+AUTHOR: jtbm37
#+DATE: 2016-11-08
** Note
Since 2021-02-21, this is now the fork the =all-the-icons-dired= Melpa recipe points to. Changes can be seen [[https://github.com/jtbm37/all-the-icons-dired/compare/master...wyuenho:master][here]].

[[file:logo.png]]

This adds dired support to [[https://github.com/domtronn/all-the-icons.el][all-the-icons]].
Expand Down
161 changes: 84 additions & 77 deletions all-the-icons-dired.el
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
;;; all-the-icons-dired.el --- Shows icons for each file in dired mode -*- lexical-binding: t; -*-

;; Copyright (C) 2016 jtbm37
;; Copyright (C) 2016-2020 jtbm37
;; Copyright (C) 2021 Jimmy Yuen Ho Wong

;; Author: jtbm37
;; Version: 1.0
;; Maintainer: Jimmy Yuen Ho Wong <wyuenho@gmail.com>
;; Version: 2.0
;; Keywords: files icons dired
;; Package-Requires: ((emacs "24.4") (all-the-icons "2.2.0"))
;; URL: https://github.com/jtbm37/all-the-icons-dired
;; Package-Requires: ((emacs "26.1") (all-the-icons "2.2.0"))
;; URL: https://github.com/wyuenho/all-the-icons-dired

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
Expand All @@ -32,100 +34,105 @@

;;; Code:

(require 'cl-lib)
(require 'dired)
(require 'all-the-icons)
(require 'subr-x)
(require 'image)
(require 'jit-lock)
(require 'font-core)
(require 'font-lock)

(defface all-the-icons-dired-dir-face
'((((background dark)) :foreground "white")
(((background light)) :foreground "black"))
"Face for the directory icon"
"Face for the directory icon."
:group 'all-the-icons-faces)

(defcustom all-the-icons-dired-lighter " all-the-icons-dired-mode"
"Lighter of all-the-icons-dired-mode"
:group 'all-the-icons
:type 'string)

(defcustom all-the-icons-dired-v-adjust 0.01
"The default vertical adjustment of the icon in the dired buffer."
"The default vertical adjustment of the icon in the Dired buffer."
:group 'all-the-icons
:type 'number)

(defcustom all-the-icons-dired-monochrome t
"Whether to show the icons as the same color as the text on the same line."
:group 'all-the-icons
:type 'boolean)

(defvar all-the-icons-dired-mode)

(defun all-the-icons-dired--add-overlay (pos string)
"Add overlay to display STRING at POS."
(let ((ov (make-overlay (1- pos) pos)))
(overlay-put ov 'all-the-icons-dired-overlay t)
(overlay-put ov 'after-string string)))

(defun all-the-icons-dired--overlays-in (beg end)
"Get all all-the-icons-dired overlays between BEG to END."
(cl-remove-if-not
(lambda (ov)
(overlay-get ov 'all-the-icons-dired-overlay))
(overlays-in beg end)))

(defun all-the-icons-dired--overlays-at (pos)
"Get all-the-icons-dired overlays at POS."
(apply #'all-the-icons-dired--overlays-in `(,pos ,pos)))

(defun all-the-icons-dired--remove-all-overlays ()
"Remove all `all-the-icons-dired' overlays."
(save-restriction
(widen)
(mapc #'delete-overlay
(all-the-icons-dired--overlays-in (point-min) (point-max)))))

(defun all-the-icons-dired--refresh ()
"Display the icons of files in a dired buffer."
(all-the-icons-dired--remove-all-overlays)
(save-excursion
(goto-char (point-min))
(while (not (eobp))
(when (dired-move-to-filename nil)
(let ((file (dired-get-filename 'relative 'noerror)))
(when file
(let ((icon (if (file-directory-p file)
(all-the-icons-icon-for-dir file
:face 'all-the-icons-dired-dir-face
:v-adjust all-the-icons-dired-v-adjust)
(all-the-icons-icon-for-file file :v-adjust all-the-icons-dired-v-adjust))))
(if (member file '("." ".."))
(all-the-icons-dired--add-overlay (point) " \t")
(all-the-icons-dired--add-overlay (point) (concat icon "\t")))))))
(forward-line 1))))

(defun all-the-icons-dired--refresh-advice (fn &rest args)
"Advice function for FN with ARGS."
(apply fn args)
(when all-the-icons-dired-mode
(all-the-icons-dired--refresh)))
(defun all-the-icons-dired--icon (file)
"Return the icon for FILE."
(if (file-directory-p file)
(all-the-icons-icon-for-dir file
:face 'all-the-icons-dired-dir-face
:v-adjust all-the-icons-dired-v-adjust)
(apply 'all-the-icons-icon-for-file file
(append
`(:v-adjust ,all-the-icons-dired-v-adjust)
(when all-the-icons-dired-monochrome
`(:face ,(face-at-point)))))))

(defun all-the-icons-dired--put-icon (pos)
"Propertize POS with icon."
(let* ((file (dired-get-filename 'relative 'noerror))
(icon (all-the-icons-dired--icon file))
(image (get-text-property 0 'display icon)))
(if (or (not (eq (car image) 'image)) (member file '("." "..")))
(put-text-property (1- pos) pos 'display
(if (member file '("." ".."))
" "
(concat " " icon " ")))
(setf (image-property image :margin) (cons (/ (window-text-width nil t) (window-text-width)) 0))
(put-text-property (1- pos) pos 'display image))))

(defun all-the-icons-dired--fontify-region (start end &optional loudly)
"Add icons using text properties from START to END.

START, END and the optional argument LOUDLY is passed to
`font-lock-default-fontify-region'."
(let ((extended-region (font-lock-default-fontify-region start end loudly)))
(when (and (consp extended-region)
(eq (car extended-region) 'jit-lock-bounds))
(setq start (cadr extended-region))
(setq end (cddr extended-region)))
(with-silent-modifications
(save-excursion
(goto-char start)
(while (< (point) end)
(when-let ((pos (dired-move-to-filename)))
(all-the-icons-dired--put-icon pos))
(forward-line 1))))
extended-region))

(defun all-the-icons-dired--setup ()
"Setup `all-the-icons-dired'."
(when (derived-mode-p 'dired-mode)
(setq-local tab-width 1)
(advice-add 'dired-readin :around #'all-the-icons-dired--refresh-advice)
(advice-add 'dired-revert :around #'all-the-icons-dired--refresh-advice)
(advice-add 'dired-internal-do-deletions :around #'all-the-icons-dired--refresh-advice)
(advice-add 'dired-insert-subdir :around #'all-the-icons-dired--refresh-advice)
(advice-add 'dired-do-kill-lines :around #'all-the-icons-dired--refresh-advice)
(with-eval-after-load 'dired-narrow
(advice-add 'dired-narrow--internal :around #'all-the-icons-dired--refresh-advice))
(all-the-icons-dired--refresh)))
"Set up `all-the-icons-dired'."
(add-function :override (local 'font-lock-fontify-region-function) #'all-the-icons-dired--fontify-region)
(setq-local font-lock-extra-managed-props (cons 'display font-lock-extra-managed-props))
(cond (jit-lock-mode
(jit-lock-refontify))
(font-lock-mode
(font-lock-fontify-region (point-min) (point-max)))))

(defun all-the-icons-dired--teardown ()
"Functions used as advice when redisplaying buffer."
(advice-remove 'dired-readin #'all-the-icons-dired--refresh-advice)
(advice-remove 'dired-revert #'all-the-icons-dired--refresh-advice)
(advice-remove 'dired-internal-do-deletions #'all-the-icons-dired--refresh-advice)
(advice-remove 'dired-narrow--internal #'all-the-icons-dired--refresh-advice)
(advice-remove 'dired-insert-subdir #'all-the-icons-dired--refresh-advice)
(advice-remove 'dired-do-kill-lines #'all-the-icons-dired--refresh-advice)
(all-the-icons-dired--remove-all-overlays))
"Tear down `all-the-icons-dired'."
(font-lock-unfontify-buffer)
(remove-function (local 'font-lock-fontify-region-function) #'all-the-icons-dired--fontify-region)
(setq-local font-lock-extra-managed-props (remove 'display font-lock-extra-managed-props))
(cond (jit-lock-mode
(jit-lock-refontify))
(font-lock-mode
(font-lock-fontify-region (point-min) (point-max)))))

;;;###autoload
(define-minor-mode all-the-icons-dired-mode
"Display all-the-icons icon for each files in a dired buffer."
:lighter " all-the-icons-dired-mode"
(when (and (derived-mode-p 'dired-mode) (display-graphic-p))
"Display all-the-icons icon for each file in a Dired buffer."
:lighter all-the-icons-dired-lighter
(when (derived-mode-p 'dired-mode)
(if all-the-icons-dired-mode
(all-the-icons-dired--setup)
(all-the-icons-dired--teardown))))
Expand Down