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

Skip to content

Make shortcut function name respect to shortcut id #348

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 13 commits into from
Jan 17, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
* Add feature to sort agenda (#335)
* Update the CI process uasing Cask (#341)
* Add a changelog (#342)
* Make shortcut function name respect to shortcut id (#348)

## 1.7.0
> Released Feb 21, 2020
Expand Down
84 changes: 46 additions & 38 deletions dashboard-widgets.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;;; dashboard-widgets.el --- A startup screen extracted from Spacemacs -*- lexical-binding: t -*-

;; Copyright (c) 2016-2021 emacs-dashboard maintainers
;; Copyright (c) 2016-2022 emacs-dashboard maintainers
;;
;; Author : Rakan Al-Hneiti <[email protected]>
;; Maintainer : Jesús Martínez <[email protected]>
Expand Down Expand Up @@ -237,21 +237,23 @@ installed."
(const :tag "Use project.el" project-el))
:group 'dashboard)

(defcustom dashboard-items '((recents . 5)
(bookmarks . 5)
(agenda . 5))
(defcustom dashboard-items
'((recents . 5)
(bookmarks . 5)
(agenda . 5))
"Association list of items to show in the startup buffer.
Will be of the form `(list-type . list-size)'.
If nil it is disabled. Possible values for list-type are:
`recents' `bookmarks' `projects' `agenda' `registers'."
:type '(repeat (alist :key-type symbol :value-type integer))
:group 'dashboard)

(defcustom dashboard-item-shortcuts '((recents . "r")
(bookmarks . "m")
(projects . "p")
(agenda . "a")
(registers . "e"))
(defcustom dashboard-item-shortcuts
'((recents . "r")
(bookmarks . "m")
(projects . "p")
(agenda . "a")
(registers . "e"))
"Association list of items and their corresponding shortcuts.
Will be of the form `(list-type . keys)' as understood by
`(kbd keys)'. If nil, shortcuts are disabled. If an entry's
Expand All @@ -278,11 +280,12 @@ Set to nil for unbounded."
:type 'integer
:group 'dashboard)

(defcustom dashboard-heading-icons '((recents . "history")
(bookmarks . "bookmark")
(agenda . "calendar")
(projects . "rocket")
(registers . "database"))
(defcustom dashboard-heading-icons
'((recents . "history")
(bookmarks . "bookmark")
(agenda . "calendar")
(projects . "rocket")
(registers . "database"))
"Association list for the icons of the heading sections.
Will be of the form `(list-type . icon-name-string)`.
If nil it is disabled. Possible values for list-type are:
Expand Down Expand Up @@ -366,35 +369,35 @@ If nil it is disabled. Possible values for list-type are:
(let ((len (length seq)))
(butlast seq (- len (min len end)))))

(defun dashboard-get-shortcut-name (item)
"Get the shortcut name to be used for ITEM."
(let ((elem (rassoc item dashboard-item-shortcuts)))
(and elem (car elem))))

(defun dashboard-get-shortcut (item)
"Get the shortcut to be used for ITEM."
(let ((elem (assq item dashboard-item-shortcuts)))
(and elem (cdr elem))))

(defmacro dashboard-insert-shortcut (shortcut-char
(defmacro dashboard-insert-shortcut (shortcut-id
shortcut-char
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."
(let* (;; Ensure punctuation and upper case in search string is not
;; used to construct the `defun'
(name (downcase (replace-regexp-in-string
"[[:punct:]]+" "" (format "%s" search-label) nil nil nil)))
(name (downcase (replace-regexp-in-string "[[:punct:]]+" "" (format "%s" search-label))))
;; Ensure whitespace in e.g. "recent files" is replaced with dashes.
(sym (intern (format "dashboard-jump-to-%s" (replace-regexp-in-string
"[[:blank:]]+" "-" name nil nil nil)))))
(sym (intern (format "dashboard-jump-to-%s" shortcut-id))))
`(progn
(eval-when-compile (defvar dashboard-mode-map))
(defun ,sym nil
,(concat
"Jump to "
name
". This code is dynamically generated in `dashboard-insert-shortcut'.")
,(concat "Jump to " name ". This code is dynamically generated in `dashboard-insert-shortcut'.")
(interactive)
(unless (search-forward ,search-label (point-max) t)
(search-backward ,search-label (point-min) t))
,@(unless no-next-line
'((forward-line 1)))
,@(unless no-next-line '((forward-line 1)))
(back-to-indentation))
(eval-after-load 'dashboard
(define-key dashboard-mode-map ,shortcut-char ',sym)))))
Expand Down Expand Up @@ -616,22 +619,22 @@ Argument IMAGE-PATH path to the image."
(insert "\n"))
(insert "\n")))

(defmacro dashboard-insert-section (section-name list list-size shortcut action &rest widget-params)
(defmacro dashboard-insert-section (section-name list list-size shortcut-id shortcut-char 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.
SHORTCUT-CHAR 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
(if (and ,list ,shortcut dashboard-show-shortcuts) ,shortcut))
(if (and ,list ,shortcut-char dashboard-show-shortcuts) ,shortcut-char))
(if ,list
(when (and (dashboard-insert-section-list
,section-name
(dashboard-subseq ,list ,list-size)
,action
,@widget-params)
,shortcut)
(dashboard-insert-shortcut ,shortcut ,section-name))
,shortcut-id ,shortcut-char)
(dashboard-insert-shortcut ,shortcut-id ,shortcut-char ,section-name))
(insert (propertize "\n --- No items ---" 'face 'dashboard-no-items-face)))))

;;
Expand Down Expand Up @@ -808,21 +811,21 @@ WIDGET-PARAMS are passed to the \"widget-create\" function."
(let ((len-item (cdr (assoc type dashboard-items))) (count 0) (align-length -1)
len-list base)
(cl-case type
(recents
(`recents
(require 'recentf)
(setq len-list (length recentf-list))
(while (and (< count len-item) (< count len-list))
(setq base (nth count recentf-list)
align-length (max align-length (length (dashboard-f-filename base))))
(cl-incf count)))
(bookmarks
(`bookmarks
(let ((bookmarks-lst (bookmark-all-names)))
(setq len-list (length bookmarks-lst))
(while (and (< count len-item) (< count len-list))
(setq base (nth count bookmarks-lst)
align-length (max align-length (length base)))
(cl-incf count))))
(projects
(`projects
(let ((projects-lst (dashboard-projects-backend-load-projects)))
(setq len-list (length projects-lst))
(while (and (< count len-item) (< count len-list))
Expand Down Expand Up @@ -863,8 +866,9 @@ WIDGET-PARAMS are passed to the \"widget-create\" function."
"Recent Files:"
(dashboard-shorten-paths recentf-list 'dashboard-recentf-alist 'recents)
list-size
'recents
(dashboard-get-shortcut 'recents)
`(lambda (&rest ignore)
`(lambda (&rest _)
(find-file-existing (dashboard-expand-path-alist ,el dashboard-recentf-alist)))
(let* ((file (dashboard-expand-path-alist el dashboard-recentf-alist))
(filename (dashboard-f-filename file))
Expand Down Expand Up @@ -906,8 +910,9 @@ WIDGET-PARAMS are passed to the \"widget-create\" function."
"Bookmarks:"
(dashboard-subseq (bookmark-all-names) list-size)
list-size
'bookmarks
(dashboard-get-shortcut 'bookmarks)
`(lambda (&rest ignore) (bookmark-jump ,el))
`(lambda (&rest _) (bookmark-jump ,el))
(if-let* ((filename el)
(path (bookmark-get-filename el))
(path-shorten (dashboard-shorten-path path 'bookmarks)))
Expand Down Expand Up @@ -963,8 +968,9 @@ switch to."
(dashboard-subseq (dashboard-projects-backend-load-projects) list-size)
'dashboard-projects-alist 'projects)
list-size
'projects
(dashboard-get-shortcut 'projects)
`(lambda (&rest ignore)
`(lambda (&rest _)
(funcall (dashboard-projects-backend-switch-function)
(dashboard-expand-path-alist ,el dashboard-projects-alist)))
(let* ((file (dashboard-expand-path-alist el dashboard-projects-alist))
Expand Down Expand Up @@ -1222,8 +1228,9 @@ If both attributes are nil or equals the next strategy in `STRATEGIES' is used t
"Agenda for today:")
(dashboard-agenda--sorted-agenda)
list-size
'agenda
(dashboard-get-shortcut 'agenda)
`(lambda (&rest ignore)
`(lambda (&rest _)
(let ((buffer (find-file-other-window (nth 2 ',el))))
(with-current-buffer buffer
(goto-char (nth 1 ',el))
Expand All @@ -1240,8 +1247,9 @@ If both attributes are nil or equals the next strategy in `STRATEGIES' is used t
"Registers:"
register-alist
list-size
'registers
(dashboard-get-shortcut 'registers)
(lambda (&rest _ignore) (jump-to-register (car el)))
(lambda (&rest _) (jump-to-register (car el)))
(format "%c - %s" (car el) (register-describe-oneline (car el)))))

(provide 'dashboard-widgets)
Expand Down
2 changes: 1 addition & 1 deletion dashboard.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;;; dashboard.el --- A startup screen extracted from Spacemacs -*- lexical-binding: t -*-

;; Copyright (c) 2016-2021 emacs-dashboard maintainers
;; Copyright (c) 2016-2022 emacs-dashboard maintainers
;;
;; Author : Rakan Al-Hneiti <[email protected]>
;; Maintainer : Jesús Martínez <[email protected]>
Expand Down