From 95cd5279159048fde21999c9ebe4d4e5da090d94 Mon Sep 17 00:00:00 2001 From: maxc01 Date: Fri, 5 Jul 2019 20:54:26 +0200 Subject: [PATCH 1/7] add follow minor mode --- magit-todos.el | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/magit-todos.el b/magit-todos.el index 30f030b6e..b3becf87c 100644 --- a/magit-todos.el +++ b/magit-todos.el @@ -135,6 +135,18 @@ magit-status buffer.") See https://magit.vc/manual/magit/Creating-Sections.html for more details about how section maps work.") +(defvar magit-todos-follow-map + (let ((map (make-sparse-keymap))) + (define-key map (kbd "n") 'magit-todos-next-todo) + (define-key map (kbd "C-n") 'magit-todos-next-todo) + (define-key map (kbd "") 'magit-todos-next-todo) + + (define-key map (kbd "p") 'magit-todos-previous-todo) + (define-key map (kbd "C-p") 'magit-todos-previous-todo) + (define-key map (kbd "") 'magit-todos-previous-todo) + map) + "Keymap for `magit-todos-follow-mode'.") + (defvar-local magit-todos-show-filenames nil "Whether to show filenames next to to-do items. Set automatically depending on grouping.") @@ -365,6 +377,13 @@ This can be toggled locally in Magit buffers with command (remove-hook 'magit-status-sections-hook #'magit-todos--insert-todos) (remove-hook 'magit-status-mode-hook #'magit-todos--add-to-status-buffer-kill-hook))) +(define-minor-mode magit-todos-follow-mode + :init-value nil + :lighter " Follow" + :keymap magit-todos-follow-map + :group 'magit-todos + ) + (defun magit-todos-update () "Update the to-do list manually. Only necessary when option `magit-todos-update' is nil." @@ -403,6 +422,22 @@ If PEEK is non-nil, keep focus in status buffer window." (interactive) (magit-todos-jump-to-item :peek t)) +(defun magit-todos-next-todo () + "Peek at next item." + (interactive) + (magit-section-forward) + (let* ((item (oref (magit-current-section) value))) + (when (cl-struct-p item) + (magit-todos-peek-at-item)))) + +(defun magit-todos-previous-todo () + "Peek at previous item." + (interactive) + (magit-section-backward) + (let* ((item (oref (magit-current-section) value))) + (when (cl-struct-p item) + (magit-todos-peek-at-item)))) + ;;;;; Jump to section (magit-define-section-jumper magit-jump-to-todos "TODOs" todos) From 7df2213ebc3469b551f3f60f80b29d54450d13e0 Mon Sep 17 00:00:00 2001 From: maxc01 Date: Fri, 5 Jul 2019 21:04:43 +0200 Subject: [PATCH 2/7] update readme for magit-todos-follow-mode --- README.org | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.org b/README.org index 42c841f6e..2fc24e30c 100644 --- a/README.org +++ b/README.org @@ -99,6 +99,12 @@ Activate =magit-todos-mode=. Then open a Magit status buffer, or run ~magit-tod + @@html:@@j l@@html:@@ :: Open dedicated to-do list buffer. + @@html:@@RET@@html:@@ :: Show item at point, or open dedicated buffer if point is on top heading. + @@html:@@SPC@@html:@@ :: Peek at the item at point. + +Activate =magit-todos-follow-mode= in =magit-todos-mode=, use +@@html:@@n@@html:@@, @@html:@@C-n@@html:@@, +@@html:@@@@html:@@ to follow the file of the next todo item and use +@@html:@@p@@html:@@, @@html:@@C-p@@html:@@, +@@html:@@@@html:@@ to follow the file of the previous todo item. *** Commands From 50a5422a87db9d7758ad0d544fd26027bb765e98 Mon Sep 17 00:00:00 2001 From: maxc01 Date: Mon, 8 Jul 2019 13:27:53 +0200 Subject: [PATCH 3/7] remap magit-section-DIR instead of hard coding the key sequences --- magit-todos.el | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/magit-todos.el b/magit-todos.el index b3becf87c..b23883e01 100644 --- a/magit-todos.el +++ b/magit-todos.el @@ -137,13 +137,8 @@ details about how section maps work.") (defvar magit-todos-follow-map (let ((map (make-sparse-keymap))) - (define-key map (kbd "n") 'magit-todos-next-todo) - (define-key map (kbd "C-n") 'magit-todos-next-todo) - (define-key map (kbd "") 'magit-todos-next-todo) - - (define-key map (kbd "p") 'magit-todos-previous-todo) - (define-key map (kbd "C-p") 'magit-todos-previous-todo) - (define-key map (kbd "") 'magit-todos-previous-todo) + (define-key map [remap magit-section-forward] #'magit-todos-next-todo) + (define-key map [remap magit-section-backward] #'magit-todos-previous-todo) map) "Keymap for `magit-todos-follow-mode'.") @@ -379,10 +374,8 @@ This can be toggled locally in Magit buffers with command (define-minor-mode magit-todos-follow-mode :init-value nil - :lighter " Follow" :keymap magit-todos-follow-map - :group 'magit-todos - ) + :group 'magit-todos) (defun magit-todos-update () "Update the to-do list manually. From fbd701349e2870e1f7ca4bd5218928287b08169f Mon Sep 17 00:00:00 2001 From: maxc01 Date: Mon, 8 Jul 2019 13:29:58 +0200 Subject: [PATCH 4/7] check valid item in magit-todos-jump-to-item --- magit-todos.el | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/magit-todos.el b/magit-todos.el index b23883e01..aee7b9f94 100644 --- a/magit-todos.el +++ b/magit-todos.el @@ -401,14 +401,17 @@ Only necessary when option `magit-todos-update' is nil." "Show current item. If PEEK is non-nil, keep focus in status buffer window." (interactive) - (let* ((status-window (selected-window)) - (buffer (magit-todos--item-buffer item))) - (pop-to-buffer buffer) - (magit-todos--goto-item item) - (when (derived-mode-p 'org-mode) - (org-show-entry)) - (when peek - (select-window status-window)))) + (if-let* ((status-window (selected-window)) + (item (oref (magit-current-section) value)) + (is-valid-item (cl-struct-p item)) + (buffer (magit-todos--item-buffer item))) + (progn + (pop-to-buffer buffer) + (magit-todos--goto-item item) + (when (derived-mode-p 'org-mode) + (org-show-entry)) + (when peek + (select-window status-window))))) (defun magit-todos-peek-at-item () "Peek at current item." @@ -419,17 +422,13 @@ If PEEK is non-nil, keep focus in status buffer window." "Peek at next item." (interactive) (magit-section-forward) - (let* ((item (oref (magit-current-section) value))) - (when (cl-struct-p item) - (magit-todos-peek-at-item)))) + (magit-todos-peek-at-item)) (defun magit-todos-previous-todo () "Peek at previous item." (interactive) (magit-section-backward) - (let* ((item (oref (magit-current-section) value))) - (when (cl-struct-p item) - (magit-todos-peek-at-item)))) + (magit-todos-peek-at-item)) ;;;;; Jump to section From 51716d39a4d08958a611bf6075050761aa7cb57c Mon Sep 17 00:00:00 2001 From: maxc01 Date: Mon, 8 Jul 2019 13:40:17 +0200 Subject: [PATCH 5/7] update readme for magit-todo-follow-mode --- README.org | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.org b/README.org index 2fc24e30c..3b4f8d948 100644 --- a/README.org +++ b/README.org @@ -100,11 +100,9 @@ Activate =magit-todos-mode=. Then open a Magit status buffer, or run ~magit-tod + @@html:@@RET@@html:@@ :: Show item at point, or open dedicated buffer if point is on top heading. + @@html:@@SPC@@html:@@ :: Peek at the item at point. -Activate =magit-todos-follow-mode= in =magit-todos-mode=, use -@@html:@@n@@html:@@, @@html:@@C-n@@html:@@, -@@html:@@@@html:@@ to follow the file of the next todo item and use -@@html:@@p@@html:@@, @@html:@@C-p@@html:@@, -@@html:@@@@html:@@ to follow the file of the previous todo item. +Activate =magit-todos-follow-mode= in the to-do buffer, use: ++ @@html:@@n@@html:@@ :: Follow the next todo item and display the corresponding file ++ @@html:@@p@@html:@@ :: Follow the previous todo item and display the corresponding file *** Commands From 1f39d6b1e7fbe41d54343a029dcb6c501711bfe6 Mon Sep 17 00:00:00 2001 From: maxc01 Date: Tue, 9 Jul 2019 13:32:43 +0200 Subject: [PATCH 6/7] when on a non-todo item, show a message --- magit-todos.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/magit-todos.el b/magit-todos.el index aee7b9f94..01850a928 100644 --- a/magit-todos.el +++ b/magit-todos.el @@ -411,7 +411,8 @@ If PEEK is non-nil, keep focus in status buffer window." (when (derived-mode-p 'org-mode) (org-show-entry)) (when peek - (select-window status-window))))) + (select-window status-window))) + (message "Not a todo item."))) (defun magit-todos-peek-at-item () "Peek at current item." From 8a6ac0181bd5b9b358b928cf36f4c2609041f3a6 Mon Sep 17 00:00:00 2001 From: maxc01 Date: Tue, 9 Jul 2019 13:51:17 +0200 Subject: [PATCH 7/7] update README for magit-todos-follow-mode --- README.org | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.org b/README.org index 3b4f8d948..473450d8a 100644 --- a/README.org +++ b/README.org @@ -99,10 +99,12 @@ Activate =magit-todos-mode=. Then open a Magit status buffer, or run ~magit-tod + @@html:@@j l@@html:@@ :: Open dedicated to-do list buffer. + @@html:@@RET@@html:@@ :: Show item at point, or open dedicated buffer if point is on top heading. + @@html:@@SPC@@html:@@ :: Peek at the item at point. - -Activate =magit-todos-follow-mode= in the to-do buffer, use: -+ @@html:@@n@@html:@@ :: Follow the next todo item and display the corresponding file -+ @@html:@@p@@html:@@ :: Follow the previous todo item and display the corresponding file + +*When magit-todos-follow-mode is activated:* ++ @@html:@@n@@html:@@ :: Peek at the next item. ++ @@html:@@p@@html:@@ :: Peek at the previous item. + + *** Commands