From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [RFC] Simplify `org-show-context' configuration Date: Tue, 17 Feb 2015 11:59:39 +0100 Message-ID: <874mqkx0pw.fsf@nicolasgoaziou.fr> References: <87lhjxh8q4.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:42572) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNfrR-0006vT-LB for emacs-orgmode@gnu.org; Tue, 17 Feb 2015 05:58:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YNfrO-0001MD-Aq for emacs-orgmode@gnu.org; Tue, 17 Feb 2015 05:58:37 -0500 Received: from relay6-d.mail.gandi.net ([2001:4b98:c:538::198]:48484) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNfrN-0001Ln-UV for emacs-orgmode@gnu.org; Tue, 17 Feb 2015 05:58:34 -0500 In-Reply-To: <87lhjxh8q4.fsf@nicolasgoaziou.fr> (Nicolas Goaziou's message of "Mon, 16 Feb 2015 22:01:07 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Org Mode List --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Actually, the first patch didn't pay attention to children, if any, of the current headline. Here is a new patch, including feedback from Kyle and S=C3=A9bastien. Considering the following buffer, "Text" being the matched location * Grandmother ** Uncle *** Heir ** Father *** Sister *** Self Text **** First born Other text **** The other child *** Brother ** Aunt `minimal' is * Grandmother *** Self Text `local' is * Grandmother *** Self Text **** First born `ancestors' is * Grandmother ** Father *** Self Text `lineage' is * Grandmother ** Father *** Sister *** Self Text **** First born *** Brother `canonical' is * Grandmother ** Uncle ** Father *** Sister *** Self Text **** First born **** The other child *** Brother ** Aunt `full' is * Grandmother ** Uncle ** Father *** Sister *** Self Text **** First born Other text **** The other child *** Brother ** Aunt Regards, --=20 Nicolas Goaziou --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Simplify-org-show-context-configuration.patch >From 7108b6a5fc2332f05979796af734b1d55e7a8172 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou 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 six different views, instead of four variables for a total of 16 configurations. --- lisp/org-agenda.el | 15 ++-- lisp/org.el | 228 +++++++++++++++++++++++++---------------------------- 2 files changed, 114 insertions(+), 129 deletions(-) diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el index 9f2d9d1..7adf351 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 'lineage)) (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..c707ff4 100755 --- a/lisp/org.el +++ b/lisp/org.el @@ -1165,87 +1165,72 @@ 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 . lineage) + (bookmark-jump . lineage) + (default . ancestors)) + "Alist between context and visibility span when revealing a location. + +\\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." + default default for all contexts not set explicitly + +Allowed visibility spans are + + minimal show current headline, and entry below if needed + local show current headline, entry below and next headline + ancestors show direct ancestors of current headline; show entry only + if required + lineage show direct ancestors, all siblings and first child of + current headline; show entry only if required + canonical show current headline, all its children, direct ancestors + and all their siblings; show entry only if required + full show current headline and its whole subtree, all siblings, + all ancestors including their siblings, and entry + +As special cases, a nil or t value means show all contexts in +`minimal' or `full' view, respectively. + +`minimal', `local', `ancestors' 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 "24.4" - :package-version '(Org . "8.0")) - -(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. - -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." - :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" + (const minimal) + (const local) + (const ancestors) + (const lineage) + (const canonical) + (const full)))))) (defcustom org-indirect-buffer-display 'other-window "How should indirect tree buffers be displayed? @@ -7522,11 +7507,9 @@ 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 'lineage))) (goto-char (point-min))) (let (org-special-ctrl-a/e) (org-beginning-of-line)) (message "Select location and press RET") @@ -11002,9 +10985,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,59 +13911,65 @@ 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 - (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 - (save-excursion - (while (and (ignore-errors (progn (org-up-heading-all 1) t)) - (not (bobp))) - (org-flag-heading nil) - (when siblings-p (org-show-siblings))))))) +Optional argument KEY, when non-nil, is a symbol. See +`org-show-context-detail' for allowed values and how much is to +be shown." + (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', `ancestors', `lineage', +`canonical', `full' or t. See `org-show-context-detail' for more +information." + ;; Show current heading and possibly its entry, following headline + ;; or all children. + (if (and (org-at-heading-p) (not (memq detail '(local full t)))) + (org-flag-heading nil) + (org-show-entry) + (org-with-limited-levels + (case detail + ((full t) + (org-show-subtree) + (run-hook-with-args 'org-cycle-hook 'subtree)) + (canonical (show-children)) + ((nil minimal ancestors)) + (t (save-excursion + (outline-next-heading) + (org-flag-heading nil)))))) + ;; Show all siblings. + (when (memq detail '(lineage canonical full t)) (org-show-siblings)) + ;; Show ancestors, possibly with their siblings. + (when (memq detail '(ancestors lineage canonical full t)) + (save-excursion + (while (org-up-heading-safe) + (org-flag-heading nil) + (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 look like when opened with hierarchical calls to `org-cycle'. + With double optional argument \\[universal-argument] \\[universal-argument], \ 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)) - (when (equal siblings '(16)) - (save-excursion - (when (org-up-heading-safe) - (org-show-subtree) - (run-hook-with-args 'org-cycle-hook 'subtree))))) + (cond ((equal siblings '(4)) (org-show-set-visibility 'canonical)) + ((equal siblings '(16)) + (save-excursion + (when (org-up-heading-safe) + (org-show-subtree) + (run-hook-with-args 'org-cycle-hook 'subtree)))) + (t (org-show-set-visibility 'lineage)))) (defun org-highlight-new-match (beg end) "Highlight from BEG to END and mark the highlight is an occur headline." -- 2.3.0 --=-=-=--