From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marco Wahl Subject: [RFC] Extend+slight change to C-c C-k and C-c TAB Date: Thu, 11 Jul 2019 15:03:16 +0200 Message-ID: <84v9w8vi3v.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:34485) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlYjW-0004jc-GU for emacs-orgmode@gnu.org; Thu, 11 Jul 2019 09:03:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hlYjV-0000tV-06 for emacs-orgmode@gnu.org; Thu, 11 Jul 2019 09:03:34 -0400 Received: from 195-159-176-226.customer.powertech.no ([195.159.176.226]:35182 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hlYjU-0000s7-KF for emacs-orgmode@gnu.org; Thu, 11 Jul 2019 09:03:32 -0400 Received: from list by blaine.gmane.org with local (Exim 4.89) (envelope-from ) id 1hlYjN-000WT9-Ie for emacs-orgmode@gnu.org; Thu, 11 Jul 2019 15:03:25 +0200 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 --=-=-= Content-Type: text/plain Hi all, For some time I use the realizations of C-c C-k (`org-kill-note-or-show-branches') and C-c TAB (`org-ctrl-c-tab') as found in the patches below. With the patch the keys apply also above the first headline opposed to the former version. In this case the whole file is treated as the subtree to act on. This moves Org a tiny bit into the direction to treat Org files as subtrees. IIRC Gustav once pointed out that it might be a good idea to regard Org files as Org subtrees. Further with the patch the behavior of C-c TAB is slightly different since it folds every unfolded subtree opposed to the previous version. Of course I'm all for this change. Is this worth to go into orgmode? What do you think? Ciao, -- Marco --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-function-to-flag-region-above-first-heading.patch >From add2614cf95d7ab569c95521747ec80f5eca2225 Mon Sep 17 00:00:00 2001 From: Marco Wahl Date: Thu, 11 Jul 2019 12:08:47 +0200 Subject: [PATCH 1/4] Add function to flag region above first heading * lisp/org.el (org-flag-above-first-heading): New function. --- lisp/org.el | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lisp/org.el b/lisp/org.el index 5d6cc757d..3326aa542 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -17908,6 +17908,15 @@ Use `\\[org-edit-special]' to edit table.el tables")) (org-reset-file-cache)) (message "%s restarted" major-mode)) +(defun org-flag-above-first-heading (&optional arg) + "Hide from bob up to the first heading. +Move point to the beginning of first heading or end of buffer." + (goto-char (point-min)) + (unless (org-at-heading-p) + (outline-next-heading)) + (unless (bobp) + (org-flag-region 1 (1- (point)) (not arg) 'outline))) + (defun org-kill-note-or-show-branches () "Abort storing current note, or call `outline-show-branches'." (interactive) -- 2.22.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-Add-function-to-show-just-every-headline-in-buffer.patch >From ee4fcc2aaa54d81fe3d5c49f203c41f13589b43f Mon Sep 17 00:00:00 2001 From: Marco Wahl Date: Thu, 11 Jul 2019 12:12:37 +0200 Subject: [PATCH 2/4] Add function to show just every headline in buffer * lisp/org.el (org-show-branches-buffer): New function. --- lisp/org.el | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lisp/org.el b/lisp/org.el index 3326aa542..e6117dcdf 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -17917,6 +17917,16 @@ Move point to the beginning of first heading or end of buffer." (unless (bobp) (org-flag-region 1 (1- (point)) (not arg) 'outline))) +(defun org-show-branches-buffer () + "Show all branches in the buffer." + (org-flag-above-first-heading) + (outline-hide-sublevels 1) + (unless (eobp) + (outline-show-branches) + (while (outline-get-next-sibling) + (outline-show-branches))) + (goto-char (point-min))) + (defun org-kill-note-or-show-branches () "Abort storing current note, or call `outline-show-branches'." (interactive) -- 2.22.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0003-Make-show-branches-applicable-to-whole-file.patch >From 3e76a9fc447f0c6e6f7f53f4808590354ea6d63d Mon Sep 17 00:00:00 2001 From: Marco Wahl Date: Thu, 11 Jul 2019 12:16:35 +0200 Subject: [PATCH 3/4] Make show-branches applicable to whole file * lisp/org.el (org-kill-note-or-show-branches): Extend and refactor. --- lisp/org.el | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index e6117dcdf..fecfc451c 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -17928,17 +17928,15 @@ Move point to the beginning of first heading or end of buffer." (goto-char (point-min))) (defun org-kill-note-or-show-branches () - "Abort storing current note, or call `outline-show-branches'." + "Abort storing current note, or show just branches." (interactive) - (if (not org-finish-function) - (save-excursion - (save-restriction - (org-narrow-to-subtree) - (org-flag-subtree t) - (call-interactively 'outline-show-branches) - (org-hide-archived-subtrees (point-min) (point-max)))) - (let ((org-note-abort t)) - (funcall org-finish-function)))) + (if org-finish-function + (let ((org-note-abort t)) + (funcall org-finish-function)) + (if (org-before-first-heading-p) + (org-show-branches-buffer) + (outline-hide-subtree) + (outline-show-branches)))) (defun org-delete-indentation (&optional arg) "Join current line to previous and fix whitespace at join. -- 2.22.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0004-Make-show-children-applicable-to-whole-file.patch >From f561ed24863ee0b501c538ffa565e290c0eeb99e Mon Sep 17 00:00:00 2001 From: Marco Wahl Date: Thu, 11 Jul 2019 12:21:12 +0200 Subject: [PATCH 4/4] Make show-children applicable to whole file * lisp/org.el (org-ctrl-c-tab): Extend and refactor. --- lisp/org.el | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index fecfc451c..de5b5855f 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -18070,14 +18070,20 @@ context. See the individual commands for more information." (interactive) (org-return t)) -(defun org-ctrl-c-tab (&optional _arg) +(defun org-ctrl-c-tab (&optional arg) "Toggle columns width in a table, or show children. Call `org-table-toggle-column-width' if point is in a table. -Otherwise, call `org-show-children'." +Otherwise, call `org-show-children'. ARG is the level to hide." (interactive "p") - (call-interactively - (if (org-at-table-p) #'org-table-toggle-column-width - #'org-show-children))) + (if (org-at-table-p) + (call-interactively #'org-table-toggle-column-width) + (if (org-before-first-heading-p) + (progn + (org-flag-above-first-heading) + (outline-hide-sublevels (or arg 1)) + (goto-char (point-min))) + (outline-hide-subtree) + (org-show-children arg)))) (defun org-ctrl-c-star () "Compute table, or change heading status of lines. -- 2.22.0 --=-=-=--