emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Add repeat-map for navigation commands
@ 2024-09-09 14:21 Visuwesh
  2024-09-09 16:53 ` Ihor Radchenko
  0 siblings, 1 reply; 7+ messages in thread
From: Visuwesh @ 2024-09-09 14:21 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 771 bytes --]

Ihor says:
> - visuwesh asked whether Org mode could have repeat maps for outline
>   navigation in Org mode (C-c C-n n n p n p ..., C-c C-f b f...)
>   - Such functionality has been added to outline-mode upstream
>   - Patches for Org mode equivalent are indeed welcome
>     - They do not even have to be the past weekend after the meetup
>       Any time will do ;)
>   - For now, we at least have speed keys as an alternative
>     https://orgmode.org/manual/Speed-Keys.html

Sorry for the month long delay.  I was busy with uni stuff so could not
find the time to invest into this properly.  I've attached a patch which
adds a repeat-map to org-keys.el but this pointed out that org-mode
lacks a org-up-heading command so I've resorted to using
outline-up-heading.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-repeat-mode-keymap-for-navigation-commands.patch --]
[-- Type: text/x-diff, Size: 1993 bytes --]

From 8b980efcd9497e395f4d82a1304267ae4426b00d Mon Sep 17 00:00:00 2001
From: Visuwesh <visuweshm@gmail.com>
Date: Mon, 9 Sep 2024 19:46:47 +0530
Subject: [PATCH] Add repeat-mode keymap for navigation commands

* org-keys.el (org-navigation-repeat-map): Add repeat-map to make
navigation easier when repeat-mode is turned on.
---
 lisp/org-keys.el | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/lisp/org-keys.el b/lisp/org-keys.el
index 1daedaae8..ec32d212d 100644
--- a/lisp/org-keys.el
+++ b/lisp/org-keys.el
@@ -462,6 +462,25 @@ (org-defkey org-mode-map (kbd "C-S-<left>") #'org-shiftcontrolleft)
 (org-defkey org-mode-map (kbd "C-S-<up>") #'org-shiftcontrolup)
 (org-defkey org-mode-map (kbd "C-S-<down>") #'org-shiftcontroldown)
 
+;;; Repeat-mode map.
+(defvar org-navigation-repeat-map (make-sparse-keymap)
+  "Repeat keymap for navigation commands.")
+(org-defkey org-navigation-repeat-map (kbd "b") #'org-backward-heading-same-level)
+(org-defkey org-navigation-repeat-map (kbd "C-b") #'org-backward-heading-same-level)
+(org-defkey org-navigation-repeat-map (kbd "f") #'org-forward-heading-same-level)
+(org-defkey org-navigation-repeat-map (kbd "C-f") #'org-forward-heading-same-level)
+(org-defkey org-navigation-repeat-map (kbd "n") #'org-next-visible-heading)
+(org-defkey org-navigation-repeat-map (kbd "C-n") #'org-next-visible-heading)
+(org-defkey org-navigation-repeat-map (kbd "p") #'org-previous-visible-heading)
+(org-defkey org-navigation-repeat-map (kbd "C-p") #'org-previous-visible-heading)
+(declare-function outline-up-heading "outline" (arg &optional invisible-ok))
+(org-defkey org-navigation-repeat-map (kbd "u") #'outline-up-heading)
+(org-defkey org-navigation-repeat-map (kbd "C-u") #'outline-up-heading)
+(map-keymap
+ (lambda (_key cmd)
+   (put cmd 'repeat-map 'org-navigation-repeat-map))
+ org-navigation-repeat-map)
+
 ;;;; Extra keys for TTY access.
 
 ;;  We only set them when really needed because otherwise the
-- 
2.45.2


[-- Attachment #3: Type: text/plain, Size: 228 bytes --]


Emacs  : GNU Emacs 31.0.50 (build 5, x86_64-pc-linux-gnu, X toolkit, cairo version 1.18.0, Xaw scroll bars)
 of 2024-08-15
Package: Org mode version 9.8-pre (release_9.7.8-713-g62cbac @ /home/viz/lib/emacs/straight/build/org/)

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] Add repeat-map for navigation commands
  2024-09-09 14:21 [PATCH] Add repeat-map for navigation commands Visuwesh
@ 2024-09-09 16:53 ` Ihor Radchenko
  2024-09-10  1:36   ` Karthik Chikmagalur
  2024-09-10  5:11   ` Visuwesh
  0 siblings, 2 replies; 7+ messages in thread
From: Ihor Radchenko @ 2024-09-09 16:53 UTC (permalink / raw)
  To: Visuwesh; +Cc: emacs-orgmode

Visuwesh <visuweshm@gmail.com> writes:

> Sorry for the month long delay.  I was busy with uni stuff so could not
> find the time to invest into this properly.

No problem.

> ... I've attached a patch which
> adds a repeat-map to org-keys.el but this pointed out that org-mode
> lacks a org-up-heading command so I've resorted to using
> outline-up-heading.

It is not the only one. But outline version should also work.

> From 8b980efcd9497e395f4d82a1304267ae4426b00d Mon Sep 17 00:00:00 2001
> From: Visuwesh <visuweshm@gmail.com>
> Date: Mon, 9 Sep 2024 19:46:47 +0530
> Subject: [PATCH] Add repeat-mode keymap for navigation commands
>
> * org-keys.el (org-navigation-repeat-map): Add repeat-map to make
> navigation easier when repeat-mode is turned on.

May you also add a news entry?
Ideally, we should also document this in the manual.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Add repeat-map for navigation commands
  2024-09-09 16:53 ` Ihor Radchenko
@ 2024-09-10  1:36   ` Karthik Chikmagalur
  2024-09-15 12:54     ` Ihor Radchenko
  2024-09-10  5:11   ` Visuwesh
  1 sibling, 1 reply; 7+ messages in thread
From: Karthik Chikmagalur @ 2024-09-10  1:36 UTC (permalink / raw)
  To: Ihor Radchenko, Visuwesh; +Cc: emacs-orgmode

>> From 8b980efcd9497e395f4d82a1304267ae4426b00d Mon Sep 17 00:00:00 2001
>> From: Visuwesh <visuweshm@gmail.com>
>> Date: Mon, 9 Sep 2024 19:46:47 +0530
>> Subject: [PATCH] Add repeat-mode keymap for navigation commands
>>
>> * org-keys.el (org-navigation-repeat-map): Add repeat-map to make
>> navigation easier when repeat-mode is turned on.
>
> May you also add a news entry?
> Ideally, we should also document this in the manual.

Do you think it makes sense to add repeat-maps for other next/previous
commands in Org, such as org-next-link and org-previous-link?  I've been
using this for a while (they don't use defvar-keymap as I wrote them a
while ago):

(defvar org-link-navigation-repeat-map
  (let ((map (make-sparse-keymap)))
    (define-key map (kbd "n") #'org-next-link)
    (define-key map (kbd "p") #'org-previous-link)
    (define-key map (kbd "v") #'org-link-preview) ;toggle preview for link at point
    map))

(map-keymap
 (lambda (_ cmd)
   (put cmd 'repeat-map 'org-link-navigation-repeat-map))
 org-link-navigation-repeat-map)

(defvar org-block-navigation-repeat-map
  (let ((map (make-sparse-keymap)))
    (define-key map (kbd "f") #'org-next-block)
    (define-key map (kbd "b") #'org-previous-block)
    map))

(put 'org-next-block     'repeat-map 'org-block-navigation-repeat-map)
(put 'org-previous-block 'repeat-map 'org-block-navigation-repeat-map)


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Add repeat-map for navigation commands
  2024-09-09 16:53 ` Ihor Radchenko
  2024-09-10  1:36   ` Karthik Chikmagalur
@ 2024-09-10  5:11   ` Visuwesh
  2024-09-15 13:08     ` Ihor Radchenko
  1 sibling, 1 reply; 7+ messages in thread
From: Visuwesh @ 2024-09-10  5:11 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

[திங்கள் செப்டம்பர் 09, 2024] Ihor Radchenko wrote:

>> ... I've attached a patch which
>> adds a repeat-map to org-keys.el but this pointed out that org-mode
>> lacks a org-up-heading command so I've resorted to using
>> outline-up-heading.
>
> It is not the only one. But outline version should also work.

I just realised that we would need a few defalias-es if we are going to
have outline commands in the repeat-map to avoid overriding
outline-navigation-repeat-map when one uses outline-up-heading in
outline-minor-mode or outline-mode.

[திங்கள் செப்டம்பர் 09, 2024] Karthik Chikmagalur wrote:

>>> From 8b980efcd9497e395f4d82a1304267ae4426b00d Mon Sep 17 00:00:00 2001
>>> From: Visuwesh <visuweshm@gmail.com>
>>> Date: Mon, 9 Sep 2024 19:46:47 +0530
>>> Subject: [PATCH] Add repeat-mode keymap for navigation commands
>>>
>>> * org-keys.el (org-navigation-repeat-map): Add repeat-map to make
>>> navigation easier when repeat-mode is turned on.
>>
>> May you also add a news entry?
>> Ideally, we should also document this in the manual.

I will add this along with the above in the next patch.

> Do you think it makes sense to add repeat-maps for other next/previous
> commands in Org, such as org-next-link and org-previous-link?  I've been
> using this for a while (they don't use defvar-keymap as I wrote them a
> while ago):
>
> (defvar org-link-navigation-repeat-map
>   (let ((map (make-sparse-keymap)))
>     (define-key map (kbd "n") #'org-next-link)
>     (define-key map (kbd "p") #'org-previous-link)
>     (define-key map (kbd "v") #'org-link-preview) ;toggle preview for link at point
>     map))
>
> (map-keymap
>  (lambda (_ cmd)
>    (put cmd 'repeat-map 'org-link-navigation-repeat-map))
>  org-link-navigation-repeat-map)
>
> (defvar org-block-navigation-repeat-map
>   (let ((map (make-sparse-keymap)))
>     (define-key map (kbd "f") #'org-next-block)
>     (define-key map (kbd "b") #'org-previous-block)
>     map))
>
> (put 'org-next-block     'repeat-map 'org-block-navigation-repeat-map)
> (put 'org-previous-block 'repeat-map 'org-block-navigation-repeat-map)

I also have a repeat-map for org-todo since I have
org-support-shift-select to t which makes changing the TODO when in the
body text quite inconvenient.

BTW, should we add C-n and friends to org-navigation-repeat-map or just
have n, p, etc.?  I personally find C-n in the repeat-map disruptive
since I usually want to move the cursor after jumping to a specific
heading, in which case C-n not being next-line is annoying.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Add repeat-map for navigation commands
  2024-09-10  1:36   ` Karthik Chikmagalur
@ 2024-09-15 12:54     ` Ihor Radchenko
  0 siblings, 0 replies; 7+ messages in thread
From: Ihor Radchenko @ 2024-09-15 12:54 UTC (permalink / raw)
  To: Karthik Chikmagalur; +Cc: Visuwesh, emacs-orgmode

Karthik Chikmagalur <karthikchikmagalur@gmail.com> writes:

> Do you think it makes sense to add repeat-maps for other next/previous
> commands in Org, such as org-next-link and org-previous-link?  I've been
> using this for a while (they don't use defvar-keymap as I wrote them a
> while ago):
>
> (defvar org-link-navigation-repeat-map
>   (let ((map (make-sparse-keymap)))
>     (define-key map (kbd "n") #'org-next-link)
>     (define-key map (kbd "p") #'org-previous-link)
>     (define-key map (kbd "v") #'org-link-preview) ;toggle preview for link at point
>     map))
>
> (map-keymap
>  (lambda (_ cmd)
>    (put cmd 'repeat-map 'org-link-navigation-repeat-map))
>  org-link-navigation-repeat-map)

Looks reasonable, yes.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Add repeat-map for navigation commands
  2024-09-10  5:11   ` Visuwesh
@ 2024-09-15 13:08     ` Ihor Radchenko
  2024-09-16 12:29       ` Visuwesh
  0 siblings, 1 reply; 7+ messages in thread
From: Ihor Radchenko @ 2024-09-15 13:08 UTC (permalink / raw)
  To: Visuwesh; +Cc: emacs-orgmode

Visuwesh <visuweshm@gmail.com> writes:

> BTW, should we add C-n and friends to org-navigation-repeat-map or just
> have n, p, etc.?  I personally find C-n in the repeat-map disruptive
> since I usually want to move the cursor after jumping to a specific
> heading, in which case C-n not being next-line is annoying.

+1 for less disruptive :)

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Add repeat-map for navigation commands
  2024-09-15 13:08     ` Ihor Radchenko
@ 2024-09-16 12:29       ` Visuwesh
  0 siblings, 0 replies; 7+ messages in thread
From: Visuwesh @ 2024-09-16 12:29 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 547 bytes --]

[ஞாயிறு செப்டம்பர் 15, 2024] Ihor Radchenko wrote:

> Visuwesh <visuweshm@gmail.com> writes:
>
>> BTW, should we add C-n and friends to org-navigation-repeat-map or just
>> have n, p, etc.?  I personally find C-n in the repeat-map disruptive
>> since I usually want to move the cursor after jumping to a specific
>> heading, in which case C-n not being next-line is annoying.
>
> +1 for less disruptive :)

Please find attached.  I tried my best to write the manual entry but it
still reads awkward.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-repeat-mode-keymap-for-navigation-commands.patch --]
[-- Type: text/x-diff, Size: 5105 bytes --]

From c66ff969e23d0d29746941383e5afa54d0e9e060 Mon Sep 17 00:00:00 2001
From: Visuwesh <visuweshm@gmail.com>
Date: Mon, 9 Sep 2024 19:46:47 +0530
Subject: [PATCH] Add repeat-mode keymap for navigation commands

* lisp/org-keys.el (org-up-heading): Add new alias for
outline-up-heading.
(org-mode-map): Remap outline-up-heading to the new alias.
(org-navigation-repeat-map, org-link-navigation-repeat-map)
(org-block-navigation-repeat-map): Add new repeat-maps to make
navigation easier.
* doc/org-manual.org (Repeating commands): Document the new feature in the manual.
* etc/ORG-NEWS (Some navigation commands can now be repeated): Announce it.
---
 doc/org-manual.org | 14 ++++++++++++++
 etc/ORG-NEWS       |  6 ++++++
 lisp/org-keys.el   | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index 9365c66b1..254764c31 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -21657,6 +21657,20 @@ of ~org-yank-dnd-method~.  Image files pasted this way also respect
 the value of ~org-yank-image-save-method~ when the action to perform
 is =attach=.
 
+** Repeating commands
+:PROPERTIES:
+:DESCRIPTION: Repeating navigation commands
+:END:
+
+#+cindex: repeat-mode, org-mode
+#+cindex: repeating navigation commands
+When ~repeat-mode~ is turned on, headline motion commands, link and
+block navigation commands by only pressing a single key.  For example,
+when navigation to the next headline using {{{kbd(C-c C-n)}}}, a
+repeat map is activated that lets you quickly execute headline motion
+commands.  When a key not in the map is pressed, it exits ~repeat-mode~
+and the command corresponding to the key is executed.
+
 * Hacking
 :PROPERTIES:
 :DESCRIPTION: How to hack your way around.
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 392788055..8acc2f6b4 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -77,6 +77,12 @@ You can now create links to =shortdoc= documentation groups for Emacs
 Lisp functions (see =M-x shortdoc-display-group=).  Requires Emacs 28
 or newer.
 
+*** Some navigation commands can now be repeated
+
+When ~repeat-mode~ is turned on, certain navigation can be repeated.
+These include the headline navigation commands, ~org-next-link~ and
+~org-previous-link~, and ~org-next-block~ and ~org-previous-block~.
+
 ** New and changed options
 
 # Chanes deadling with changing default values of customizations,
diff --git a/lisp/org-keys.el b/lisp/org-keys.el
index 1daedaae8..f6de753af 100644
--- a/lisp/org-keys.el
+++ b/lisp/org-keys.el
@@ -232,6 +232,7 @@ (declare-function org-up-element "org" ())
 (declare-function org-update-statistics-cookies "org" (all))
 (declare-function org-yank "org" (&optional arg))
 (declare-function orgtbl-ascii-plot "org-table" (&optional ask))
+(declare-function outline-up-heading "outline" (arg &optional invisible-ok))
 
 
 \f
@@ -409,6 +410,8 @@ (define-key org-mode-map [remap outline-next-visible-heading]
 (define-key org-mode-map [remap outline-previous-visible-heading]
   #'org-previous-visible-heading)
 (define-key org-mode-map [remap outline-show-children] #'org-fold-show-children)
+(defalias 'org-up-heading #'outline-up-heading)
+(define-key org-mode-map [remap outline-up-heading] #'org-up-heading)
 
 ;;;; Make `C-c C-x' a prefix key
 (org-defkey org-mode-map (kbd "C-c C-x") (make-sparse-keymap))
@@ -462,6 +465,37 @@ (org-defkey org-mode-map (kbd "C-S-<left>") #'org-shiftcontrolleft)
 (org-defkey org-mode-map (kbd "C-S-<up>") #'org-shiftcontrolup)
 (org-defkey org-mode-map (kbd "C-S-<down>") #'org-shiftcontroldown)
 
+;;; Repeat-mode map.
+(defvar org-navigation-repeat-map (make-sparse-keymap)
+  "Repeat keymap for navigation commands.")
+(org-defkey org-navigation-repeat-map (kbd "b") #'org-backward-heading-same-level)
+(org-defkey org-navigation-repeat-map (kbd "f") #'org-forward-heading-same-level)
+(org-defkey org-navigation-repeat-map (kbd "n") #'org-next-visible-heading)
+(org-defkey org-navigation-repeat-map (kbd "p") #'org-previous-visible-heading)
+(org-defkey org-navigation-repeat-map (kbd "u") #'org-up-heading)
+(map-keymap
+ (lambda (_key cmd)
+   (put cmd 'repeat-map 'org-navigation-repeat-map))
+ org-navigation-repeat-map)
+
+(defvar org-link-navigation-repeat-map (make-sparse-keymap)
+  "Repeat keymap for link navigation commands.")
+(org-defkey org-link-navigation-repeat-map (kbd "n") #'org-next-link)
+(org-defkey org-link-navigation-repeat-map (kbd "p") #'org-previous-link)
+(map-keymap
+ (lambda (_ cmd)
+   (put cmd 'repeat-map 'org-link-navigation-repeat-map))
+ org-link-navigation-repeat-map)
+
+(defvar org-block-navigation-repeat-map (make-sparse-keymap)
+  "Repeat keymap for block navigation commands.")
+(org-defkey org-block-navigation-repeat-map (kbd "f") #'org-next-block)
+(org-defkey org-block-navigation-repeat-map (kbd "b") #'org-previous-block)
+(map-keymap
+ (lambda (_ cmd)
+   (put cmd 'repeat-map 'org-block-navigation-repeat-map))
+ org-block-navigation-repeat-map)
+
 ;;;; Extra keys for TTY access.
 
 ;;  We only set them when really needed because otherwise the
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-09-16 12:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-09 14:21 [PATCH] Add repeat-map for navigation commands Visuwesh
2024-09-09 16:53 ` Ihor Radchenko
2024-09-10  1:36   ` Karthik Chikmagalur
2024-09-15 12:54     ` Ihor Radchenko
2024-09-10  5:11   ` Visuwesh
2024-09-15 13:08     ` Ihor Radchenko
2024-09-16 12:29       ` Visuwesh

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).