From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matthew Palermo Subject: Skipping the SUBTREE visibility state Date: Fri, 5 Oct 2018 18:29:13 +1000 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35590) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g8LUg-0003gK-SY for emacs-orgmode@gnu.org; Fri, 05 Oct 2018 04:29:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g8LUc-0008HU-F0 for emacs-orgmode@gnu.org; Fri, 05 Oct 2018 04:29:51 -0400 Received: from mail-ua1-x92d.google.com ([2607:f8b0:4864:20::92d]:34702) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g8LUa-0008FH-IA for emacs-orgmode@gnu.org; Fri, 05 Oct 2018 04:29:49 -0400 Received: by mail-ua1-x92d.google.com with SMTP id r15-v6so4424621uao.1 for ; Fri, 05 Oct 2018 01:29:46 -0700 (PDT) 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" To: emacs-orgmode@gnu.org Hi Org mode list, I find it really distracting when a large SUBTREE is expanded while browsing through an Org document. Does anyone else find this problematic or am I doing something wrong? Today I explored some ways to avoid this problem and came up with a patch to the ~org-cycle~ function to allow skipping the SUBTREE state. I have included the patch to ~org.el~ inline below. This patch makes a minimal modification to ~org-cycle~, defines a new command ~org-cycle-skip-subtree~ and binds it to C-Tab (overwriting the original binding). I'd like to hear your feedback. Thanks. Btw, I'm new to this sending patches via mailing list so please let me know if I've done something wrong. diff -u "c:/Users/Matthew Palermo/AppData/Roaming/.emacs.d/org.el" "c:/Users/Matthew Palermo/AppData/Roaming/.emacs.d/org-skip.el" --- "c:/Users/Matthew Palermo/AppData/Roaming/.emacs.d/org.el" 2018-04-24 00:17:49.000000000 +1000 +++ "c:/Users/Matthew Palermo/AppData/Roaming/.emacs.d/org-skip.el" 2018-10-05 17:10:33.347064600 +1000 @@ -6677,7 +6677,7 @@ (apply 'message args))) ;;;###autoload -(defun org-cycle (&optional arg) +(defun org-cycle (&optional arg skipsubtree) "TAB-action and visibility cycling for Org mode. This is the command invoked in Org mode by the `TAB' key. Its main @@ -6817,7 +6817,7 @@ (save-excursion (move-beginning-of-line 1) (looking-at org-outline-regexp))) (or (bolp) (not (eq org-cycle-emulate-tab 'exc-hl-bol)))) - (org-cycle-internal-local)) + (org-cycle-internal-local skipsubtree)) ;; From there: TAB emulation and template completion. (buffer-read-only (org-back-to-heading)) @@ -6849,6 +6849,11 @@ (org-back-to-heading) (org-cycle))))))) +(defun org-cycle-skip-subtree () + "Calls `org-cycle' except it skips the SUBTREE state" + (interactive) + (org-cycle nil t)) + (defun org-cycle-internal-global () "Do the global cycling action." ;; Hack to avoid display of messages for .org attachments in Gnus @@ -6890,7 +6895,7 @@ If POS is nil, use `point' instead." (get-char-property (or pos (point)) 'invisible)) -(defun org-cycle-internal-local () +(defun org-cycle-internal-local (&optional skipsubtree) "Do the local cycling action." (let ((goal-column 0) eoh eol eos has-children children-skipped struct) ;; First, determine end of headline (EOH), end of subtree or item @@ -6936,7 +6941,7 @@ (when (org-invisible-p) (org-flag-heading nil)))) ((and (or (>= eol eos) (not (string-match "\\S-" (buffer-substring eol eos)))) - (or has-children + (or has-children skipsubtree (not (setq children-skipped org-cycle-skip-children-state-if-no-children)))) ;; Entire subtree is hidden in one line: children view @@ -6972,9 +6977,10 @@ (setq org-cycle-subtree-status 'children) (unless (org-before-first-heading-p) (run-hook-with-args 'org-cycle-hook 'children))) - ((or children-skipped - (and (eq last-command this-command) - (eq org-cycle-subtree-status 'children))) + ((and (not skipsubtree) + (or children-skipped + (and (eq last-command this-command) + (eq org-cycle-subtree-status 'children)))) ;; We just showed the children, or no children are there, ;; now show everything. (unless (org-before-first-heading-p) @@ -19508,6 +19514,7 @@ (org-defkey org-mode-map "\C-i" 'org-cycle) (org-defkey org-mode-map [(tab)] 'org-cycle) (org-defkey org-mode-map [(control tab)] 'org-force-cycle-archived) +(org-defkey org-mode-map [(control tab)] 'org-cycle-skip-subtree) (org-defkey org-mode-map "\M-\t" #'pcomplete) ;; The following line is necessary under Suse GNU/Linux Diff finished. Fri Oct 5 18:08:00 2018