diff --git a/dashboard-widgets.el b/dashboard-widgets.el index d81de6b..7074fe9 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -214,8 +214,8 @@ is displayed." (integer :tag "index of a text banner") (string :tag "a path to an image or text banner") (cons :tag "an image and text banner" - (string :tag "image banner path") - (string :tag "text banner path"))) + (string :tag "image banner path") + (string :tag "text banner path"))) :group 'dashboard) (defcustom dashboard-item-generators @@ -497,8 +497,7 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (let ((width 0)) (while (< (point) end) (let ((line-length (- (line-end-position) (line-beginning-position)))) - (if (< width line-length) - (setq width line-length))) + (setq width (max width line-length))) (forward-line 1)) (let ((prefix (propertize " " 'display `(space . (:align-to (- center ,(/ width 2))))))) (add-text-properties start end `(line-prefix ,prefix indent-prefix ,prefix)))))) @@ -526,45 +525,45 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (defun dashboard-choose-banner () "Return a plist specifying the chosen banner based on `dashboard-startup-banner'." - (pcase dashboard-startup-banner - ('nil nil) - ('official - (append (when (image-type-available-p 'png) - (list :image dashboard-banner-official-png)) - (list :text (dashboard-get-banner-path 1)))) - ('logo - (append (when (image-type-available-p 'png) - (list :image dashboard-banner-logo-png)) - (list :text (dashboard-get-banner-path 1)))) - ((pred integerp) - (list :text (dashboard-get-banner-path dashboard-startup-banner))) - ((pred stringp) - (pcase dashboard-startup-banner - ((pred (lambda (f) (not (file-exists-p f)))) - (message "could not find banner %s, use default instead" dashboard-startup-banner) - (list :text (dashboard-get-banner-path 1))) - ((pred (string-suffix-p ".txt")) - (list :text (if (file-exists-p dashboard-startup-banner) - dashboard-startup-banner - (message "could not find banner %s, use default instead" dashboard-startup-banner) - (dashboard-get-banner-path 1)))) - ((pred dashboard--image-supported-p) - (list :image dashboard-startup-banner - :text (dashboard-get-banner-path 1))) - (_ - (message "unsupported file type %s" (file-name-nondirectory dashboard-startup-banner)) - (list :text (dashboard-get-banner-path 1))))) - (`(,img . ,txt) - (list :image (if (dashboard--image-supported-p img) - img - (message "could not find banner %s, use default instead" img) - dashboard-banner-official-png) - :text (if (and (file-exists-p txt) (string-suffix-p ".txt" txt)) - txt - (message "could not find banner %s, use default instead" txt) - (dashboard-get-banner-path 1)))) - (_ - (message "unsupported banner config %s" dashboard-startup-banner)))) + (pcase dashboard-startup-banner + ('nil nil) + ('official + (append (when (image-type-available-p 'png) + (list :image dashboard-banner-official-png)) + (list :text (dashboard-get-banner-path 1)))) + ('logo + (append (when (image-type-available-p 'png) + (list :image dashboard-banner-logo-png)) + (list :text (dashboard-get-banner-path 1)))) + ((pred integerp) + (list :text (dashboard-get-banner-path dashboard-startup-banner))) + ((pred stringp) + (pcase dashboard-startup-banner + ((pred (lambda (f) (not (file-exists-p f)))) + (message "could not find banner %s, use default instead" dashboard-startup-banner) + (list :text (dashboard-get-banner-path 1))) + ((pred (string-suffix-p ".txt")) + (list :text (if (file-exists-p dashboard-startup-banner) + dashboard-startup-banner + (message "could not find banner %s, use default instead" dashboard-startup-banner) + (dashboard-get-banner-path 1)))) + ((pred dashboard--image-supported-p) + (list :image dashboard-startup-banner + :text (dashboard-get-banner-path 1))) + (_ + (message "unsupported file type %s" (file-name-nondirectory dashboard-startup-banner)) + (list :text (dashboard-get-banner-path 1))))) + (`(,img . ,txt) + (list :image (if (dashboard--image-supported-p img) + img + (message "could not find banner %s, use default instead" img) + dashboard-banner-official-png) + :text (if (and (file-exists-p txt) (string-suffix-p ".txt" txt)) + txt + (message "could not find banner %s, use default instead" txt) + (dashboard-get-banner-path 1)))) + (_ + (message "unsupported banner config %s" dashboard-startup-banner)))) (defun dashboard--type-is-gif-p (image-path) "Return if image is a gif. @@ -633,7 +632,8 @@ Argument IMAGE-PATH path to the image." (insert "\n\n") (add-text-properties start (point) '(cursor-intangible t inhibit-isearch t)))) (when dashboard-banner-logo-title - (dashboard-insert-center (propertize dashboard-banner-logo-title 'face 'dashboard-banner-logo-title) "\n\n")) + (dashboard-insert-center (propertize dashboard-banner-logo-title 'face 'dashboard-banner-logo-title)) + (insert "\n\n")) (dashboard-insert-navigator) (dashboard-insert-init-info)) diff --git a/dashboard.el b/dashboard.el index c86b7f6..3685eb9 100644 --- a/dashboard.el +++ b/dashboard.el @@ -249,11 +249,11 @@ Optional prefix ARG says how many lines to move; default is one line." (defun dashboard--section-list (section) "Return the list from SECTION." (cl-case section - (`recents recentf-list) - (`bookmarks (bookmark-all-names)) - (`projects (dashboard-projects-backend-load-projects)) + (`recents recentf-list) + (`bookmarks (bookmark-all-names)) + (`projects (dashboard-projects-backend-load-projects)) (`ls-directories (dashboard-ls--dirs)) - (`ls-files (dashboard-ls--files)) + (`ls-files (dashboard-ls--files)) (t (user-error "Unknown section for search: %s" section)))) (defun dashboard--current-item-in-path () @@ -367,6 +367,13 @@ Optional argument ARGS adviced function arguments." ;; ;; Insertion ;; +(defmacro dashboard--with-buffer (&rest body) + "Execute BODY in dashboard buffer." + (declare (indent 0)) + `(with-current-buffer (get-buffer-create dashboard-buffer-name) + (let (buffer-read-only) ,@body) + (current-buffer))) + (defun dashboard-maximum-section-length () "For the just-inserted section, calculate the length of the longest line." (let ((max-line-length 0)) @@ -388,45 +395,46 @@ Optional argument ARGS adviced function arguments." (max-line-length 0)) (when recentf-is-on (setq recentf-list (dashboard-subseq recentf-list dashboard-num-recents))) - (prog1 - (with-current-buffer (get-buffer-create dashboard-buffer-name) - (when (or dashboard-force-refresh (not (eq major-mode 'dashboard-mode))) - (let (buffer-read-only) - (erase-buffer) - (dashboard-insert-banner) - (setq dashboard--section-starts nil) - (mapc (lambda (els) - (let* ((el (or (car-safe els) els)) - (list-size - (or (cdr-safe els) - dashboard-items-default-length)) - (item-generator - (cdr-safe (assoc el dashboard-item-generators)))) - (push (point) dashboard--section-starts) - (funcall item-generator list-size) - (goto-char (point-max)) - (when recentf-is-on - (setq recentf-list origial-recentf-list)) - (setq max-line-length - (max max-line-length (dashboard-maximum-section-length))))) - dashboard-items) - (when dashboard-center-content - (dashboard-center-text - (if dashboard--section-starts - (car (last dashboard--section-starts)) - (point)) - (point-max))) - (insert dashboard-page-separator) - (save-excursion - (dolist (start dashboard--section-starts) - (goto-char start) - (insert dashboard-page-separator))) - (dashboard-insert-footer)) - (goto-char (point-min)) - (dashboard-mode)) - (current-buffer)) - (when recentf-is-on - (setq recentf-list origial-recentf-list))))) + (dashboard--with-buffer + (when (or dashboard-force-refresh (not (eq major-mode 'dashboard-mode))) + (erase-buffer) + (dashboard-insert-banner) + (setq dashboard--section-starts nil) + (mapc (lambda (els) + (let* ((el (or (car-safe els) els)) + (list-size + (or (cdr-safe els) + dashboard-items-default-length)) + (item-generator + (cdr-safe (assoc el dashboard-item-generators)))) + (push (point) dashboard--section-starts) + (funcall item-generator list-size) + (goto-char (point-max)) + ;; add a newline so the next section-name doesn't get include + ;; on the same line. + (insert "\n") + (when recentf-is-on + (setq recentf-list origial-recentf-list)) + (setq max-line-length + (max max-line-length (dashboard-maximum-section-length))))) + dashboard-items) + (when dashboard-center-content + (dashboard-center-text + (if dashboard--section-starts + (car (last dashboard--section-starts)) + (point)) + (point-max))) + (insert dashboard-page-separator) + (save-excursion + (dolist (start dashboard--section-starts) + (goto-char start) + (backward-delete-char 1) ; delete the newline we added previously + (insert dashboard-page-separator))) + (dashboard-insert-footer) + (goto-char (point-min)) + (dashboard-mode))) + (when recentf-is-on + (setq recentf-list origial-recentf-list)))) (defun dashboard-refresh-buffer (&rest _) "Refresh buffer."