From bdb83375cffeff5e03bb65c5cc63b341f5821b72 Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Sat, 26 Mar 2022 12:28:21 +0800 Subject: [PATCH 1/3] Add capability to navigation each section --- dashboard.el | 75 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 3 deletions(-) diff --git a/dashboard.el b/dashboard.el index 2ea7d647..fce951e0 100644 --- a/dashboard.el +++ b/dashboard.el @@ -47,6 +47,16 @@ (define-key map [mouse-1] 'dashboard-mouse-1) (define-key map (kbd "}") #'dashboard-next-section) (define-key map (kbd "{") #'dashboard-previous-section) + + (define-key map (kbd "1") #'dashboard-section-1) + (define-key map (kbd "2") #'dashboard-section-2) + (define-key map (kbd "3") #'dashboard-section-3) + (define-key map (kbd "4") #'dashboard-section-4) + (define-key map (kbd "5") #'dashboard-section-5) + (define-key map (kbd "6") #'dashboard-section-6) + (define-key map (kbd "7") #'dashboard-section-7) + (define-key map (kbd "8") #'dashboard-section-8) + (define-key map (kbd "9") #'dashboard-section-9) map) "Keymap for dashboard mode.") @@ -78,12 +88,12 @@ (defconst dashboard-buffer-name "*dashboard*" "Dashboard's buffer name.") -(defvar dashboard--section-starts nil - "List of section starting positions.") - (defvar dashboard-force-refresh nil "If non-nil, force refresh dashboard buffer.") +(defvar dashboard--section-starts nil + "List of section starting positions.") + (defun dashboard-previous-section () "Navigate back to previous section." (interactive) @@ -109,6 +119,65 @@ (when next-section-start (goto-char next-section-start)))) +(defun dashboard--goto-line (ln) + "Goto LN." + (goto-char (point-min)) (forward-line (1- ln))) + +(defun dashboard--current-section () + "Return section symbol in dashboard." + (save-excursion + (if (and (search-backward dashboard-page-separator nil t) + (search-forward dashboard-page-separator nil t)) + (let ((ln (thing-at-point 'line))) + (cond ((string-match-p "Recent Files:" ln) 'recents) + ((string-match-p "Bookmarks:" ln) 'bookmarks) + ((string-match-p "Projects:" ln) 'projects) + ((string-match-p "Agenda for " ln) 'agenda) + ((string-match-p "Registers:" ln) 'registers) + ((string-match-p "List Directories:" ln) 'ls-directories) + ((string-match-p "List Files:" ln) 'ls-files) + (t (user-error "Unknown section from dashboard")))) + (user-error "Failed searching dashboard section")))) + +(defun dashboard--section-lines () + "Return a list of integer represent the starting line number of each section." + (let (pb-lst) + (save-excursion + (goto-char (point-min)) + (while (search-forward dashboard-page-separator nil t) + (when (ignore-errors (dashboard--current-section)) + (push (line-number-at-pos) pb-lst)))) + (setq pb-lst (reverse pb-lst)) + pb-lst)) + +(defun dashboard--goto-section (index) + "Navigate to item section by INDEX." + (let* ((pg-lst (dashboard--section-lines)) + (items-id (1- index)) + (items-pg (nth items-id pg-lst)) + (items-len (length pg-lst))) + (when (and items-pg (< items-id items-len)) + (dashboard--goto-line items-pg)))) + +(defun dashboard-section-1 () + "Navigate to section 1." (interactive) (dashboard--goto-section 1)) +(defun dashboard-section-2 () + "Navigate to section 2." (interactive) (dashboard--goto-section 2)) +(defun dashboard-section-3 () + "Navigate to section 3." (interactive) (dashboard--goto-section 3)) +(defun dashboard-section-4 () + "Navigate to section 4." (interactive) (dashboard--goto-section 4)) +(defun dashboard-section-5 () + "Navigate to section 5." (interactive) (dashboard--goto-section 5)) +(defun dashboard-section-6 () + "Navigate to section 6." (interactive) (dashboard--goto-section 6)) +(defun dashboard-section-7 () + "Navigate to section 7." (interactive) (dashboard--goto-section 7)) +(defun dashboard-section-8 () + "Navigate to section 8." (interactive) (dashboard--goto-section 8)) +(defun dashboard-section-9 () + "Navigate to section 9." (interactive) (dashboard--goto-section 9)) + (defun dashboard-previous-line (arg) "Move point up and position it at that line’s item. Optional prefix ARG says how many lines to move; default is one line." From 6c812511cb43db3023c7551b53ba65549b2f4400 Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Sat, 26 Mar 2022 12:32:43 +0800 Subject: [PATCH 2/3] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4411e3fc..ae48a821 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how * Correct straight.el package count (#354) * Lazy load modules specify in dashboard buffer (#359) * Clean up zombie project for project.el (#363) +* Add capability to navigate each section (#365) ## 1.7.0 > Released Feb 21, 2020 From bb2b7f996c357ceeb9ef9c00f7a41562a8d8de2f Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Sat, 26 Mar 2022 12:32:57 +0800 Subject: [PATCH 3/3] Add header for each code section --- dashboard.el | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/dashboard.el b/dashboard.el index fce951e0..ac230942 100644 --- a/dashboard.el +++ b/dashboard.el @@ -94,6 +94,9 @@ (defvar dashboard--section-starts nil "List of section starting positions.") +;; +;; Navigation +;; (defun dashboard-previous-section () "Navigate back to previous section." (interactive) @@ -198,6 +201,9 @@ Optional prefix ARG says how many lines to move; default is one line." (forward-char (if (and arg (< arg 0)) -1 1))) (beginning-of-line-text)) +;; +;; Confirmation +;; (defun dashboard-return () "Hit return key in dashboard buffer." (interactive) @@ -226,6 +232,9 @@ Optional prefix ARG says how many lines to move; default is one line." (when (call-interactively #'widget-button-click) (setq track-mouse old-track-mouse)))) +;; +;; Insertion +;; (defun dashboard-maximum-section-length () "For the just-inserted section, calculate the length of the longest line." (let ((max-line-length 0))