From 754df63e90e56ab9a87464c9efbaa2bf34919699 Mon Sep 17 00:00:00 2001 From: Jason Dufair Date: Wed, 20 Feb 2019 22:53:02 -0800 Subject: [PATCH 01/17] WIP: Render content centered if specified. --- dashboard-widgets.el | 126 +++++++++++++++++++++++-------------------- dashboard.el | 39 ++++++++------ 2 files changed, 90 insertions(+), 75 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index 7f67d569..6d2f8ac3 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -1,4 +1,4 @@ -;;; dashboard.el --- A startup screen extracted from Spacemacs +;;; dashboard-widgets.el --- A startup screen extracted from Spacemacs ;; Copyright (c) 2016 Rakan Al-Hneiti & Contributors ;; @@ -42,8 +42,8 @@ to the specified width, with aspect ratio preserved." (defconst dashboard-banners-directory (concat (file-name-directory - (locate-library "dashboard")) - "/banners/")) + (locate-library "dashboard")) + "/banners/")) (defconst dashboard-banner-official-png (expand-file-name (concat dashboard-banners-directory "emacs.png")) @@ -57,10 +57,10 @@ to the specified width, with aspect ratio preserved." "Width of a banner.") (defvar dashboard-banner-logo-title "Welcome to Emacs!" - "Specify the startup banner.") + "Specify the startup banner.") (defvar dashboard-startup-banner 'official - "Specify the startup banner. + "Specify the startup banner. Default value is `official', it displays the Emacs logo. `logo' displays Emacs alternative logo. An integer value is the index of text @@ -112,17 +112,17 @@ Return entire list if `END' is omitted." (min len end))))) (defmacro dashboard-insert-shortcut (shortcut-char - search-label - &optional no-next-line) + search-label + &optional no-next-line) "Insert a shortcut SHORTCUT-CHAR for a given SEARCH-LABEL. Optionally, provide NO-NEXT-LINE to move the cursor forward a line." `(define-key dashboard-mode-map ,shortcut-char (lambda () - (interactive) - (unless (search-forward ,search-label (point-max) t) - (search-backward ,search-label (point-min) t)) - ,@(unless no-next-line - '((forward-line 1))) - (back-to-indentation)))) + (interactive) + (unless (search-forward ,search-label (point-max) t) + (search-backward ,search-label (point-min) t)) + ,@(unless no-next-line + '((forward-line 1))) + (back-to-indentation)))) (defun dashboard-append (msg &optional messagebuf) "Append MSG to dashboard buffer. @@ -157,7 +157,7 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (goto-char 0) (let ((margin (max 0 (floor (/ (- dashboard-banner-length banner-width) 2))))) (while (not (eobp)) - (insert (make-string margin ?\ )) + (insert (make-string margin ?\ )) (forward-line 1)))) (buffer-string)))) @@ -181,9 +181,9 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (insert-image spec) (insert "\n\n") (when title - (insert (make-string (max 0 (floor (/ (- dashboard-banner-length - (+ (length title) 1)) 2))) ?\ )) - (insert (format "%s\n\n" (propertize title 'face 'dashboard-banner-logo-title-face))))))) + (insert (make-string (max 0 (floor (/ (- dashboard-banner-length + (+ (length title) 1)) 2))) ?\ )) + (insert (format "%s\n\n" (propertize title 'face 'dashboard-banner-logo-title-face))))))) (defun dashboard-get-banner-path (index) "Return the full path to banner with index INDEX." @@ -196,7 +196,7 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (if (and (display-graphic-p) (image-type-available-p 'png)) dashboard-banner-official-png (dashboard-get-banner-path 1))) - ((eq 'logo dashboard-startup-banner) + ((eq 'logo dashboard-startup-banner) (if (and (display-graphic-p) (image-type-available-p 'png)) dashboard-banner-logo-png (dashboard-get-banner-path 1))) @@ -208,9 +208,9 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (display-graphic-p)) (if (file-exists-p dashboard-startup-banner) dashboard-startup-banner - (message (format "could not find banner %s" - dashboard-startup-banner)) - (dashboard-get-banner-path 1))) + (message (format "could not find banner %s" + dashboard-startup-banner)) + (dashboard-get-banner-path 1))) (t (dashboard-get-banner-path 1))))) (defun dashboard-insert-banner () @@ -220,7 +220,7 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (buffer-read-only nil)) (progn (when banner - (if (image-type-available-p (intern (file-name-extension banner))) + (if (image-type-available-p (intern (file-name-extension banner))) (dashboard-insert-image-banner banner) (dashboard-insert-ascii-banner-centered banner)))))) @@ -229,27 +229,35 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." ;; (defun dashboard-insert-recentf-list (list-display-name list) "Render LIST-DISPLAY-NAME title and items of LIST." - (when (car list) - (dashboard-insert-heading list-display-name) - (mapc (lambda (el) - (insert "\n ") - (widget-create 'push-button - :action `(lambda (&rest ignore) (find-file-existing ,el)) - :mouse-face 'highlight - :follow-link "\C-m" - :button-prefix "" - :button-suffix "" - :format "%[%t%]" - (abbreviate-file-name el))) - list))) + (let ((max-line-length 0)) + (when (car list) + (dashboard-insert-heading list-display-name) + (mapc (lambda (el) + (let ((widget nil)) + (insert "\n ") + (setq widget + (widget-create 'push-button + :action `(lambda (&rest ignore) (find-file-existing ,el)) + :mouse-face 'highlight + :follow-link "\C-m" + :button-prefix "" + :button-suffix "" + :format "%[%t%]" + (abbreviate-file-name el))) + (setq max-line-length + (max max-line-length (length (widget-value-value-get widget)))))) + list)) + max-line-length)) (defun dashboard-insert-recents (list-size) "Add the list of LIST-SIZE items from recently edited files." (recentf-mode) - (when (dashboard-insert-recentf-list - "Recent Files:" - (dashboard-subseq recentf-list 0 list-size)) - (dashboard-insert-shortcut "r" "Recent Files:"))) + (when-let ((max-line-length + (dashboard-insert-recentf-list + "Recent Files:" + (dashboard-subseq recentf-list 0 list-size)))) + (dashboard-insert-shortcut "r" "Recent Files:") + max-line-length)) ;; @@ -278,9 +286,9 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." "Add the list of LIST-SIZE items of bookmarks." (require 'bookmark) (when (dashboard-insert-bookmark-list - "Bookmarks:" - (dashboard-subseq (bookmark-all-names) - 0 list-size)) + "Bookmarks:" + (dashboard-subseq (bookmark-all-names) + 0 list-size)) (dashboard-insert-shortcut "m" "Bookmarks:"))) ;; @@ -294,7 +302,7 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (insert "\n ") (widget-create 'push-button :action `(lambda (&rest ignore) - (projectile-switch-project-by-name ,el)) + (projectile-switch-project-by-name ,el)) :mouse-face 'highlight :follow-link "\C-m" :button-prefix "" @@ -310,12 +318,12 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (projectile-mode) (if (bound-and-true-p projectile-mode) (progn - (projectile-load-known-projects) - (when (dashboard-insert-project-list - "Projects:" - (dashboard-subseq (projectile-relevant-known-projects) - 0 list-size)) - (dashboard-insert-shortcut "p" "Projects:"))) + (projectile-load-known-projects) + (when (dashboard-insert-project-list + "Projects:" + (dashboard-subseq (projectile-relevant-known-projects) + 0 list-size)) + (dashboard-insert-shortcut "p" "Projects:"))) (message "Failed to load projects list"))) ;; @@ -384,16 +392,16 @@ date part is considered." (org-map-entries (lambda () (let* ((schedule-time (org-get-scheduled-time (point))) - (deadline-time (org-get-deadline-time (point))) - (item (org-agenda-format-item - (format-time-string "%Y-%m-%d" schedule-time) - (org-get-heading t t) - (org-outline-level) - (org-get-category) - (org-get-tags) - t)) - (loc (point)) - (file (buffer-file-name))) + (deadline-time (org-get-deadline-time (point))) + (item (org-agenda-format-item + (format-time-string "%Y-%m-%d" schedule-time) + (org-get-heading t t) + (org-outline-level) + (org-get-category) + (org-get-tags) + t)) + (loc (point)) + (file (buffer-file-name))) (when (and (not (org-entry-is-done-p)) (or (and schedule-time (dashboard-date-due-p schedule-time due-date)) (and deadline-time (dashboard-date-due-p deadline-time due-date)))) diff --git a/dashboard.el b/dashboard.el index c3947d51..2d1268f1 100644 --- a/dashboard.el +++ b/dashboard.el @@ -100,11 +100,11 @@ "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)) - ) + (save-line nil) + (recentf-is-on (recentf-enabled-p)) + (origial-recentf-list recentf-list) + (dashboard-num-recents (or (cdr (assoc 'recents dashboard-items)) 0)) + (max-line-length 0)) ;; disable recentf mode, ;; so we don't flood the recent files list with org mode files ;; do this by making a copy of the part of the list we'll use @@ -113,14 +113,13 @@ ;; (this avoids many saves/loads that would result from ;; disabling/enabling recentf-mode) (if recentf-is-on - (setq recentf-list (seq-take recentf-list dashboard-num-recents)) - ) + (setq recentf-list (seq-take recentf-list dashboard-num-recents))) (when (or (not (eq dashboard-buffer-last-width (window-width))) (not buffer-exists)) (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) + (let ((buffer-read-only nil) (list-separator "\n\n")) (erase-buffer) (dashboard-insert-banner) @@ -128,20 +127,28 @@ (setq dashboard--section-starts nil) (mapc (lambda (els) (let* ((el (or (car-safe els) els)) - (list-size + (list-size (or (cdr-safe els) dashboard-items-default-length)) - (item-generator + (item-generator (cdr-safe (assoc el dashboard-item-generators)))) (add-to-list 'dashboard--section-starts (point)) - (funcall item-generator list-size) + (setq max-line-length + (max (funcall item-generator list-size))) (dashboard-insert-page-break))) - dashboard-items)) - (dashboard-mode) - (goto-char (point-min)))) + dashboard-items) + (if dashboard-center-content + (progn + (goto-char (car dashboard--section-starts)) + (dashboard-next-section) + (let ((margin (max 0 (floor (/ (- (window-width) max-line-length) 2))))) + (while (not (eobp)) + (insert (make-string margin ?\ )) + (forward-line 1)))))) + (dashboard-mode) + (goto-char (point-min)))) (if recentf-is-on - (setq recentf-list origial-recentf-list) - ))) + (setq recentf-list origial-recentf-list)))) (add-hook 'window-setup-hook (lambda () From 16e40fcaae4a3bcff558663f4bc85b2a6d070514 Mon Sep 17 00:00:00 2001 From: Jason Dufair Date: Wed, 20 Feb 2019 23:39:43 -0800 Subject: [PATCH 02/17] Start macro-fying section generation --- dashboard-widgets.el | 46 ++++++++++++++++++++++++++------------------ dashboard.el | 8 ++++---- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index 6d2f8ac3..30225dea 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -224,42 +224,43 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (dashboard-insert-image-banner banner) (dashboard-insert-ascii-banner-centered banner)))))) -;; -;; Recentf -;; -(defun dashboard-insert-recentf-list (list-display-name list) - "Render LIST-DISPLAY-NAME title and items of LIST." - (let ((max-line-length 0)) - (when (car list) - (dashboard-insert-heading list-display-name) +(defmacro dashboard-insert-section (list-display-name list action &rest rest) + "Render LIST-DISPLAY-NAME and items of LIST, expanding ACTION and passing REST to widget creation." + `(let ((max-line-length 0)) + (when (car ,list) + (dashboard-insert-heading ,list-display-name) (mapc (lambda (el) (let ((widget nil)) (insert "\n ") (setq widget (widget-create 'push-button - :action `(lambda (&rest ignore) (find-file-existing ,el)) + :action ,action :mouse-face 'highlight :follow-link "\C-m" :button-prefix "" :button-suffix "" :format "%[%t%]" - (abbreviate-file-name el))) + ,@rest)) (setq max-line-length (max max-line-length (length (widget-value-value-get widget)))))) - list)) + ,list)) max-line-length)) +;; +;; Recentf +;; (defun dashboard-insert-recents (list-size) "Add the list of LIST-SIZE items from recently edited files." (recentf-mode) (when-let ((max-line-length - (dashboard-insert-recentf-list + (dashboard-insert-section "Recent Files:" - (dashboard-subseq recentf-list 0 list-size)))) + (dashboard-subseq recentf-list 0 list-size) + `(lambda (&rest ignore) (find-file-existing ,el)) + (abbreviate-file-name el)))) (dashboard-insert-shortcut "r" "Recent Files:") max-line-length)) - ;; ;; Bookmarks ;; @@ -285,11 +286,18 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (defun dashboard-insert-bookmarks (list-size) "Add the list of LIST-SIZE items of bookmarks." (require 'bookmark) - (when (dashboard-insert-bookmark-list - "Bookmarks:" - (dashboard-subseq (bookmark-all-names) - 0 list-size)) - (dashboard-insert-shortcut "m" "Bookmarks:"))) + (when-let ((max-line-length + (dashboard-insert-section + "Bookmarks:" + (dashboard-subseq (bookmark-all-names) + 0 list-size) + `(lambda (&rest ignore) (bookmark-jump ,el)) + (let ((file (bookmark-get-filename el))) + (if file + (format "%s - %s" el (abbreviate-file-name file)) + el))))) + (dashboard-insert-shortcut "m" "Bookmarks:") + max-line-length)) ;; ;; Projectile diff --git a/dashboard.el b/dashboard.el index 2d1268f1..17186276 100644 --- a/dashboard.el +++ b/dashboard.el @@ -134,14 +134,14 @@ (cdr-safe (assoc el dashboard-item-generators)))) (add-to-list 'dashboard--section-starts (point)) (setq max-line-length - (max (funcall item-generator list-size))) + (max max-line-length (funcall item-generator list-size))) (dashboard-insert-page-break))) dashboard-items) (if dashboard-center-content (progn - (goto-char (car dashboard--section-starts)) - (dashboard-next-section) - (let ((margin (max 0 (floor (/ (- (window-width) max-line-length) 2))))) + (goto-char (car (last dashboard--section-starts))) + (let ((margin (floor (/ (- (window-width) max-line-length) 2)))) + (message "%d %d %d" (window-width) max-line-length margin) (while (not (eobp)) (insert (make-string margin ?\ )) (forward-line 1)))))) From 410ceab7d5ea257feed3c97949d663fab8babdde Mon Sep 17 00:00:00 2001 From: Jason Dufair Date: Thu, 21 Feb 2019 06:34:59 -0800 Subject: [PATCH 03/17] Customization for centering --- dashboard.el | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dashboard.el b/dashboard.el index 17186276..08c54fe1 100644 --- a/dashboard.el +++ b/dashboard.el @@ -62,6 +62,11 @@ "Settings that are used in the Dashboard" :group 'dashboard) +(defcustom dashboard-center-content t + "Whether to center content within the window." + :type 'boolean + :group 'dashboard) + (defconst dashboard-buffer-name "*dashboard*" "Dashboard's buffer name.") From 1ca657379988737f7b105f20de3f2d22868f127b Mon Sep 17 00:00:00 2001 From: Jason Dufair Date: Thu, 21 Feb 2019 07:04:04 -0800 Subject: [PATCH 04/17] Macro-fy recentf, bookmarks, projects --- dashboard-widgets.el | 113 ++++++++++++++++++------------------------- 1 file changed, 47 insertions(+), 66 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index 30225dea..0b082af9 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -224,8 +224,11 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (dashboard-insert-image-banner banner) (dashboard-insert-ascii-banner-centered banner)))))) -(defmacro dashboard-insert-section (list-display-name list action &rest rest) - "Render LIST-DISPLAY-NAME and items of LIST, expanding ACTION and passing REST to widget creation." +;; +;; Section insertion +;; +(defmacro dashboard-insert-section-list (list-display-name list action &rest rest) + "Insert a LIST of items with LIST-DISPLAY-NAME, expanding ACTION and passing REST to widget creation." `(let ((max-line-length 0)) (when (car ,list) (dashboard-insert-heading ,list-display-name) @@ -246,93 +249,71 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." ,list)) max-line-length)) +(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. +ACTION is theaction taken when the user activates the widget button. +SHORTCUT is the keyboard shortcut used to access the section. +WIDGET-PARAMS are passed to the \"widget-create\" function." + `(progn + (when-let ((max-line-length + (dashboard-insert-section-list + ,section-name + (dashboard-subseq ,list 0 list-size) + ,action + ,@widget-params))) + (dashboard-insert-shortcut ,shortcut ,section-name) + max-line-length))) + ;; ;; Recentf ;; (defun dashboard-insert-recents (list-size) "Add the list of LIST-SIZE items from recently edited files." (recentf-mode) - (when-let ((max-line-length - (dashboard-insert-section - "Recent Files:" - (dashboard-subseq recentf-list 0 list-size) - `(lambda (&rest ignore) (find-file-existing ,el)) - (abbreviate-file-name el)))) - (dashboard-insert-shortcut "r" "Recent Files:") - max-line-length)) + (dashboard-insert-section + "Recent Files:" + recentf-list + list-size + "r" + `(lambda (&rest ignore) (find-file-existing ,el)) + (abbreviate-file-name el))) ;; ;; Bookmarks ;; -(defun dashboard-insert-bookmark-list (list-display-name list) - "Render LIST-DISPLAY-NAME title and bookmarks items of LIST." - (when (car list) - (dashboard-insert-heading list-display-name) - (mapc (lambda (el) - (insert "\n ") - (widget-create 'push-button - :action `(lambda (&rest ignore) (bookmark-jump ,el)) - :mouse-face 'highlight - :follow-link "\C-m" - :button-prefix "" - :button-suffix "" - :format "%[%t%]" - (let ((file (bookmark-get-filename el))) - (if file - (format "%s - %s" el (abbreviate-file-name file)) - el)))) - list))) - (defun dashboard-insert-bookmarks (list-size) "Add the list of LIST-SIZE items of bookmarks." (require 'bookmark) - (when-let ((max-line-length - (dashboard-insert-section - "Bookmarks:" - (dashboard-subseq (bookmark-all-names) + (dashboard-insert-section + "Bookmarks:" + (dashboard-subseq (bookmark-all-names) 0 list-size) - `(lambda (&rest ignore) (bookmark-jump ,el)) - (let ((file (bookmark-get-filename el))) + list-size + "m" + `(lambda (&rest ignore) (bookmark-jump ,el)) + (let ((file (bookmark-get-filename el))) (if file (format "%s - %s" el (abbreviate-file-name file)) - el))))) - (dashboard-insert-shortcut "m" "Bookmarks:") - max-line-length)) + el)))) ;; ;; Projectile ;; -(defun dashboard-insert-project-list (list-display-name list) - "Render LIST-DISPLAY-NAME title and project items of LIST." - (when (car list) - (dashboard-insert-heading list-display-name) - (mapc (lambda (el) - (insert "\n ") - (widget-create 'push-button - :action `(lambda (&rest ignore) - (projectile-switch-project-by-name ,el)) - :mouse-face 'highlight - :follow-link "\C-m" - :button-prefix "" - :button-suffix "" - :format "%[%t%]" - (abbreviate-file-name el))) - list))) - (defun dashboard-insert-projects (list-size) "Add the list of LIST-SIZE items of projects." - ;; For some reason, projectile has to be loaded here - ;; before trying to load projects list - (projectile-mode) - (if (bound-and-true-p projectile-mode) - (progn + (projectile-mode) + (if (bound-and-true-p projectile-mode) + (progn (projectile-load-known-projects) - (when (dashboard-insert-project-list - "Projects:" - (dashboard-subseq (projectile-relevant-known-projects) - 0 list-size)) - (dashboard-insert-shortcut "p" "Projects:"))) - (message "Failed to load projects list"))) + (dashboard-insert-section + "Projects:" + (dashboard-subseq (projectile-relevant-known-projects) + 0 list-size) + list-size + "p" + `(lambda (&rest ignore) + (projectile-switch-project-by-name ,el)) + (abbreviate-file-name el))))) ;; ;; Org Agenda From 9ce8c1ab72f8233664ba9c6f2dd129e4b7c1585f Mon Sep 17 00:00:00 2001 From: Jason Dufair Date: Thu, 21 Feb 2019 11:25:31 -0800 Subject: [PATCH 05/17] Macro-fy agenda, registers --- dashboard-widgets.el | 121 ++++++++++++++++--------------------------- dashboard.el | 3 +- 2 files changed, 46 insertions(+), 78 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index 0b082af9..2f1ac9a5 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -227,34 +227,35 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." ;; ;; Section insertion ;; -(defmacro dashboard-insert-section-list (list-display-name list action &rest rest) - "Insert a LIST of items with LIST-DISPLAY-NAME, expanding ACTION and passing REST to widget creation." +(defmacro dashboard-insert-section-list (section-name list action &rest rest) + "Insert a LIST of items with SECTION-NAME, expanding ACTION and passing REST to widget creation." `(let ((max-line-length 0)) - (when (car ,list) - (dashboard-insert-heading ,list-display-name) - (mapc (lambda (el) - (let ((widget nil)) - (insert "\n ") - (setq widget - (widget-create 'push-button - :action ,action - :mouse-face 'highlight - :follow-link "\C-m" - :button-prefix "" - :button-suffix "" - :format "%[%t%]" - ,@rest)) - (setq max-line-length - (max max-line-length (length (widget-value-value-get widget)))))) - ,list)) - max-line-length)) + (when (car ,list) + (mapc (lambda (el) + (let ((widget nil)) + (insert "\n ") + (setq widget + (widget-create 'push-button + :action ,action + :mouse-face 'highlight + :follow-link "\C-m" + :button-prefix "" + :button-suffix "" + :format "%[%t%]" + ,@rest)) + (setq max-line-length + (max max-line-length (length (widget-value-value-get widget)))))) + ,list)) + max-line-length)) (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. ACTION is theaction taken when the user activates the widget button. SHORTCUT is the keyboard shortcut used to access the section. -WIDGET-PARAMS are passed to the \"widget-create\" function." +WIDGET-PARAMS are passed to the \"widget-create\" function. +Show EMPTY-LIST-TEXT if no items in list" `(progn + (dashboard-insert-heading ,section-name) (when-let ((max-line-length (dashboard-insert-section-list ,section-name @@ -318,32 +319,6 @@ WIDGET-PARAMS are passed to the \"widget-create\" function." ;; ;; Org Agenda ;; -(defun dashboard-insert-agenda-list (list-display-name list) - "Render LIST-DISPLAY-NAME title and agenda items from LIST." - (dashboard-insert-heading list-display-name) - (if (car list) - (mapc (lambda (el) - (insert "\n ") - (let ((filename (nth 4 el)) - (lineno (nth 3 el)) - (title (nth 0 el))) - (widget-create 'push-button - :action `(lambda (&rest ignore) - (let ((buffer (find-file-other-window ,filename))) - (with-current-buffer buffer - (goto-char ,lineno) - ) - (switch-to-buffer buffer))) - :mouse-face 'highlight - :follow-link "\C-m" - :button-prefix "" - :button-suffix "" - :format "%[%t%]" - (format "%s" title))) - ) - list) - (insert (propertize "\n --- No items ---" 'face 'widget-button)))) - (defun dashboard-timestamp-to-gregorian-date (timestamp) "Convert TIMESTAMP to a gregorian date. @@ -402,42 +377,36 @@ date part is considered." filtered-entries)) (defun dashboard-insert-agenda (list-size) - "Add the list of LIST-SIZE items of agenda." - (if (and (boundp 'show-week-agenda-p) show-week-agenda-p) - (setq agenda-time-string "Agenda for the coming week:") - (setq agenda-time-string "Agenda for today:") - ) - (when (dashboard-insert-agenda-list agenda-time-string - (dashboard-get-agenda)) - (dashboard-insert-shortcut "a" agenda-time-string))) + "Add the list of LIST-SIZE items of agenda." + (let ((agenda (dashboard-get-agenda))) + (dashboard-insert-section + (or (and (boundp 'show-week-agenda-p) show-week-agenda-p "Agenda for the coming week:") + "Agenda for today:") + (or agenda '()) + list-size + "a" + `(lambda (&rest ignore) + (let ((buffer (find-file-other-window (nth 4 el)))) + (with-current-buffer buffer + (goto-char (nth 3 el))) + (switch-to-buffer buffer))) + (format "%s" (nth 0 el))) + (and (not agenda) + (insert "\n --- No items ---")))) ;; ;; Registers ;; -(defun dashboard-insert-register-list (list-display-name list) - "Render LIST-DISPLAY-NAME title and registers items of LIST." - (when (car list) - (dashboard-insert-heading list-display-name) - (mapc (lambda (el) - (let ((register (car el))) - (insert "\n ") - (widget-create 'push-button - :action `(lambda (&rest ignore) (jump-to-register ,register)) - :mouse-face 'highlight - :follow-link "\C-m" - :button-prefix "" - :button-suffix "" - :format "%[%t%]" - (format "%c - %s" register (register-describe-oneline register))))) - list))) - (defun dashboard-insert-registers (list-size) "Add the list of LIST-SIZE items of registers." (require 'register) - (when (dashboard-insert-register-list - "Registers:" - (dashboard-subseq register-alist 0 list-size)) - (dashboard-insert-shortcut "e" "Registers:"))) + (dashboard-insert-section + "Registers:" + register-alist + list-size + "e" + `(lambda (&rest ignore) (jump-to-register ,(car el))) + (format "%c - %s" (car el) (register-describe-oneline (car el))))) ;; Forward declartions for optional dependency to keep check-declare happy. diff --git a/dashboard.el b/dashboard.el index 08c54fe1..89954d5a 100644 --- a/dashboard.el +++ b/dashboard.el @@ -139,14 +139,13 @@ (cdr-safe (assoc el dashboard-item-generators)))) (add-to-list 'dashboard--section-starts (point)) (setq max-line-length - (max max-line-length (funcall item-generator list-size))) + (max max-line-length (or (funcall item-generator list-size) 0))) (dashboard-insert-page-break))) dashboard-items) (if dashboard-center-content (progn (goto-char (car (last dashboard--section-starts))) (let ((margin (floor (/ (- (window-width) max-line-length) 2)))) - (message "%d %d %d" (window-width) max-line-length margin) (while (not (eobp)) (insert (make-string margin ?\ )) (forward-line 1)))))) From 0e86bf2aef5770fd959ff0d3c4a61d6b8ffbfb17 Mon Sep 17 00:00:00 2001 From: Jason Dufair Date: Fri, 22 Feb 2019 13:15:47 -0500 Subject: [PATCH 06/17] Don't "center" page break lines --- dashboard.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dashboard.el b/dashboard.el index 89954d5a..92b0778b 100644 --- a/dashboard.el +++ b/dashboard.el @@ -147,7 +147,8 @@ (goto-char (car (last dashboard--section-starts))) (let ((margin (floor (/ (- (window-width) max-line-length) 2)))) (while (not (eobp)) - (insert (make-string margin ?\ )) + (and (not (eq ? (char-after))) + (insert (make-string margin ?\ ))) (forward-line 1)))))) (dashboard-mode) (goto-char (point-min)))) From 7ddd2eefc7834cf96eabe444758dafdbcd6babfe Mon Sep 17 00:00:00 2001 From: Jason Dufair Date: Fri, 22 Feb 2019 13:23:32 -0500 Subject: [PATCH 07/17] Update README.org to indicate default centering and customize option --- README.org | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.org b/README.org index 2868afc9..e8a0076b 100644 --- a/README.org +++ b/README.org @@ -59,6 +59,8 @@ To update the banner or banner title (setq dashboard-banner-logo-title "Welcome to Emacs Dashboard") ;; Set the banner (setq dashboard-startup-banner [VALUE]) +;; Content is centered by default. To left-justify, set +(setq dashboard-center-content nil) ;; Value can be ;; 'official which displays the official emacs logo ;; 'logo which displays an alternative emacs logo From e24b81ac4be53a94d307aa43f54e89b9c3da20cc Mon Sep 17 00:00:00 2001 From: Jason Dufair Date: Fri, 22 Feb 2019 13:54:09 -0500 Subject: [PATCH 08/17] Don't interrupt the existing docs! --- README.org | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.org b/README.org index e8a0076b..a33636ca 100644 --- a/README.org +++ b/README.org @@ -59,13 +59,14 @@ To update the banner or banner title (setq dashboard-banner-logo-title "Welcome to Emacs Dashboard") ;; Set the banner (setq dashboard-startup-banner [VALUE]) -;; Content is centered by default. To left-justify, set -(setq dashboard-center-content nil) ;; Value can be ;; 'official which displays the official emacs logo ;; 'logo which displays an alternative emacs logo ;; 1, 2 or 3 which displays one of the text banners ;; "path/to/your/image.png" which displays whatever image you would prefer + +;; Content is centered by default. To left-justify, set +(setq dashboard-center-content nil) #+END_SRC To customize which widgets are displayed, you can use the following snippet From a25c6541cc581d84e40df90dc3fc33cbf652026b Mon Sep 17 00:00:00 2001 From: Jason Dufair Date: Fri, 22 Feb 2019 15:54:32 -0500 Subject: [PATCH 09/17] Revert whitespace-only changes --- dashboard-widgets.el | 62 ++++++++++++++++++++++---------------------- dashboard.el | 15 ++++++----- 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index 2f1ac9a5..f99da0c7 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -42,8 +42,8 @@ to the specified width, with aspect ratio preserved." (defconst dashboard-banners-directory (concat (file-name-directory - (locate-library "dashboard")) - "/banners/")) + (locate-library "dashboard")) + "/banners/")) (defconst dashboard-banner-official-png (expand-file-name (concat dashboard-banners-directory "emacs.png")) @@ -57,10 +57,10 @@ to the specified width, with aspect ratio preserved." "Width of a banner.") (defvar dashboard-banner-logo-title "Welcome to Emacs!" - "Specify the startup banner.") + "Specify the startup banner.") (defvar dashboard-startup-banner 'official - "Specify the startup banner. + "Specify the startup banner. Default value is `official', it displays the Emacs logo. `logo' displays Emacs alternative logo. An integer value is the index of text @@ -112,17 +112,17 @@ Return entire list if `END' is omitted." (min len end))))) (defmacro dashboard-insert-shortcut (shortcut-char - search-label - &optional no-next-line) + search-label + &optional no-next-line) "Insert a shortcut SHORTCUT-CHAR for a given SEARCH-LABEL. Optionally, provide NO-NEXT-LINE to move the cursor forward a line." `(define-key dashboard-mode-map ,shortcut-char (lambda () - (interactive) - (unless (search-forward ,search-label (point-max) t) - (search-backward ,search-label (point-min) t)) - ,@(unless no-next-line - '((forward-line 1))) - (back-to-indentation)))) + (interactive) + (unless (search-forward ,search-label (point-max) t) + (search-backward ,search-label (point-min) t)) + ,@(unless no-next-line + '((forward-line 1))) + (back-to-indentation)))) (defun dashboard-append (msg &optional messagebuf) "Append MSG to dashboard buffer. @@ -157,7 +157,7 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (goto-char 0) (let ((margin (max 0 (floor (/ (- dashboard-banner-length banner-width) 2))))) (while (not (eobp)) - (insert (make-string margin ?\ )) + (insert (make-string margin ?\ )) (forward-line 1)))) (buffer-string)))) @@ -181,9 +181,9 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (insert-image spec) (insert "\n\n") (when title - (insert (make-string (max 0 (floor (/ (- dashboard-banner-length - (+ (length title) 1)) 2))) ?\ )) - (insert (format "%s\n\n" (propertize title 'face 'dashboard-banner-logo-title-face))))))) + (insert (make-string (max 0 (floor (/ (- dashboard-banner-length + (+ (length title) 1)) 2))) ?\ )) + (insert (format "%s\n\n" (propertize title 'face 'dashboard-banner-logo-title-face))))))) (defun dashboard-get-banner-path (index) "Return the full path to banner with index INDEX." @@ -196,7 +196,7 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (if (and (display-graphic-p) (image-type-available-p 'png)) dashboard-banner-official-png (dashboard-get-banner-path 1))) - ((eq 'logo dashboard-startup-banner) + ((eq 'logo dashboard-startup-banner) (if (and (display-graphic-p) (image-type-available-p 'png)) dashboard-banner-logo-png (dashboard-get-banner-path 1))) @@ -208,9 +208,9 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (display-graphic-p)) (if (file-exists-p dashboard-startup-banner) dashboard-startup-banner - (message (format "could not find banner %s" - dashboard-startup-banner)) - (dashboard-get-banner-path 1))) + (message (format "could not find banner %s" + dashboard-startup-banner)) + (dashboard-get-banner-path 1))) (t (dashboard-get-banner-path 1))))) (defun dashboard-insert-banner () @@ -220,7 +220,7 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (buffer-read-only nil)) (progn (when banner - (if (image-type-available-p (intern (file-name-extension banner))) + (if (image-type-available-p (intern (file-name-extension banner))) (dashboard-insert-image-banner banner) (dashboard-insert-ascii-banner-centered banner)))))) @@ -356,16 +356,16 @@ date part is considered." (org-map-entries (lambda () (let* ((schedule-time (org-get-scheduled-time (point))) - (deadline-time (org-get-deadline-time (point))) - (item (org-agenda-format-item - (format-time-string "%Y-%m-%d" schedule-time) - (org-get-heading t t) - (org-outline-level) - (org-get-category) - (org-get-tags) - t)) - (loc (point)) - (file (buffer-file-name))) + (deadline-time (org-get-deadline-time (point))) + (item (org-agenda-format-item + (format-time-string "%Y-%m-%d" schedule-time) + (org-get-heading t t) + (org-outline-level) + (org-get-category) + (org-get-tags) + t)) + (loc (point)) + (file (buffer-file-name))) (when (and (not (org-entry-is-done-p)) (or (and schedule-time (dashboard-date-due-p schedule-time due-date)) (and deadline-time (dashboard-date-due-p deadline-time due-date)))) diff --git a/dashboard.el b/dashboard.el index 92b0778b..837c76d3 100644 --- a/dashboard.el +++ b/dashboard.el @@ -105,11 +105,11 @@ "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)) - (max-line-length 0)) + (save-line nil) + (recentf-is-on (recentf-enabled-p)) + (origial-recentf-list recentf-list) + (dashboard-num-recents (or (cdr (assoc 'recents dashboard-items)) 0)) + ) ;; disable recentf mode, ;; so we don't flood the recent files list with org mode files ;; do this by making a copy of the part of the list we'll use @@ -118,13 +118,14 @@ ;; (this avoids many saves/loads that would result from ;; disabling/enabling recentf-mode) (if recentf-is-on - (setq recentf-list (seq-take recentf-list dashboard-num-recents))) + (setq recentf-list (seq-take recentf-list dashboard-num-recents)) + ) (when (or (not (eq dashboard-buffer-last-width (window-width))) (not buffer-exists)) (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) + (let ((buffer-read-only nil) (list-separator "\n\n")) (erase-buffer) (dashboard-insert-banner) From e81acaacfa671462fc2c3f5bcc9673805ef0cdb6 Mon Sep 17 00:00:00 2001 From: Jason Dufair Date: Fri, 22 Feb 2019 15:57:45 -0500 Subject: [PATCH 10/17] Reverse one bad reversal --- dashboard.el | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dashboard.el b/dashboard.el index 837c76d3..b15e3606 100644 --- a/dashboard.el +++ b/dashboard.el @@ -105,11 +105,11 @@ "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)) - ) + (save-line nil) + (recentf-is-on (recentf-enabled-p)) + (origial-recentf-list recentf-list) + (dashboard-num-recents (or (cdr (assoc 'recents dashboard-items)) 0)) + (max-line-length 0)) ;; disable recentf mode, ;; so we don't flood the recent files list with org mode files ;; do this by making a copy of the part of the list we'll use From a092fb8d73987942f9f86bbb848bf5eb33a8bb41 Mon Sep 17 00:00:00 2001 From: Jason Dufair Date: Fri, 22 Feb 2019 20:55:47 -0500 Subject: [PATCH 11/17] Whitespace cleanup. Small PR fixes --- dashboard-widgets.el | 164 +++++++++++++++++++++---------------------- dashboard.el | 31 ++++---- 2 files changed, 97 insertions(+), 98 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index f99da0c7..20b9af05 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -228,25 +228,25 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." ;; Section insertion ;; (defmacro dashboard-insert-section-list (section-name list action &rest rest) - "Insert a LIST of items with SECTION-NAME, expanding ACTION and passing REST to widget creation." - `(let ((max-line-length 0)) - (when (car ,list) - (mapc (lambda (el) - (let ((widget nil)) - (insert "\n ") - (setq widget - (widget-create 'push-button - :action ,action - :mouse-face 'highlight - :follow-link "\C-m" - :button-prefix "" - :button-suffix "" - :format "%[%t%]" - ,@rest)) - (setq max-line-length - (max max-line-length (length (widget-value-value-get widget)))))) - ,list)) - max-line-length)) + "Insert a LIST of items with SECTION-NAME, expanding ACTION and passing REST to widget creation." + `(let ((max-line-length 0)) + (when (car ,list) + (mapc (lambda (el) + (let ((widget nil)) + (insert "\n ") + (setq widget + (widget-create 'push-button + :action ,action + :mouse-face 'highlight + :follow-link "\C-m" + :button-prefix "" + :button-suffix "" + :format "%[%t%]" + ,@rest)) + (setq max-line-length + (max max-line-length (length (widget-value-value-get widget)))))) + ,list)) + max-line-length)) (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. @@ -254,16 +254,16 @@ ACTION is theaction taken when the user activates the widget button. SHORTCUT is the keyboard shortcut used to access the section. WIDGET-PARAMS are passed to the \"widget-create\" function. Show EMPTY-LIST-TEXT if no items in list" - `(progn - (dashboard-insert-heading ,section-name) - (when-let ((max-line-length - (dashboard-insert-section-list - ,section-name - (dashboard-subseq ,list 0 list-size) - ,action - ,@widget-params))) - (dashboard-insert-shortcut ,shortcut ,section-name) - max-line-length))) + `(progn + (dashboard-insert-heading ,section-name) + (when-let ((max-line-length + (dashboard-insert-section-list + ,section-name + (dashboard-subseq ,list 0 list-size) + ,action + ,@widget-params))) + (dashboard-insert-shortcut ,shortcut ,section-name) + max-line-length))) ;; ;; Recentf @@ -271,13 +271,13 @@ Show EMPTY-LIST-TEXT if no items in list" (defun dashboard-insert-recents (list-size) "Add the list of LIST-SIZE items from recently edited files." (recentf-mode) - (dashboard-insert-section - "Recent Files:" - recentf-list - list-size - "r" - `(lambda (&rest ignore) (find-file-existing ,el)) - (abbreviate-file-name el))) + (dashboard-insert-section + "Recent Files:" + recentf-list + list-size + "r" + `(lambda (&rest ignore) (find-file-existing ,el)) + (abbreviate-file-name el))) ;; ;; Bookmarks @@ -286,35 +286,35 @@ Show EMPTY-LIST-TEXT if no items in list" "Add the list of LIST-SIZE items of bookmarks." (require 'bookmark) (dashboard-insert-section - "Bookmarks:" - (dashboard-subseq (bookmark-all-names) - 0 list-size) - list-size - "m" - `(lambda (&rest ignore) (bookmark-jump ,el)) - (let ((file (bookmark-get-filename el))) - (if file - (format "%s - %s" el (abbreviate-file-name file)) - el)))) + "Bookmarks:" + (dashboard-subseq (bookmark-all-names) + 0 list-size) + list-size + "m" + `(lambda (&rest ignore) (bookmark-jump ,el)) + (let ((file (bookmark-get-filename el))) + (if file + (format "%s - %s" el (abbreviate-file-name file)) + el)))) ;; ;; Projectile ;; (defun dashboard-insert-projects (list-size) "Add the list of LIST-SIZE items of projects." - (projectile-mode) - (if (bound-and-true-p projectile-mode) - (progn - (projectile-load-known-projects) - (dashboard-insert-section - "Projects:" - (dashboard-subseq (projectile-relevant-known-projects) - 0 list-size) - list-size - "p" - `(lambda (&rest ignore) - (projectile-switch-project-by-name ,el)) - (abbreviate-file-name el))))) + (projectile-mode) + (if (bound-and-true-p projectile-mode) + (progn + (projectile-load-known-projects) + (dashboard-insert-section + "Projects:" + (dashboard-subseq (projectile-relevant-known-projects) + 0 list-size) + list-size + "p" + `(lambda (&rest ignore) + (projectile-switch-project-by-name ,el)) + (abbreviate-file-name el))))) ;; ;; Org Agenda @@ -377,22 +377,22 @@ date part is considered." filtered-entries)) (defun dashboard-insert-agenda (list-size) - "Add the list of LIST-SIZE items of agenda." - (let ((agenda (dashboard-get-agenda))) - (dashboard-insert-section - (or (and (boundp 'show-week-agenda-p) show-week-agenda-p "Agenda for the coming week:") - "Agenda for today:") - (or agenda '()) - list-size - "a" - `(lambda (&rest ignore) - (let ((buffer (find-file-other-window (nth 4 el)))) - (with-current-buffer buffer - (goto-char (nth 3 el))) - (switch-to-buffer buffer))) - (format "%s" (nth 0 el))) - (and (not agenda) - (insert "\n --- No items ---")))) + "Add the list of LIST-SIZE items of agenda." + (let ((agenda (dashboard-get-agenda))) + (dashboard-insert-section + (or (and (boundp 'show-week-agenda-p) show-week-agenda-p "Agenda for the coming week:") + "Agenda for today:") + (or agenda '()) + list-size + "a" + `(lambda (&rest ignore) + (let ((buffer (find-file-other-window (nth 4 el)))) + (with-current-buffer buffer + (goto-char (nth 3 el))) + (switch-to-buffer buffer))) + (format "%s" (nth 0 el))) + (and (not agenda) + (insert "\n --- No items ---")))) ;; ;; Registers @@ -400,13 +400,13 @@ date part is considered." (defun dashboard-insert-registers (list-size) "Add the list of LIST-SIZE items of registers." (require 'register) - (dashboard-insert-section - "Registers:" - register-alist - list-size - "e" - `(lambda (&rest ignore) (jump-to-register ,(car el))) - (format "%c - %s" (car el) (register-describe-oneline (car el))))) + (dashboard-insert-section + "Registers:" + register-alist + list-size + "e" + `(lambda (&rest ignore) (jump-to-register ,(car el))) + (format "%c - %s" (car el) (register-describe-oneline (car el))))) ;; Forward declartions for optional dependency to keep check-declare happy. diff --git a/dashboard.el b/dashboard.el index b15e3606..225b3989 100644 --- a/dashboard.el +++ b/dashboard.el @@ -125,7 +125,7 @@ (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) + (let ((buffer-read-only nil) (list-separator "\n\n")) (erase-buffer) (dashboard-insert-banner) @@ -133,28 +133,27 @@ (setq dashboard--section-starts nil) (mapc (lambda (els) (let* ((el (or (car-safe els) els)) - (list-size + (list-size (or (cdr-safe els) dashboard-items-default-length)) - (item-generator + (item-generator (cdr-safe (assoc el dashboard-item-generators)))) (add-to-list 'dashboard--section-starts (point)) (setq max-line-length - (max max-line-length (or (funcall item-generator list-size) 0))) + (max max-line-length (or (funcall item-generator list-size) 0))) (dashboard-insert-page-break))) - dashboard-items) - (if dashboard-center-content - (progn - (goto-char (car (last dashboard--section-starts))) - (let ((margin (floor (/ (- (window-width) max-line-length) 2)))) - (while (not (eobp)) - (and (not (eq ? (char-after))) - (insert (make-string margin ?\ ))) - (forward-line 1)))))) - (dashboard-mode) - (goto-char (point-min)))) + dashboard-items) + (when dashboard-center-content + (goto-char (car (last dashboard--section-starts))) + (let ((margin (floor (/ (- (window-width) max-line-length) 2)))) + (while (not (eobp)) + (and (not (eq ? (char-after))) + (insert (make-string margin ?\ ))) + (forward-line 1))))) + (dashboard-mode) + (goto-char (point-min)))) (if recentf-is-on - (setq recentf-list origial-recentf-list)))) + (setq recentf-list origial-recentf-list)))) (add-hook 'window-setup-hook (lambda () From 3fa9298c38b965262ca6d5ed24fabac7bd57fa12 Mon Sep 17 00:00:00 2001 From: Jason Dufair Date: Fri, 22 Feb 2019 21:29:43 -0500 Subject: [PATCH 12/17] Whitespace cleanup --- dashboard-widgets.el | 12 ++++++------ dashboard.el | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index a03ad4f4..32c81eea 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -273,8 +273,8 @@ Show EMPTY-LIST-TEXT if no items in list" (dashboard-subseq ,list 0 list-size) ,action ,@widget-params))) - (dashboard-insert-shortcut ,shortcut ,section-name) - max-line-length))) + (dashboard-insert-shortcut ,shortcut ,section-name) + max-line-length))) ;; ;; Recentf @@ -299,14 +299,14 @@ Show EMPTY-LIST-TEXT if no items in list" (dashboard-insert-section "Bookmarks:" (dashboard-subseq (bookmark-all-names) - 0 list-size) + 0 list-size) list-size "m" `(lambda (&rest ignore) (bookmark-jump ,el)) (let ((file (bookmark-get-filename el))) - (if file - (format "%s - %s" el (abbreviate-file-name file)) - el)))) + (if file + (format "%s - %s" el (abbreviate-file-name file)) + el)))) ;; ;; Projectile diff --git a/dashboard.el b/dashboard.el index 2cab7150..ae22f5b9 100644 --- a/dashboard.el +++ b/dashboard.el @@ -63,9 +63,9 @@ :group 'dashboard) (defcustom dashboard-center-content t - "Whether to center content within the window." - :type 'boolean - :group 'dashboard) + "Whether to center content within the window." + :type 'boolean + :group 'dashboard) (defconst dashboard-buffer-name "*dashboard*" "Dashboard's buffer name.") @@ -107,11 +107,11 @@ "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)) - (max-line-length 0)) + (save-line nil) + (recentf-is-on (recentf-enabled-p)) + (origial-recentf-list recentf-list) + (dashboard-num-recents (or (cdr (assoc 'recents dashboard-items)) 0)) + (max-line-length 0)) ;; disable recentf mode, ;; so we don't flood the recent files list with org mode files ;; do this by making a copy of the part of the list we'll use From d2ba70ea9364e276aed2be1836e05acd1de8fd3e Mon Sep 17 00:00:00 2001 From: Jason Dufair Date: Sat, 23 Feb 2019 08:17:52 -0500 Subject: [PATCH 13/17] Linter cleanup. Which also apparently doesn't like when-let --- dashboard-widgets.el | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index 32c81eea..b791cc51 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -255,7 +255,7 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." :format "%[%t%]" ,@rest)) (setq max-line-length - (max max-line-length (length (widget-value-value-get widget)))))) + (max max-line-length (length (widget-get widget :value)))))) ,list)) max-line-length)) @@ -267,14 +267,15 @@ WIDGET-PARAMS are passed to the \"widget-create\" function. Show EMPTY-LIST-TEXT if no items in list" `(progn (dashboard-insert-heading ,section-name) - (when-let ((max-line-length - (dashboard-insert-section-list - ,section-name - (dashboard-subseq ,list 0 list-size) - ,action - ,@widget-params))) - (dashboard-insert-shortcut ,shortcut ,section-name) - max-line-length))) + (let ((max-line-length (dashboard-insert-section-list + ,section-name + (dashboard-subseq ,list 0 list-size) + ,action + ,@widget-params))) + (if max-line-length + (progn + (dashboard-insert-shortcut ,shortcut ,section-name) + max-line-length))))) ;; ;; Recentf @@ -287,7 +288,7 @@ Show EMPTY-LIST-TEXT if no items in list" recentf-list list-size "r" - `(lambda (&rest ignore) (find-file-existing ,el)) + (lambda (&rest ignore) (find-file-existing el)) (abbreviate-file-name el))) ;; @@ -302,7 +303,7 @@ Show EMPTY-LIST-TEXT if no items in list" 0 list-size) list-size "m" - `(lambda (&rest ignore) (bookmark-jump ,el)) + (lambda (&rest ignore) (bookmark-jump el)) (let ((file (bookmark-get-filename el))) (if file (format "%s - %s" el (abbreviate-file-name file)) @@ -323,8 +324,7 @@ Show EMPTY-LIST-TEXT if no items in list" 0 list-size) list-size "p" - `(lambda (&rest ignore) - (projectile-switch-project-by-name ,el)) + (lambda (&rest ignore) (projectile-switch-project-by-name el)) (abbreviate-file-name el))))) ;; @@ -397,11 +397,11 @@ date part is considered." (or agenda '()) list-size "a" - `(lambda (&rest ignore) - (let ((buffer (find-file-other-window (nth 4 el)))) - (with-current-buffer buffer - (goto-char (nth 3 el))) - (switch-to-buffer buffer))) + (lambda (&rest ignore) + (let ((buffer (find-file-other-window (nth 4 el)))) + (with-current-buffer buffer + (goto-char (nth 3 el))) + (switch-to-buffer buffer))) (format "%s" (nth 0 el))) (and (not agenda) (insert "\n --- No items ---")))) @@ -417,7 +417,7 @@ date part is considered." register-alist list-size "e" - `(lambda (&rest ignore) (jump-to-register ,(car el))) + (lambda (&rest ignore) (jump-to-register (car el))) (format "%c - %s" (car el) (register-describe-oneline (car el))))) From e46ed6c83cd80f91e76c7d491bea7fefd3302f83 Mon Sep 17 00:00:00 2001 From: Jason Dufair Date: Sat, 23 Feb 2019 08:26:07 -0500 Subject: [PATCH 14/17] Documentation fixes --- dashboard-widgets.el | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index b791cc51..47b0f8c1 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -239,7 +239,7 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." ;; Section insertion ;; (defmacro dashboard-insert-section-list (section-name list action &rest rest) - "Insert a LIST of items with SECTION-NAME, expanding ACTION and passing REST to widget creation." + "Insert into SECTION-NAME a LIST of items, expanding ACTION and passing REST to widget creation." `(let ((max-line-length 0)) (when (car ,list) (mapc (lambda (el) @@ -261,10 +261,9 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (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. -ACTION is theaction taken when the user activates the widget button. SHORTCUT is the keyboard shortcut used to access the section. -WIDGET-PARAMS are passed to the \"widget-create\" function. -Show EMPTY-LIST-TEXT if no items in list" +ACTION is theaction taken when the user activates the widget button. +WIDGET-PARAMS are passed to the \"widget-create\" function." `(progn (dashboard-insert-heading ,section-name) (let ((max-line-length (dashboard-insert-section-list From e5c65bed7955937eb847e1814a2c65b160ceb1b1 Mon Sep 17 00:00:00 2001 From: Jason Dufair Date: Sat, 23 Feb 2019 08:29:26 -0500 Subject: [PATCH 15/17] Linter fixes --- dashboard-widgets.el | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index 47b0f8c1..d6f7ac41 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -287,7 +287,7 @@ WIDGET-PARAMS are passed to the \"widget-create\" function." recentf-list list-size "r" - (lambda (&rest ignore) (find-file-existing el)) + `(lambda (&rest ignore) (find-file-existing ,el)) (abbreviate-file-name el))) ;; @@ -302,7 +302,7 @@ WIDGET-PARAMS are passed to the \"widget-create\" function." 0 list-size) list-size "m" - (lambda (&rest ignore) (bookmark-jump el)) + `(lambda (&rest ignore) (bookmark-jump ,el)) (let ((file (bookmark-get-filename el))) (if file (format "%s - %s" el (abbreviate-file-name file)) @@ -323,7 +323,7 @@ WIDGET-PARAMS are passed to the \"widget-create\" function." 0 list-size) list-size "p" - (lambda (&rest ignore) (projectile-switch-project-by-name el)) + `(lambda (&rest ignore) (projectile-switch-project-by-name ,el)) (abbreviate-file-name el))))) ;; @@ -396,11 +396,11 @@ date part is considered." (or agenda '()) list-size "a" - (lambda (&rest ignore) - (let ((buffer (find-file-other-window (nth 4 el)))) - (with-current-buffer buffer - (goto-char (nth 3 el))) - (switch-to-buffer buffer))) + `(lambda (&rest ignore) + (let ((buffer (find-file-other-window (nth 4 ,el)))) + (with-current-buffer buffer + (goto-char (nth 3 ,el))) + (switch-to-buffer buffer))) (format "%s" (nth 0 el))) (and (not agenda) (insert "\n --- No items ---")))) From 450001ddea5292a25a89d37d7617223398bea026 Mon Sep 17 00:00:00 2001 From: Jason Dufair Date: Sun, 24 Feb 2019 15:57:48 -0500 Subject: [PATCH 16/17] Remove requirement for sections to calculate their max length --- dashboard-widgets.el | 47 +++++++++++++++++++------------------------- dashboard.el | 15 +++++++++++++- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index d6f7ac41..50559622 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -240,24 +240,20 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." ;; (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." - `(let ((max-line-length 0)) - (when (car ,list) - (mapc (lambda (el) - (let ((widget nil)) - (insert "\n ") - (setq widget - (widget-create 'push-button - :action ,action - :mouse-face 'highlight - :follow-link "\C-m" - :button-prefix "" - :button-suffix "" - :format "%[%t%]" - ,@rest)) - (setq max-line-length - (max max-line-length (length (widget-get widget :value)))))) - ,list)) - max-line-length)) + `(when (car ,list) + (mapc (lambda (el) + (let ((widget nil)) + (insert "\n ") + (setq widget + (widget-create 'push-button + :action ,action + :mouse-face 'highlight + :follow-link "\C-m" + :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. @@ -266,15 +262,12 @@ ACTION is theaction taken when the user activates the widget button. WIDGET-PARAMS are passed to the \"widget-create\" function." `(progn (dashboard-insert-heading ,section-name) - (let ((max-line-length (dashboard-insert-section-list - ,section-name - (dashboard-subseq ,list 0 list-size) - ,action - ,@widget-params))) - (if max-line-length - (progn - (dashboard-insert-shortcut ,shortcut ,section-name) - max-line-length))))) + (when (dashboard-insert-section-list + ,section-name + (dashboard-subseq ,list 0 list-size) + ,action + ,@widget-params) + (dashboard-insert-shortcut ,shortcut ,section-name)))) ;; ;; Recentf diff --git a/dashboard.el b/dashboard.el index ae22f5b9..0dce8727 100644 --- a/dashboard.el +++ b/dashboard.el @@ -103,6 +103,18 @@ (when next-section-start (goto-char next-section-start))))) +(defun dashboard-maximum-section-length () + "For the just-inserted section, calculate the length of the longest line." + (let ((max-line-length 0)) + (save-excursion + (dashboard-previous-section) + (while (not (eobp)) + (setq max-line-length + (max max-line-length + (- (line-end-position) (line-beginning-position)))) + (forward-line))) + max-line-length)) + (defun dashboard-insert-startupify-lists () "Insert the list of widgets into the buffer." (interactive) @@ -141,8 +153,9 @@ (item-generator (cdr-safe (assoc el dashboard-item-generators)))) (add-to-list 'dashboard--section-starts (point)) + (funcall item-generator list-size) (setq max-line-length - (max max-line-length (or (funcall item-generator list-size) 0))) + (max max-line-length (dashboard-maximum-section-length))) (dashboard-insert-page-break))) dashboard-items) (when dashboard-center-content From 634755a1e50941258051ad75e9867f9e7fa96dc2 Mon Sep 17 00:00:00 2001 From: Jason Dufair Date: Sun, 24 Feb 2019 16:11:16 -0500 Subject: [PATCH 17/17] Do not center content by default --- README.org | 2 +- dashboard.el | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.org b/README.org index 2339a3e0..23e45b3f 100644 --- a/README.org +++ b/README.org @@ -66,7 +66,7 @@ To update the banner or banner title ;; 1, 2 or 3 which displays one of the text banners ;; "path/to/your/image.png" which displays whatever image you would prefer -;; Content is centered by default. To left-justify, set +;; Content is not centered by default. To center, set (setq dashboard-center-content nil) #+END_SRC diff --git a/dashboard.el b/dashboard.el index 0dce8727..944e900e 100644 --- a/dashboard.el +++ b/dashboard.el @@ -62,7 +62,7 @@ "Settings that are used in the Dashboard" :group 'dashboard) -(defcustom dashboard-center-content t +(defcustom dashboard-center-content nil "Whether to center content within the window." :type 'boolean :group 'dashboard)