Look up command binds dynamically in dashboard

Keys are no longer hard coded.

cc @UndeadKernel
This commit is contained in:
Henrik Lissner 2018-07-04 23:05:49 +02:00
parent a406b2d0c8
commit 0b1cb1bb48
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -37,41 +37,28 @@ Possible values:
:when (and (bound-and-true-p persp-mode) :when (and (bound-and-true-p persp-mode)
(file-exists-p (expand-file-name persp-auto-save-fname (file-exists-p (expand-file-name persp-auto-save-fname
persp-save-dir))) persp-save-dir)))
:key "SPC TAB R"
:face (:inherit (font-lock-keyword-face bold)) :face (:inherit (font-lock-keyword-face bold))
:action (+workspace/load-session)) :action +workspace/load-session)
("See agenda for this week" ("See agenda for this week"
:icon (all-the-icons-octicon "calendar" :face 'font-lock-keyword-face) :icon (all-the-icons-octicon "calendar" :face 'font-lock-keyword-face)
:when (fboundp 'org-agenda-list) :when (fboundp 'org-agenda-list)
:key "SPC o a" :action org-agenda-list)
:action (call-interactively #'org-agenda-list))
("Recently opened files" ("Recently opened files"
:icon (all-the-icons-octicon "file-text" :face 'font-lock-keyword-face) :icon (all-the-icons-octicon "file-text" :face 'font-lock-keyword-face)
:key "SPC f r" :action recentf-open-files)
:action
(call-interactively (or (command-remapping #'recentf-open-files)
#'recentf-open-files)))
("Open project" ("Open project"
:icon (all-the-icons-octicon "briefcase" :face 'font-lock-keyword-face) :icon (all-the-icons-octicon "briefcase" :face 'font-lock-keyword-face)
:key "SPC p p" :action projectile-switch-project)
:action
(call-interactively (or (command-remapping #'projectile-switch-project)
#'projectile-switch-project)))
("Jump to bookmark" ("Jump to bookmark"
:icon (all-the-icons-octicon "bookmark" :face 'font-lock-keyword-face) :icon (all-the-icons-octicon "bookmark" :face 'font-lock-keyword-face)
:key "SPC RET" :action bookmark-jump)
:action
(call-interactively (or (command-remapping #'bookmark-jump)
#'bookmark-jump)))
("Open private configuration" ("Open private configuration"
:icon (all-the-icons-octicon "tools" :face 'font-lock-keyword-face) :icon (all-the-icons-octicon "tools" :face 'font-lock-keyword-face)
:when (file-directory-p doom-private-dir) :when (file-directory-p doom-private-dir)
:key "SPC f p" :action +default/browse-config)
:action (doom-project-find-file doom-private-dir))
("Open user manual" ("Open user manual"
:icon (all-the-icons-octicon "book" :face 'font-lock-keyword-face) :icon (all-the-icons-octicon "book" :face 'font-lock-keyword-face)
:key "SPC h D" :action doom/open-manual))
:action (doom/open-manual)))
"An alist of menu buttons used by `doom-dashboard-widget-shortmenu'. Each "An alist of menu buttons used by `doom-dashboard-widget-shortmenu'. Each
element is a cons cell (LABEL . PLIST). LABEL is a string to display after the element is a cons cell (LABEL . PLIST). LABEL is a string to display after the
icon and before the key string. icon and before the key string.
@ -400,8 +387,10 @@ controlled by `+doom-dashboard-pwd-policy'."
(all-the-icons-default-adjust -0.02)) (all-the-icons-default-adjust -0.02))
(insert "\n") (insert "\n")
(dolist (section +doom-dashboard-menu-sections) (dolist (section +doom-dashboard-menu-sections)
(cl-destructuring-bind (label &key icon action when key face) section (cl-destructuring-bind (label &key icon action when face) section
(when (or (null when) (eval when t)) (when (and (fboundp action)
(or (null when)
(eval when t)))
(insert (insert
(+doom-dashboard--center (+doom-dashboard--center
(- +doom-dashboard--width 1) (- +doom-dashboard--width 1)
@ -411,16 +400,26 @@ controlled by `+doom-dashboard-pwd-policy'."
(with-temp-buffer (with-temp-buffer
(insert-text-button (insert-text-button
(propertize label 'face (or face 'font-lock-keyword-face)) (propertize label 'face (or face 'font-lock-keyword-face))
'action `(lambda (_) ,action) 'action
`(lambda (_)
(call-interactively (or (command-remapping #',action)
#',action)))
'follow-link t 'follow-link t
'help-echo label) 'help-echo label)
(format "%-37s" (buffer-string))) (format "%-37s" (buffer-string)))
;; Lookup command keys dynamically ;; Lookup command keys dynamically
(cond ((null key) "") (or (let ((maps (list global-map)))
((stringp key) (when (bound-and-true-p evil-normal-state-map)
(propertize key 'face 'font-lock-constant-face)) (push evil-motion-state-map maps)
((listp key) (push evil-normal-state-map maps))
(eval key t)))))) (when-let* ((key (where-is-internal action maps t)))
(propertize (with-temp-buffer
(save-excursion (insert (key-description key)))
(while (re-search-forward "<\\([^>]+\\)>" nil t)
(replace-match (upcase (substring (match-string 1) 0 3))))
(buffer-string))
'face 'font-lock-constant-face)))
""))))
(if (display-graphic-p) (if (display-graphic-p)
"\n\n" "\n\n"
"\n"))))))) "\n")))))))