From 8ae8c7b1223d0d387ab507d85e0a85ffa080fe9a Mon Sep 17 00:00:00 2001 From: Rudi Schlatte Date: Sun, 17 Mar 2019 16:44:43 +0100 Subject: [PATCH] Make line moving commands behave like `dired` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add `dashboard-previous-line`, `dashboard-next-line`. - When moving point up or down a line, move to the beginning of that line’s item. This lets us move to some line with `C-n`, then press `RET` to open that line’s item immediately. --- dashboard.el | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/dashboard.el b/dashboard.el index cae7107b..9dc4e68d 100644 --- a/dashboard.el +++ b/dashboard.el @@ -32,6 +32,10 @@ ;; Custom splash screen (defvar dashboard-mode-map (let ((map (make-sparse-keymap))) + (define-key map (kbd "C-p") 'dashboard-previous-line) + (define-key map (kbd "C-n") 'dashboard-next-line) + (define-key map (kbd "") 'dashboard-previous-line) + (define-key map (kbd "") 'dashboard-next-line) (define-key map [tab] 'widget-forward) (define-key map (kbd "C-i") 'widget-forward) (define-key map [backtab] 'widget-backward) @@ -102,6 +106,27 @@ (when next-section-start (goto-char next-section-start))))) +(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." + (interactive "^p") + (dashboard-next-line (- arg))) + +(defun dashboard-next-line (arg) + "Move point down and position it at that line’s item. +Optional prefix ARG says how many lines to move; default is one line." + ;; code heavily inspired by `dired-next-line' + (interactive "^p") + (let ((line-move-visual nil) + (goal-column nil)) + (line-move arg t)) + ;; We never want to move point into an invisible line. Dashboard doesn’t + ;; use invisible text currently but when it does we’re ready! + (while (and (invisible-p (point)) + (not (if (and arg (< arg 0)) (bobp) (eobp)))) + (forward-char (if (and arg (< arg 0)) -1 1))) + (beginning-of-line-text)) + (defun dashboard-maximum-section-length () "For the just-inserted section, calculate the length of the longest line." (let ((max-line-length 0))