-
-
Notifications
You must be signed in to change notification settings - Fork 141
Feature/center content #88
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
Changes from all commits
754df63
16e40fc
410ceab
1ca6573
9ce8c1a
0e86bf2
7ddd2ee
e24b81a
a25c654
e81acaa
a092fb8
4ab1b96
3fa9298
d2ba70e
e46ed6c
e5c65be
450001d
634755a
e423a93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -244,124 +244,91 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." | |
(dashboard-insert-ascii-banner-centered banner)))))) | ||
|
||
;; | ||
;; Recentf | ||
;; Section insertion | ||
;; | ||
(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 | ||
:button-prefix "" | ||
:button-suffix "" | ||
:format "%[%t%]" | ||
(abbreviate-file-name el))) | ||
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 ") | ||
(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. | ||
SHORTCUT is the keyboard shortcut used to access the section. | ||
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) | ||
(when (dashboard-insert-section-list | ||
,section-name | ||
(dashboard-subseq ,list 0 list-size) | ||
,action | ||
,@widget-params) | ||
(dashboard-insert-shortcut ,shortcut ,section-name)))) | ||
|
||
;; | ||
;; Recentf | ||
;; | ||
(defun dashboard-insert-recents (list-size) | ||
"Add the list of LIST-SIZE items from recently edited files." | ||
(recentf-mode) | ||
(when (dashboard-insert-recentf-list | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dashboard let's you configure widgets to include... this is why the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this still works as intended? When I remove, i.e. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry. I should add there is a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, the linter seems to have had trouble with |
||
"Recent Files:" | ||
(dashboard-subseq recentf-list 0 list-size)) | ||
(dashboard-insert-shortcut "r" "Recent Files:"))) | ||
|
||
(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 | ||
: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 (dashboard-insert-bookmark-list | ||
"Bookmarks:" | ||
(dashboard-subseq (bookmark-all-names) | ||
0 list-size)) | ||
(dashboard-insert-shortcut "m" "Bookmarks:"))) | ||
(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)))) | ||
|
||
;; | ||
;; 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 | ||
: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-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 | ||
;; | ||
(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 | ||
: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. | ||
|
||
|
@@ -422,41 +389,35 @@ date part is considered." | |
|
||
(defun dashboard-insert-agenda (list-size) | ||
"Add the list of LIST-SIZE items of agenda." | ||
(let ((agenda-time-string nil)) | ||
(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)))) | ||
(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 | ||
: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. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did this become a macro rather than a function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to have each section insert return its longest line so I could do centering calculations. Each of the section and section list inserts was similar and I didn't want to just boilerplate it in there. So I refactored the section and section list inserts into a macro and replaced the repetitive sections with calls to the macro. This should also make it easy to create new sections in the future with less boilerplate code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also it should make the intent of creating sections more clean and more declarative