From eaf552988deb5eb3f005e9939c9b41aab70c5734 Mon Sep 17 00:00:00 2001 From: "B. Saifullah" Date: Fri, 16 Jul 2021 14:13:33 -0300 Subject: [PATCH 1/4] Allow section headings to be customized Section headings can now be given custom names through `dashboard-item-names'. Since this is done through overlays it doesn't break any function that expects the headings to have their default names. --- dashboard-widgets.el | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index 920ba0aa..6df5a8fd 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -262,6 +262,17 @@ value is nil, that item's shortcut is disbaled. See :type '(repeat (alist :key-type symbol :value-type string)) :group 'dashboard) +(defcustom dashboard-item-names nil + "Association list of item heading names. +When an item is nil or not present, the default name is used. +Will be of the form `(default-name . new-name)'. +Possible values for default-name are: +\"Recent Files:\" \"Bookmarks:\" \"Agenda for today:\", +\"Agenda for the coming week:\" \"Registers:\" \"Projects:\"." + :type '(alist :key-type string :value-type string) + :options '("Recent Files:" "Bookmarks:" "Agenda for today:" + "Agenda for the coming week:" "Registers:" "Projects:")) + (defcustom dashboard-items-default-length 20 "Length used for startup lists with otherwise unspecified bounds. Set to nil for unbounded." @@ -438,6 +449,8 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (insert " ")) (insert (propertize heading 'face 'dashboard-heading)) + (overlay-put (make-overlay (- (point) (length heading)) (point)) + 'display (or (cdr (assoc heading dashboard-item-names)) heading)) (when shortcut (insert (format " (%s)" shortcut)))) (defun dashboard-center-line (string) From ec131b260555ca4c6f378d442033dd31bd48ec86 Mon Sep 17 00:00:00 2001 From: "B. Saifullah" Date: Fri, 16 Jul 2021 14:36:34 -0300 Subject: [PATCH 2/4] Fix missing group. --- dashboard-widgets.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index 6df5a8fd..b12c7e8d 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -271,7 +271,8 @@ Possible values for default-name are: \"Agenda for the coming week:\" \"Registers:\" \"Projects:\"." :type '(alist :key-type string :value-type string) :options '("Recent Files:" "Bookmarks:" "Agenda for today:" - "Agenda for the coming week:" "Registers:" "Projects:")) + "Agenda for the coming week:" "Registers:" "Projects:") + :group 'dashboard) (defcustom dashboard-items-default-length 20 "Length used for startup lists with otherwise unspecified bounds. From bcd13781cb60764497a4a63bde4b1cf3f30605e2 Mon Sep 17 00:00:00 2001 From: "B. Saifullah" Date: Sat, 17 Jul 2021 15:16:02 -0300 Subject: [PATCH 3/4] Apply face to the overlay & add comment. Also fix the issue with `dashboard-center-content' by using the correct marker insertion type when making the overlay. --- dashboard-widgets.el | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index b12c7e8d..2d8ce000 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -450,8 +450,16 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (insert " ")) (insert (propertize heading 'face 'dashboard-heading)) - (overlay-put (make-overlay (- (point) (length heading)) (point)) - 'display (or (cdr (assoc heading dashboard-item-names)) heading)) + + ;; Turn the inserted heading into an overlay, so that we may freely change + ;; its name without breaking any of the functions that expect the default name. + ;; If there isn't a suitable entry in `dashboard-item-names', + ;; we fallback to using HEADING. In that case we still want it to be an + ;; overlay to maintain consistent behavior (such as the point movement) + ;; between modified and default headings. + (let ((ov (make-overlay (- (point) (length heading)) (point) nil t))) + (overlay-put ov 'display (or (cdr (assoc heading dashboard-item-names)) heading)) + (overlay-put ov 'face 'dashboard-heading)) (when shortcut (insert (format " (%s)" shortcut)))) (defun dashboard-center-line (string) From 922c2fa72de22fcc4770ec414883ba0090ae80a7 Mon Sep 17 00:00:00 2001 From: "B. Saifullah" Date: Sun, 18 Jul 2021 03:22:17 -0300 Subject: [PATCH 4/4] Update README with the new custom heading name feature. --- README.org | 7 +++++++ dashboard-widgets.el | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.org b/README.org index 8fa93d89..b38fdd61 100644 --- a/README.org +++ b/README.org @@ -99,6 +99,13 @@ To add your own custom widget is pretty easy, define your widget's callback func (add-to-list 'dashboard-items '(custom) t) #+END_SRC +To modify the widget heading name: +#+BEGIN_SRC elisp + (setq dashboard-item-names '(("Recent Files:" . "Recently opened files:") + ("Agenda for today:" . "Today's agenda:") + ("Agenda for the coming week:" . "Agenda:")) +#+END_SRC + To add icons to the widget headings and their items: #+BEGIN_SRC elisp (setq dashboard-set-heading-icons t) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index 2d8ce000..4b711866 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -450,7 +450,7 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (insert " ")) (insert (propertize heading 'face 'dashboard-heading)) - + ;; Turn the inserted heading into an overlay, so that we may freely change ;; its name without breaking any of the functions that expect the default name. ;; If there isn't a suitable entry in `dashboard-item-names',