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

Skip to content

Make the icons clickable with the file names and performance improvements #129

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 3 commits into from
May 23, 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
146 changes: 69 additions & 77 deletions dashboard-widgets.el
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;;; dashboard-widgets.el --- A startup screen extracted from Spacemacs
;;; dashboard-widgets.el --- A startup screen extracted from Spacemacs -*- lexical-binding: t -*-

;; Copyright (c) 2016 Rakan Al-Hneiti & Contributors
;;
Expand Down Expand Up @@ -174,7 +174,7 @@ Optionally, provide NO-NEXT-LINE to move the cursor forward a line."
(eval-after-load 'dashboard
(define-key dashboard-mode-map ,shortcut-char sym)))))

(defun dashboard-append (msg &optional messagebuf)
(defun dashboard-append (msg &optional _messagebuf)
"Append MSG to dashboard buffer.
If MESSAGEBUF is not nil then MSG is also written in message buffer."
(with-current-buffer (get-buffer-create "*dashboard*")
Expand All @@ -188,6 +188,26 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer."

(defun dashboard-insert-heading (heading &optional shortcut)
"Insert a widget HEADING in dashboard buffer, adding SHORTCUT if provided."
(when (and (display-graphic-p)
dashboard-set-heading-icons)
;; Try loading `all-the-icons'
(unless (require 'all-the-icons nil 'noerror)
(error "Package `all-the-icons' isn't installed"))

(insert
(cond
((string-equal heading "Recent Files:")
(all-the-icons-octicon "file-text" :height 1.2 :v-adjust 0 :face 'dashboard-heading))
((string-equal heading "Bookmarks:")
(all-the-icons-octicon "bookmark" :height 1.2 :v-adjust 0 :face 'dashboard-heading))
((string-equal heading "Agenda for today:")
(all-the-icons-octicon "calendar" :height 1.2 :v-adjust 0 :face 'dashboard-heading))
((string-equal heading "Registers:")
(all-the-icons-octicon "database" :height 1.2 :v-adjust 0 :face 'dashboard-heading))
((string-equal heading "Projects:")
(all-the-icons-octicon "file-directory" :height 1.2 :v-adjust 0 :face 'dashboard-heading))))
(insert " "))

(insert (propertize heading 'face 'dashboard-heading))
(if shortcut (insert (format " (%s)" shortcut))))

Expand Down Expand Up @@ -296,90 +316,61 @@ WIDGET-PARAMS are passed to the \"widget-create\" function."
(if ,list
(when (dashboard-insert-section-list
,section-name
(dashboard-subseq ,list 0 list-size)
(dashboard-subseq ,list 0 ,list-size)
,action
,@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)
;; Section list
;;
(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)
(mapc
(lambda (el)
(let ((tag ,@rest))
(insert "\n ")

(when (and (display-graphic-p)
dashboard-set-file-icons
(featurep 'all-the-icons))
(let* ((path (car (last (split-string ,@rest " - "))))
(icon (if (and (not (file-remote-p path))
(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)))
(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))
((file-remote-p path)
(all-the-icons-octicon "radio-tower" :height 1.1 :v-adjust 0.01))
(t (all-the-icons-icon-for-file (file-name-nondirectory path)))))))
(setq tag (concat icon " " ,@rest))))

(widget-create 'file-link
:tag tag
:mouse-face 'highlight
:help-echo el
:button-prefix ""
:button-suffix ""
:format "%[%t%]"
el)))
,list)))

;;
;; Recentf
;;
Expand Down Expand Up @@ -412,6 +403,7 @@ 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
6 changes: 2 additions & 4 deletions dashboard.el
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;;; dashboard.el --- A startup screen extracted from Spacemacs
;;; dashboard.el --- A startup screen extracted from Spacemacs -*- lexical-binding: t -*-

;; Copyright (c) 2016 Rakan Al-Hneiti & Contributors
;;
Expand Down Expand Up @@ -143,7 +143,6 @@ Optional prefix ARG says how many lines to move; default is one line."
"Insert the list of widgets into the buffer."
(interactive)
(let ((buffer-exists (buffer-live-p (get-buffer dashboard-buffer-name)))
(save-line nil)
(recentf-is-on (recentf-enabled-p))
(origial-recentf-list recentf-list)
(dashboard-num-recents (or (cdr (assoc 'recents dashboard-items)) 0))
Expand All @@ -163,8 +162,7 @@ Optional prefix ARG says how many lines to move; default is one line."
(setq dashboard-banner-length (window-width)
dashboard-buffer-last-width dashboard-banner-length)
(with-current-buffer (get-buffer-create dashboard-buffer-name)
(let ((buffer-read-only nil)
(list-separator "\n\n"))
(let ((buffer-read-only nil))
(erase-buffer)
(dashboard-insert-banner)
(dashboard-insert-page-break)
Expand Down