emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: Org Mode List <emacs-orgmode@gnu.org>
Subject: [RFC] Simplify `org-show-context' configuration
Date: Mon, 16 Feb 2015 22:01:07 +0100	[thread overview]
Message-ID: <87lhjxh8q4.fsf@nicolasgoaziou.fr> (raw)

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

Hello,

As explained in its commit message, the following patch is an attempt at
simplifying `org-show-context' configuration by offering a set of
5 predefined views to choose from instead of setting 4 different
variables (`org-show-following-heading', `org-show-siblings',
`org-show-entry-below' and `org-show-hierarchy-above'). These views are

  minimal        show current headline, and entry below if needed
  local          show current headline, entry below and next headline
  lineage        show direct ancestors and all siblings of current headline;
                 show entry only if required
  canonical      show direct ancestors and all of their siblings; show entry
                 only if required
  full           show direct ancestors, all their siblings and entry

To sum it up, if original buffer is

  * H1
  * H2
  ** Sub 1
  ** Sub 2
  *** Sub sub 1
  *** Sub sub 2
      Text
  *** Sub sub 3
  *** Sub sub 4
  ** Sub 3

and match is on "Text", minimal is

  * H1
  * H2
    * Sub sub 2
      Text

`local' is

  * H1
  * H2
  *** Sub sub 2
      Text
  *** Sub sub 3

`lineage' is

  * H1
  * H2
  ** Sub 2
  *** Sub sub 1
  *** Sub sub 2
      Text
  *** Sub sub 3
  *** Sub sub 4

`canonical' and `full' are

  * H1
  * H2
  ** Sub 1
  ** Sub 2
  *** Sub sub 1
  *** Sub sub 2
      Text
  *** Sub sub 3
  *** Sub sub 4
  ** Sub 3

Note that neither `canonical' nor `full' are possible to obtain with the
4 original variables.

"if required"/"if needed" means the entry will only be shown if point is
within the entry (i.e., not on the headline). Thus, for example,
`canonical' and `full' only differ when match is on a headline, since
only latter will show the entry.

I think this is enough, but I can add more views if needed.

WDYT?


Regards,

-- 
Nicolas Goaziou                                                0x80A93738

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Simplify-org-show-context-configuration.patch --]
[-- Type: text/x-diff, Size: 12971 bytes --]

From c04351a77a7d3af99d292f71e33d43f7e72410d2 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Date: Mon, 16 Feb 2015 21:43:35 +0100
Subject: [PATCH] Simplify `org-show-context' configuration

* lisp/org.el (org-show-context-detail): New variable.
(org-context-choice, org-show-following-heading, org-show-siblings,
org-show-entry-below, org-show-hierarchy-above): Remove variables.
(org-show-set-visibility): New function.
(org-get-location, org-show-context, org-reveal): Use new function.
(org-link-search): Update docstring.

* lisp/org-agenda.el (org-agenda-cycle-show): Use new function.

Configuration of `org-show-context' is done with a single variable
offering five different views, instead of four variables for a total
of 16 configurations.
---
 lisp/org-agenda.el |  15 ++---
 lisp/org.el        | 190 ++++++++++++++++++++++-------------------------------
 2 files changed, 86 insertions(+), 119 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 9f2d9d1..f7406d7 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -8696,11 +8696,12 @@ if it was hidden in the outline."
 (defvar org-agenda-cycle-counter nil)
 (defun org-agenda-cycle-show (&optional n)
   "Show the current entry in another window, with default settings.
-Default settings are taken from `org-show-hierarchy-above' and siblings.
-When use repeatedly in immediate succession, the remote entry will cycle
-through visibility
 
-children -> subtree -> folded
+Default settings are taken from `org-show-context-detail'.  When
+use repeatedly in immediate succession, the remote entry will
+cycle through visibility
+
+  children -> subtree -> folded
 
 When called with a numeric prefix arg, that arg will be passed through to
 `org-agenda-show-1'.  For the interpretation of that argument, see the
@@ -9521,11 +9522,7 @@ a timestamp can be added there."
     (unless (bolp) (insert "\n"))
     (unless (org-looking-at-p "^[ \t]*$") (save-excursion (insert "\n")))
     (when org-adapt-indentation (org-indent-to-column col)))
-  (let ((org-show-following-heading t)
-	(org-show-siblings t)
-	(org-show-hierarchy-above t)
-	(org-show-entry-below t))
-    (org-show-context)))
+  (org-show-set-visibility 'canonical))
 
 (defun org-agenda-diary-entry ()
   "Make a diary entry, like the `i' command from the calendar.
diff --git a/lisp/org.el b/lisp/org.el
index 4f047b2..bbabb9a 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -1165,87 +1165,67 @@ effective."
   :tag "Org Reveal Location"
   :group 'org-structure)
 
-(defconst org-context-choice
-  '(choice
-    (const :tag "Always" t)
-    (const :tag "Never" nil)
-    (repeat :greedy t :tag "Individual contexts"
-	    (cons
-	     (choice :tag "Context"
-		     (const agenda)
-		     (const org-goto)
-		     (const occur-tree)
-		     (const tags-tree)
-		     (const link-search)
-		     (const mark-goto)
-		     (const bookmark-jump)
-		     (const isearch)
-		     (const default))
-	     (boolean))))
-  "Contexts for the reveal options.")
-
-(defcustom org-show-hierarchy-above '((default . t))
-  "Non-nil means show full hierarchy when revealing a location.
-Org-mode often shows locations in an org-mode file which might have
-been invisible before.  When this is set, the hierarchy of headings
-above the exposed location is shown.
-Turning this off for example for sparse trees makes them very compact.
-Instead of t, this can also be an alist specifying this option for different
-contexts.  Valid contexts are
+(defcustom org-show-context-detail '((isearch . canonical)
+				     (bookmark-jump . canonical)
+				     (default . lineage))
+  "Alist between context and visibility span when revealing a location.
+
+\\<org-mode-map>Some actions may move point into invisible
+locations.  As a consequence, Org always expose a neighborhood
+around point.  How much is shown depends on the initial action,
+or context.  Valid contexts are
+
   agenda         when exposing an entry from the agenda
-  org-goto       when using the command `org-goto' on key C-c C-j
-  occur-tree     when using the command `org-occur' on key C-c /
+  org-goto       when using the command `org-goto' (\\[org-goto])
+  occur-tree     when using the command `org-occur' (\\[org-sparse-tree] /)
   tags-tree      when constructing a sparse tree based on tags matches
   link-search    when exposing search matches associated with a link
   mark-goto      when exposing the jump goal of a mark
   bookmark-jump  when exposing a bookmark location
   isearch        when exiting from an incremental search
-  default        default for all contexts not set explicitly"
-  :group 'org-reveal-location
-  :type org-context-choice)
-
-(defcustom org-show-following-heading '((default . nil))
-  "Non-nil means show following heading when revealing a location.
-Org-mode often shows locations in an org-mode file which might have
-been invisible before.  When this is set, the heading following the
-match is shown.
-Turning this off for example for sparse trees makes them very compact,
-but makes it harder to edit the location of the match.  In such a case,
-use the command \\[org-reveal] to show more context.
-Instead of t, this can also be an alist specifying this option for different
-contexts.  See `org-show-hierarchy-above' for valid contexts."
-  :group 'org-reveal-location
-  :type org-context-choice)
-
-(defcustom org-show-siblings '((default . nil) (isearch t) (bookmark-jump t))
-  "Non-nil means show all sibling heading when revealing a location.
-Org-mode often shows locations in an org-mode file which might have
-been invisible before.  When this is set, the sibling of the current entry
-heading are all made visible.  If `org-show-hierarchy-above' is t,
-the same happens on each level of the hierarchy above the current entry.
-
-By default this is on for the isearch context, off for all other contexts.
-Turning this off for example for sparse trees makes them very compact,
-but makes it harder to edit the location of the match.  In such a case,
-use the command \\[org-reveal] to show more context.
-Instead of t, this can also be an alist specifying this option for different
-contexts.  See `org-show-hierarchy-above' for valid contexts."
-  :group 'org-reveal-location
-  :type org-context-choice
-  :version "24.4"
-  :package-version '(Org . "8.0"))
+  default        default for all contexts not set explicitly
+
+Allowed visibility spans are
 
-(defcustom org-show-entry-below '((default . nil))
-  "Non-nil means show the entry below a headline when revealing a location.
-Org-mode often shows locations in an org-mode file which might have
-been invisible before.  When this is set, the text below the headline that is
-exposed is also shown.
+  minimal        show current headline, and entry below if needed
+  local          show current headline, entry below and next headline
+  lineage        show direct ancestors and all siblings of current headline;
+                 show entry only if required
+  canonical      show direct ancestors and all of their siblings; show entry
+                 only if required
+  full           show direct ancestors, all their siblings and entry
 
-By default this is off for all contexts.
-Instead of t, this can also be an alist specifying this option for different
-contexts.  See `org-show-hierarchy-above' for valid contexts."
+As a special case, a nil (respectively t) value means
+`minimal' (respectively `full') detail level for all contexts.
+
+`minimal', `local' and, to a lesser extent `lineage', can make
+displayed information very compact, but also make it harder to
+edit the location of the match.  In such a case, use the command
+`org-reveal' (\\[org-reveal]) to show more context."
   :group 'org-reveal-location
-  :type org-context-choice)
+  :version "25.1"
+  :package-version '(Org . "8.3")
+  :type '(choice
+	  (const :tag "Full" t)
+	  (const :tag "Minimal" nil)
+	  (repeat :greedy t :tag "Individual contexts"
+		  (cons
+		   (choice :tag "Context"
+			   (const agenda)
+			   (const org-goto)
+			   (const occur-tree)
+			   (const tags-tree)
+			   (const link-search)
+			   (const mark-goto)
+			   (const bookmark-jump)
+			   (const isearch)
+			   (const default))
+		   (choice :tag "Detail level"
+			   (cons minimal)
+			   (cons local)
+			   (cons lineage)
+			   (cons canonical)
+			   (cons full))))))
 
 (defcustom org-indirect-buffer-display 'other-window
   "How should indirect tree buffers be displayed?
@@ -7522,11 +7502,8 @@ or nil."
 	 (setq buffer-read-only t)
 	 (if (and (boundp 'org-goto-start-pos)
 		  (integer-or-marker-p org-goto-start-pos))
-	     (let ((org-show-hierarchy-above t)
-		   (org-show-siblings t)
-		   (org-show-following-heading t))
-	       (goto-char org-goto-start-pos)
-	       (and (outline-invisible-p) (org-show-context)))
+	     (progn (goto-char org-goto-start-pos)
+		    (when (outline-invisible-p) (org-show-set-visibility t)))
 	   (goto-char (point-min)))
 	 (let (org-special-ctrl-a/e) (org-beginning-of-line))
 	 (message "Select location and press RET")
@@ -11002,9 +10979,8 @@ If the current buffer is in `dired-mode', grep will be used to search
 in all files.  If AVOID-POS is given, ignore matches near that position.
 
 When optional argument STEALTH is non-nil, do not modify
-visibility around point, thus ignoring
-`org-show-hierarchy-above', `org-show-following-heading' and
-`org-show-siblings' variables."
+visibility around point, thus ignoring `org-show-context-detail'
+variable."
   (let ((case-fold-search t)
 	(s0 (mapconcat 'identity (org-split-string s "[ \t\r\n]+") " "))
 	(markers (concat "\\(?:" (mapconcat (lambda (x) (regexp-quote (car x)))
@@ -13929,41 +13905,38 @@ starting point when no match is found."
 
 (defun org-show-context (&optional key)
   "Make sure point and context are visible.
-How much context is shown depends upon the variables
-`org-show-hierarchy-above', `org-show-following-heading',
-`org-show-entry-below' and `org-show-siblings'."
-  (let ((heading-p   (org-at-heading-p t))
-	(hierarchy-p (org-get-alist-option org-show-hierarchy-above key))
-	(following-p (org-get-alist-option org-show-following-heading key))
-	(entry-p     (org-get-alist-option org-show-entry-below key))
-	(siblings-p  (org-get-alist-option org-show-siblings key)))
-    ;; Show heading or entry text
-    (if (and heading-p (not entry-p))
-	(org-flag-heading nil)    ; only show the heading
-      (and (or entry-p (outline-invisible-p) (org-invisible-p2))
-	   (org-show-hidden-entry)))    ; show entire entry
-    (when following-p
-      ;; Show next sibling, or heading below text
+How much context is shown depends upon the variable
+`org-show-context-detail', which see."
+  (org-show-set-visibility (org-get-alist-option org-show-context-detail key)))
+
+(defun org-show-set-visibility (detail)
+  "Set visibility around point according to DETAIL.
+DETAIL is either nil, `minimal', `local', `lineage', `canonical'
+and `full'.  See `org-show-context-detail' for more information."
+  (let ((headingp (org-at-heading-p)))
+    (when headingp (org-flag-heading nil))
+    (when (or (not headingp) (memq detail '(full local)))
+      (org-show-entry))
+    (when (eq detail 'local)
       (save-excursion
-	(and (if heading-p (org-goto-sibling) (outline-next-heading))
-	     (org-flag-heading nil))))
-    (when siblings-p (org-show-siblings))
-    (when hierarchy-p
-      ;; show all higher headings, possibly with siblings
+	(outline-next-heading)
+	(org-flag-heading nil)))
+    (when (memq detail '(lineage canonical full t))
+      (org-show-siblings)
       (save-excursion
-	(while (and (ignore-errors (progn (org-up-heading-all 1) t))
-		    (not (bobp)))
+	(while (org-up-heading-safe)
 	  (org-flag-heading nil)
-	  (when siblings-p (org-show-siblings)))))))
+	  (when (memq detail '(canonical full t))
+	    (org-show-siblings)))))))
 
 (defvar org-reveal-start-hook nil
   "Hook run before revealing a location.")
 
 (defun org-reveal (&optional siblings)
   "Show current entry, hierarchy above it, and the following headline.
-This can be used to show a consistent set of context around locations
-exposed with `org-show-hierarchy-above' or `org-show-following-heading'
-not t for the search context.
+
+This can be used to show a consistent set of context around
+locations exposed with `org-show-context'.
 
 With optional argument SIBLINGS, on each level of the hierarchy all
 siblings are shown.  This repairs the tree structure to what it would
@@ -13973,10 +13946,7 @@ go to the parent and show the
 entire tree."
   (interactive "P")
   (run-hooks 'org-reveal-start-hook)
-  (let ((org-show-hierarchy-above t)
-	(org-show-following-heading t)
-	(org-show-siblings (if siblings t org-show-siblings)))
-    (org-show-context nil))
+  (org-show-set-visibility 'lineage)
   (when (equal siblings '(16))
     (save-excursion
       (when (org-up-heading-safe)
-- 
2.3.0


             reply	other threads:[~2015-02-16 21:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-16 21:01 Nicolas Goaziou [this message]
2015-02-16 23:15 ` [RFC] Simplify `org-show-context' configuration Kyle Meyer
2015-02-17  0:00   ` Nicolas Goaziou
2015-02-17  8:25 ` Sebastien Vauban
2015-02-17  8:43   ` Nicolas Goaziou
2015-02-17  9:19     ` Sebastien Vauban
2015-02-17  9:53       ` Eric Abrahamsen
2015-02-17 10:10         ` Sebastien Vauban
2015-02-17 10:59 ` Nicolas Goaziou
2015-02-17 19:05 ` Samuel Wales
2015-02-17 20:41   ` Nicolas Goaziou
2015-02-17 22:07     ` Samuel Wales
2015-02-18  0:24       ` Nicolas Goaziou
2015-02-18  0:52         ` Samuel Wales
2015-02-22 14:01           ` Nicolas Goaziou

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=87lhjxh8q4.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=emacs-orgmode@gnu.org \
    /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).