From: Michael Brand <michael.brand@alumni.ethz.ch>
To: Org Mode <emacs-orgmode@gnu.org>
Cc: hsitz@nwlink.com, rainer.stengele@diplan.de
Subject: Re: suggestion: simplify depth stepping of document structure (outline) visibility
Date: Wed, 01 Sep 2010 19:10:33 +0200 [thread overview]
Message-ID: <4C7E8909.9040504@alumni.ethz.ch> (raw)
In-Reply-To: <4AD5C312.7010703@alumni.ethz.ch>
Hi all
This is a follow-up to
http://thread.gmane.org/gmane.emacs.orgmode/17581
On 09-10-14 14:24 , I wrote:
> (global-set-key (kbd "C->") 'my-orgstruct-dive)
> (global-set-key (kbd "C-<") 'my-orgstruct-dive-out)
> (defvar my-orgstruct-dive-level 0)
Now I did a rewrite for some improvements, mainly to support dive in
and out of headings also in a variant that leaves the visibility of
siblings. The code is at the end.
Example 1: C-> C-> C-< C-> [...]
This changes only the visibility of of the current heading and leaves
the visibility of siblings, similar to Tab.
Example 2: C-u C-> C-> C-< C-< C-< C-> [...]
This changes the visibility of all headings, similar to S-Tab.
Michael
-----------------------------------------------------------
(global-set-key (kbd "C->") 'my-orgstruct-dive-in)
(global-set-key (kbd "C-<") 'my-orgstruct-dive-out)
(defun my-orgstruct-dive-in (arg)
"This func is very similar to the func my-orgstruct-dive-out. They are
wrappers to simplify comparison with last-command in my-orgstruct-dive.
Without prefix C-u: Dive in and out the current heading (relative) and leave
the visibility of the siblings, similar to Tab. Having the point before the
first heading in a buffer does not make sense.
Example: `C-> C-> C-< C-> [...]'
With prefix C-u: Dive in and out all headings in the buffer (absolute),
similar to S-Tab. If the point is before the first heading then the behavior
is like if it is on a top level heading.
Example: `C-u C-> C-> C-< C-< C-< C-> [...]'"
(interactive "P")
(my-orgstruct-dive arg))
(defun my-orgstruct-dive-out (arg)
"See the docstring of the very similar func my-orgstruct-dive-in."
(interactive "P")
(my-orgstruct-dive arg t))
(defvar my-orgstruct-dive-start-arg nil
"State variable of func my-orgstruct-dive: The prefix state of the first
invoke of my-orgstruct-dive-in or my-orgstruct-dive-out, see their
docstrings.")
(defvar my-orgstruct-dive-level 1
"State variable of func my-orgstruct-dive: The reduced level which is the
level of the heading and not necessarily the number of stars if oddeven.
The type of level is relative if my-orgstruct-dive-start-arg is nil, else
absolute. For both types of level the smallest possible value is 1.")
(defun my-orgstruct-dive (arg &optional dive-out)
"Make visible one heading level more or less.
return value: Undefined.
arg: See the docstring about prefix C-u in func my-orgstruct-dive-in
dive-out: If nil dive in, else dive out."
;; determine new level
(if (or arg ; let any intermediate `C-u' break the invoke repetition
(and (not (eq last-command 'my-orgstruct-dive-in))
(not (eq last-command 'my-orgstruct-dive-out))))
;; this is the first invoke of dive
(progn
;; move back to beginning of line with heading:
;; - to prepare the point location for possibly hitting some Tabs
;; afterwards
;; - to skip list elements, they are not supported do dive in
;; (this alone could also be covered within a save-excursion)
;; - for the func org-outline-level that requires beginning of line
;; (this alone could also be covered within a save-excursion)
(unless (org-before-first-heading-p) (outline-back-to-heading))
;; reset start arg and level
(setq my-orgstruct-dive-start-arg arg)
(setq my-orgstruct-dive-level
(if my-orgstruct-dive-start-arg
;; absolute level
(if (org-before-first-heading-p)
'1
(org-reduced-level (org-outline-level)))
;; relative level
'1)))
;; this is a repeated invoke of dive: increase/decrease level
(setq my-orgstruct-dive-level
(+ my-orgstruct-dive-level (if dive-out '-1 '1)))
(when (< my-orgstruct-dive-level 1) (setq my-orgstruct-dive-level 1)))
;; update heading visibility according to new level
(if my-orgstruct-dive-start-arg
;; absolute level
(org-shifttab my-orgstruct-dive-level) ; logs the level itself
;; relative level
(hide-subtree)
(show-children (* (org-level-increment) (1- my-orgstruct-dive-level)))
(message "Content view to relative level: %d" my-orgstruct-dive-level))
;; move back to beginning of line with heading to prepare
;; the point location for possibly hitting some Tabs afterwards
(unless (org-before-first-heading-p) (outline-back-to-heading)))
-----------------------------------------------------------
next prev parent reply other threads:[~2010-09-01 17:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <4AB0000D.5000004@alumni.ethz.ch>
2009-09-15 22:00 ` suggestion: simplify depth stepping of document structure (outline) visibility Michael Brand
2009-09-16 0:26 ` Bernt Hansen
2009-10-14 12:24 ` Michael Brand
2010-09-01 17:10 ` Michael Brand [this message]
2010-09-03 1:26 ` Bastien
2010-09-03 5:01 ` Herbert Sitz
2010-09-03 7:59 ` Michael Brand
2010-09-03 9:05 ` Michael Brand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4C7E8909.9040504@alumni.ethz.ch \
--to=michael.brand@alumni.ethz.ch \
--cc=emacs-orgmode@gnu.org \
--cc=hsitz@nwlink.com \
--cc=rainer.stengele@diplan.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).