emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [RFC] [PATCH] Introduce org-specific functions for (next/previous)-visible-heading
@ 2015-01-19  5:14 Aaron Ecay
  2015-01-19 17:58 ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Aaron Ecay @ 2015-01-19  5:14 UTC (permalink / raw)
  To: Org-mode

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

Hello,

By default, org uses outline-next-visible-heading and the -previous-
variant for the C-c C-n and C-c C-p keys, which means these commands
stop on inline tasks (since they don’t know to skip them).  This seems
incorrect.

The attached patch adds inlinetask-aware org functions for these keys.
Comments are welcome.

Thanks,

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-new-functions-to-move-to-the-next-prev-headline-.patch --]
[-- Type: text/x-diff, Size: 5994 bytes --]

From e3a61ab42c6e3d411a955473535bac80d69e9d7e Mon Sep 17 00:00:00 2001
From: Aaron Ecay <aaronecay@gmail.com>
Date: Sun, 18 Jan 2015 23:57:55 -0500
Subject: [PATCH] Add new functions to move to the next/prev headline skipping
 inline tasks.

* lisp/org.el (org-next-visible-heading):
(org-previous-visible-heading): New functions.
(org-speed-commands-default, org-mode-map): Use them.
---
 lisp/org.el | 67 +++++++++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 45 insertions(+), 22 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 1222a69..2e0335c 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -19420,34 +19420,38 @@ boundaries."
 (define-key org-mode-map [remap outline-promote] 'org-promote-subtree)
 (define-key org-mode-map [remap outline-demote] 'org-demote-subtree)
 (define-key org-mode-map [remap outline-insert-heading] 'org-ctrl-c-ret)
+(define-key org-mode-map [remap outline-next-visible-heading]
+  'org-next-visible-heading)
+(define-key org-mode-map [remap outline-previous-visible-heading]
+  'org-previous-visible-heading)
 
 ;; Outline functions from `outline-mode-prefix-map' that can not
 ;; be remapped in Org:
-;;
+
 ;; - the column "key binding" shows whether the Outline function is still
 ;;   available in Org mode on the same key that it has been bound to in
 ;;   Outline mode:
 ;;   - "overridden": key used for a different functionality in Org mode
 ;;   - else: key still bound to the same Outline function in Org mode
-;;
-;; | Outline function                   | key binding | Org replacement       |
-;; |------------------------------------+-------------+-----------------------|
-;; | `outline-next-visible-heading'     | `C-c C-n'   | still same function   |
-;; | `outline-previous-visible-heading' | `C-c C-p'   | still same function   |
-;; | `outline-up-heading'               | `C-c C-u'   | still same function   |
-;; | `outline-move-subtree-up'          | overridden  | better: org-shiftup   |
-;; | `outline-move-subtree-down'        | overridden  | better: org-shiftdown |
-;; | `show-entry'                       | overridden  | no replacement        |
-;; | `show-children'                    | `C-c C-i'   | visibility cycling    |
-;; | `show-branches'                    | `C-c C-k'   | still same function   |
-;; | `show-subtree'                     | overridden  | visibility cycling    |
-;; | `show-all'                         | overridden  | no replacement        |
-;; | `hide-subtree'                     | overridden  | visibility cycling    |
-;; | `hide-body'                        | overridden  | no replacement        |
-;; | `hide-entry'                       | overridden  | visibility cycling    |
-;; | `hide-leaves'                      | overridden  | no replacement        |
-;; | `hide-sublevels'                   | overridden  | no replacement        |
-;; | `hide-other'                       | overridden  | no replacement        |
+
+;; | Outline function                   | key binding | Org replacement          |
+;; |------------------------------------+-------------+--------------------------|
+;; | `outline-next-visible-heading'     | `C-c C-n'   | better: skip inlinetasks |
+;; | `outline-previous-visible-heading' | `C-c C-p'   | better: skip inlinetasks |
+;; | `outline-up-heading'               | `C-c C-u'   | still same function      |
+;; | `outline-move-subtree-up'          | overridden  | better: org-shiftup      |
+;; | `outline-move-subtree-down'        | overridden  | better: org-shiftdown    |
+;; | `show-entry'                       | overridden  | no replacement           |
+;; | `show-children'                    | `C-c C-i'   | visibility cycling       |
+;; | `show-branches'                    | `C-c C-k'   | still same function      |
+;; | `show-subtree'                     | overridden  | visibility cycling       |
+;; | `show-all'                         | overridden  | no replacement           |
+;; | `hide-subtree'                     | overridden  | visibility cycling       |
+;; | `hide-body'                        | overridden  | no replacement           |
+;; | `hide-entry'                       | overridden  | visibility cycling       |
+;; | `hide-leaves'                      | overridden  | no replacement           |
+;; | `hide-sublevels'                   | overridden  | no replacement           |
+;; | `hide-other'                       | overridden  | no replacement           |
 
 ;; Make `C-c C-x' a prefix key
 (org-defkey org-mode-map "\C-c\C-x" (make-sparse-keymap))
@@ -19687,8 +19691,8 @@ boundaries."
 (defconst org-speed-commands-default
   '(
     ("Outline Navigation")
-    ("n" . (org-speed-move-safe 'outline-next-visible-heading))
-    ("p" . (org-speed-move-safe 'outline-previous-visible-heading))
+    ("n" . (org-speed-move-safe 'org-next-visible-heading))
+    ("p" . (org-speed-move-safe 'org-previous-visible-heading))
     ("f" . (org-speed-move-safe 'org-forward-heading-same-level))
     ("b" . (org-speed-move-safe 'org-backward-heading-same-level))
     ("F" . org-next-block)
@@ -24090,6 +24094,25 @@ Stop at the first and last subheadings of a superior heading."
   (interactive "p")
   (org-forward-heading-same-level (if arg (- arg) -1) invisible-ok))
 
+(defun org-next-visible-heading (arg)
+  (interactive "p")
+  (if (< arg 0)
+      (beginning-of-line)
+    (end-of-line))
+  (let ((sign
+	 ;; Taken from `cl-signum'
+	 (cond ((> arg 0) 1) ((< arg 0) -1) (t (error "Should not happen")))))
+    (setq arg (abs arg))
+    (dotimes (_i arg)
+      (outline-next-visible-heading sign)
+      (when (featurep 'org-inlinetask)
+	(while (org-inlinetask-in-task-p)
+	  (outline-next-visible-heading sign))))))
+
+(defun org-previous-visible-heading (arg)
+  (interactive "p")
+  (org-next-visible-heading (- arg)))
+
 (defun org-next-block (arg &optional backward block-regexp)
   "Jump to the next block.
 With a prefix argument ARG, jump forward ARG many source blocks.
-- 
2.2.2


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

-- 
Aaron Ecay

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

* Re: [RFC] [PATCH] Introduce org-specific functions for (next/previous)-visible-heading
  2015-01-19  5:14 [RFC] [PATCH] Introduce org-specific functions for (next/previous)-visible-heading Aaron Ecay
@ 2015-01-19 17:58 ` Nicolas Goaziou
  2015-01-19 21:45   ` Andreas Leha
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Goaziou @ 2015-01-19 17:58 UTC (permalink / raw)
  To: Org-mode

Hello,

Aaron Ecay <aaronecay@gmail.com> writes:

> By default, org uses outline-next-visible-heading and the -previous-
> variant for the C-c C-n and C-c C-p keys, which means these commands
> stop on inline tasks (since they don’t know to skip them).  This seems
> incorrect.

Are you sure? This is a way to move to the next inline task (which is
some kind of headline). How do you move to it otherwise?

> The attached patch adds inlinetask-aware org functions for these keys.
> Comments are welcome.

You don't need to implement anything new, actually. If you need to
ignore inlinetasks for something, just wrap it within
`org-with-limited-levels' macro:

  (org-with-limited-levels (outline-next-visible-heading))


Regards,

-- 
Nicolas Goaziou

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

* Re: [RFC] [PATCH] Introduce org-specific functions for (next/previous)-visible-heading
  2015-01-19 17:58 ` Nicolas Goaziou
@ 2015-01-19 21:45   ` Andreas Leha
  2015-01-19 21:56     ` Rasmus
  0 siblings, 1 reply; 6+ messages in thread
From: Andreas Leha @ 2015-01-19 21:45 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> Hello,
>
> Aaron Ecay <aaronecay@gmail.com> writes:
>
>> By default, org uses outline-next-visible-heading and the -previous-
>> variant for the C-c C-n and C-c C-p keys, which means these commands
>> stop on inline tasks (since they don’t know to skip them).  This seems
>> incorrect.
>
> Are you sure? This is a way to move to the next inline task (which is
> some kind of headline). How do you move to it otherwise?

I agree with Aaron.  Actually I have written a message about that exact
topic (without a patch, though) already last year -- but that did not
get through, as it seems.

I use inline-tasks extensively (and map them to todonotes in the pdf
export).  And I am always surprised to end up at an inline-task when I
navigate the document.

If I need to find the next inline task I can always search for a lot
of *'s.

>
>> The attached patch adds inlinetask-aware org functions for these keys.
>> Comments are welcome.
>
> You don't need to implement anything new, actually. If you need to
> ignore inlinetasks for something, just wrap it within
> `org-with-limited-levels' macro:
>
>   (org-with-limited-levels (outline-next-visible-heading))

That wrapper is handy and works like a charm.  Thanks.

But I'd still argue that the default behaviour should be to skip inline
tasks for all navigation commands in org.

Regards,
Andreas

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

* Re: [RFC] [PATCH] Introduce org-specific functions for (next/previous)-visible-heading
  2015-01-19 21:45   ` Andreas Leha
@ 2015-01-19 21:56     ` Rasmus
  2015-01-20 12:00       ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Rasmus @ 2015-01-19 21:56 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:

> But I'd still argue that the default behaviour should be to skip inline
> tasks for all navigation commands in org.

I use inlinetasks in a similar way to Andreas: i.e. as TODO-notes in my
ongoing work.

To *me*, inlinetasks have got nothing to do with headlines (the syntax is
unfortunate, especially for people who write Org without org-mode).

Thus, I like Aaron patch, though we could add a defcustom if it breaks
somebody's setup.

Cheers & Thanks,
Rasmus

-- 
The right to be left alone is a human right

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

* Re: [RFC] [PATCH] Introduce org-specific functions for (next/previous)-visible-heading
  2015-01-19 21:56     ` Rasmus
@ 2015-01-20 12:00       ` Nicolas Goaziou
  2015-01-20 23:56         ` Aaron Ecay
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Goaziou @ 2015-01-20 12:00 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Hello,

Rasmus <rasmus@gmx.us> writes:


[...]

> To *me*, inlinetasks have got nothing to do with headlines (the syntax is
> unfortunate, especially for people who write Org without org-mode).

Indeed. It makes sense.

> Thus, I like Aaron patch, though we could add a defcustom if it breaks
> somebody's setup.

Then the patch is fine (with `org-with-limited-levels' instead of
re-inventing the wheel).


Regards,

-- 
Nicolas Goaziou

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

* Re: [RFC] [PATCH] Introduce org-specific functions for (next/previous)-visible-heading
  2015-01-20 12:00       ` Nicolas Goaziou
@ 2015-01-20 23:56         ` Aaron Ecay
  0 siblings, 0 replies; 6+ messages in thread
From: Aaron Ecay @ 2015-01-20 23:56 UTC (permalink / raw)
  To: Nicolas Goaziou, Rasmus; +Cc: emacs-orgmode

Hello,

2015ko urtarrilak 20an, Nicolas Goaziou-ek idatzi zuen:

[...]

> Then the patch is fine (with `org-with-limited-levels' instead of
> re-inventing the wheel).

Thanks everyone for the feedback.  The patch is pushed (with an entry in
ORG-NEWS).

-- 
Aaron Ecay

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

end of thread, other threads:[~2015-01-20 23:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-19  5:14 [RFC] [PATCH] Introduce org-specific functions for (next/previous)-visible-heading Aaron Ecay
2015-01-19 17:58 ` Nicolas Goaziou
2015-01-19 21:45   ` Andreas Leha
2015-01-19 21:56     ` Rasmus
2015-01-20 12:00       ` Nicolas Goaziou
2015-01-20 23:56         ` Aaron Ecay

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).