Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Added heading and file icons #123

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

Merged
merged 16 commits into from
May 21, 2019
Merged
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
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ default: &default-steps
jobs:
test-emacs-25:
docker:
- image: silex/emacs:25
- image: silex/emacs:25.3
entrypoint: bash
<<: *default-steps

test-emacs-26:
docker:
- image: silex/emacs:26.0
- image: silex/emacs:26.2
entrypoint: bash
<<: *default-steps

Expand Down
3 changes: 2 additions & 1 deletion .dir-locals.el
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
((emacs-lisp-mode . ((indent-tabs-mode . nil)
(fill-column . 100))))
(fill-column . 100)
(elisp-lint-indent-specs . ((when-let . 1))))))
4 changes: 4 additions & 0 deletions .emacs/dependencies.el
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
;;:pin melpa-stable
:ensure t)

(use-package all-the-icons
;;:pin melpa-stable
:ensure t)

;;; dependencies.el ends here
2 changes: 2 additions & 0 deletions .emacs/init.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
;;
;; Usage: emacs -q -l $project_root/emacs/init.el

(setq coding-system-for-write 'utf-8)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Set `user-emacs-directory' to avoid overwriting $HOME/.emacs.d
;; See also: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=15539#66
Expand Down
12 changes: 12 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ You will need the following packages which are all available on Melpa:

1. page-break-lines - [[https://github.com/purcell/page-break-lines]]
2. (optional) projectile - [[https://github.com/bbatsov/projectile]]
3. (optional) all-the-icons - [[https://github.com/domtronn/all-the-icons.el]]

* Usage

Expand Down Expand Up @@ -88,6 +89,17 @@ To add your own custom widget is pretty easy, define your widget's callback func
(add-to-list 'dashboard-item-generators '(custom . dashboard-insert-custom))
(add-to-list 'dashboard-items '(custom) t)
#+END_SRC

To add icons to the widget headings and their items:
#+BEGIN_SRC elisp
(setq dashboard-set-heading-icons t)
(setq dashboard-set-file-icons t)
#+END_SRC

To show info about the packages loaded and the init time
#+BEGIN_SRC elisp
(setq dashboard-set-init-info t)
#+END_SRC

** Org mode’s agenda

Expand Down
112 changes: 92 additions & 20 deletions dashboard-widgets.el
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ to the specified width, with aspect ratio preserved."
:type 'integer
:group 'dashboard)


(defcustom dashboard-set-heading-icons nil
"When non nil, heading sections will have icons."
:type 'boolean
:group 'dashboard)

(defcustom dashboard-set-file-icons nil
"When non nil, file lists will have icons."
:type 'boolean
:group 'dashboard)


(defcustom dashboard-show-shortcuts t
"Whether to show shortcut keys for each section."
:type 'boolean
Expand Down Expand Up @@ -113,7 +125,7 @@ Set to nil for unbounded.")
:group 'dashboard)

(defface dashboard-heading
'((t (:inherit font-lock-function-name-face)))
'((t (:inherit font-lock-keyword-face)))
"Face used for widget headings."
:group 'dashboard)

Expand Down Expand Up @@ -259,24 +271,6 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer."
(dashboard-insert-image-banner banner)
(dashboard-insert-ascii-banner-centered banner))))))

;;
;; Section insertion
;;
(defmacro dashboard-insert-section-list (section-name list action &rest rest)
"Insert into SECTION-NAME a LIST of items, expanding ACTION and passing REST to widget creation."
`(when (car ,list)
(mapc (lambda (el)
(let ((widget nil))
(insert "\n ")
(setq widget
(widget-create 'push-button
:action ,action
:mouse-face 'highlight
:button-prefix ""
:button-suffix ""
:format "%[%t%]"
,@rest))))
,list)))

(defmacro dashboard-insert-section (section-name list list-size shortcut action &rest widget-params)
"Add a section with SECTION-NAME and LIST of LIST-SIZE items to the dashboard.
Expand All @@ -294,6 +288,85 @@ WIDGET-PARAMS are passed to the \"widget-create\" function."
,@widget-params)
(dashboard-insert-shortcut ,shortcut ,section-name))
(insert "\n --- No items ---"))))


;; Add heading icons
(defun dashboard-insert-heading-icon (heading &optional _shortcut)
"Add icon to the section's HEADING."
(when (and
(display-graphic-p)
(eq dashboard-set-heading-icons t))
;; Load `all-the-icons' if it's unavailable
(unless (featurep 'all-the-icons)
(require 'all-the-icons nil t))

(insert (cond
((string-equal heading "Recent Files:")
(all-the-icons-octicon "history" :height 1.2 :v-adjust 0.0 :face 'dashboard-heading))
((string-equal heading "Bookmarks:")
(all-the-icons-octicon "bookmark" :height 1.2 :v-adjust 0.0 :face 'dashboard-heading))
((string-equal heading "Agenda for today:")
(all-the-icons-octicon "calendar" :height 1.2 :v-adjust 0.0 :face 'dashboard-heading))
((string-equal heading "Registers:")
(all-the-icons-octicon "database" :height 1.2 :v-adjust 0.0 :face 'dashboard-heading))
((string-equal heading "Projects:")
(all-the-icons-octicon "rocket" :height 1.2 :v-adjust 0.0 :face 'dashboard-heading))))
(insert " ")))
(advice-add #'dashboard-insert-heading :before #'dashboard-insert-heading-icon)

;;
;; Add file icons
(defmacro dashboard-insert-section-list (section-name list action &rest rest)
"Insert into SECTION-NAME a LIST of items, expanding ACTION and passing REST to widget creation."
`(when (car ,list)
(mapc (lambda (el)
(let ((widget nil))
(insert "\n ")
(when (and
(display-graphic-p)
(eq dashboard-set-file-icons t))
(insert (let ((path (car (last (split-string ,@rest " - ")))))
(when path
(if (and
(eq (file-remote-p path) nil)
(file-directory-p path))
(cond
((and (fboundp 'tramp-tramp-file-p)
(tramp-tramp-file-p default-directory))
(all-the-icons-octicon "file-directory"
:height 1.0 :v-adjust 0.01))
((file-symlink-p path)
(all-the-icons-octicon "file-symlink-directory"
:height 1.0 :v-adjust 0.01))
((all-the-icons-dir-is-submodule path)
(all-the-icons-octicon "file-submodule"
:height 1.0 :v-adjust 0.01))
((file-exists-p (format "%s/.git" path))
(all-the-icons-octicon "repo"
:height 1.1 :v-adjust 0.01))
(t (let
((matcher (all-the-icons-match-to-alist
path all-the-icons-dir-icon-alist)))
(apply (car matcher) (list (cadr matcher)
:v-adjust 0.01)))))
(cond
((string-equal ,section-name "Agenda for today:")
(all-the-icons-octicon "primitive-dot"
:height 1.0 :v-adjust 0.01))
((eq (file-remote-p path) nil)
(all-the-icons-icon-for-file (file-name-nondirectory path)))
(t (all-the-icons-octicon "radio-tower"
:height 1.1 :v-adjust 0.01)))))))
(insert "\t"))
(setq widget
(widget-create 'push-button
:action ,action
:mouse-face 'highlight
:button-prefix ""
:button-suffix ""
:format "%[%t%]"
,@rest))))
,list)))
;;
;; Recentf
;;
Expand Down Expand Up @@ -326,7 +399,6 @@ WIDGET-PARAMS are passed to the \"widget-create\" function."
(format "%s - %s" el (abbreviate-file-name file))
el))))

;;
;; Projectile
;;
(defun dashboard-insert-projects (list-size)
Expand Down
Binary file modified screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.