org-cycle (from CHILDREN TO SUBTREE when SUBTREE is empty) - emacs

When I am using org-cycle it annoys me when I have to execute a redundant org-cycle when the SUBTREE is empty.
- list A
- sub_list A
Here org-cycle goes from FOLDED to CHILDREN then to SUBTREE, yet there's nothing to show. Is there a way to go back to FOLDED state when the subtree is empty?

Related

VS code snippets - what is the required number in front of a choice list?

https://code.visualstudio.com/docs/editor/userdefinedsnippets#_choice
${1|one,two,three|}
So I'm new to snippets, and I noticed the number in front of a list of completion choices is required to show the choice menu correctly (if omitted, it will populate the choice list as a literal string - https://github.com/infosec-intern/textmate-yara/pull/29).
What does this number do, and why is it needed ?
(the documentation doesn't explain it)
is it for the default selection ?
Thanks,
In ${1|one,two,three|} the 1 is a tabstop. When you trigger the snippet that is the first place your cursor will go. See https://code.visualstudio.com/docs/editor/userdefinedsnippets#_tabstops
Tabstops
With tabstops, you can make the editor cursor move inside a snippet.
Use $1, $2 to specify cursor locations. The number is the order in
which tabstops will be visited, whereas $0 denotes the final cursor
position. Multiple occurrences of the same tabstop are linked and
updated in sync.
Accorsing to the snippet grammar the tabstop number is required before a choice element.
choice ::= '${' int '|' text (',' text)* '|}'
Since it is a choice element it makes sense that you want the cursor to go there at some time just by cycling through the tabstops with the tab key. You can select the order of the tabstops, they don't have to be in any certain order within your snippet. Tabstop $2 could appear before $1 for example.
And the tabstop has nothing to do with the default selection/option. The default will always be the first option listed in the snippet.

org-mode folding considers whitespace as content

Disclaimer: I am new to org-mode.
In org-mode, I sometimes add extra empty lines to make the separation between different tasks clearer when they are expanded. Like so:
** Task 1
*** Subtask 1.1
text text
*** Subtask 1.2
** Task 2
The problem is that when I fold 'Task 1' (by pressing C-tab while on its line) the subtasks and their contents are folded correctly, but the content of 'Subtask 1.2' is also folded (namely, the new line under it).
If I press C-tab while on the line of 'Subtask 1.2', the message 'SUBTREE (NO CHILDREN)' is printed and 'Subtask 1.2' is correctly not folded.
Is this normal? Can I somehow correct this behaviour so that empty content is not folded?
Use (setq org-cycle-separator-lines -1) in your config file.
This will fix it.
Documentation:
Number of empty lines needed to keep an empty line between collapsed trees.
If you leave an empty line between the end of a subtree and the following
headline, this empty line is hidden when the subtree is folded.
Org mode will leave (exactly) one empty line visible if the number of
empty lines is equal or larger to the number given in this variable.
So the default 2 means at least 2 empty lines after the end of a subtree
are needed to produce free space between a collapsed subtree and the
following headline.
If the number is negative, and the number of empty lines is at least -N,
all empty lines are shown.

how to warn against deleting folded subtree in org-mode?

I'm editing content in emacs org-mode and using the header structure in both folded and unfolded modes. In editing, though, I'm worried I will accidentally delete a folded subtree containing content.
Is there a way to get org-mode to warn me before deleting a folded subtree containing hidden content?
See the following variables to protect hidden trees under some circumstances:
org-catch-invisible-edits
org-ctrl-k-protect-subtree
Note however that those will not protect hidden trees from being killed by, e.g., C-w (kill-region).

Collapsing the current outline in Emacs org-mode

Say I am in org-mode in a document with the following structure:
* First headline
* Second headline
** Section A
Here is one line
Here is another line
blah, blah
** Section B
Say the cursor is on the line that reads Here is another line. I would like to collapse ** Section A from this location with a keyboard shortcut.
If I press <TAB> it does not collapse ** Section A, as I would need the cursor to be on the stars for this to work.
If I press <Shift-TAB> it collapses all outlines, and not the current one.
Is there any way to cycle through the collapsing of the outline in scope (i.e. the "current outline")?
You can customize the behaviour of the org-cycle command (which is bound to <TAB>) by changing the value of org-cycle-emulate-tab.
To get it to collapse ** Section A when your cursor is on Here is another line add the following line to your .emacs file:
(setq org-cycle-emulate-tab 'white)
The white will allow you to still use <TAB> to indent in empty lines. From org-mode Github:
org-cycle-emulate-tab's value is t
Documentation:
Where should `org-cycle' emulate TAB.
nil Never
white Only in completely white lines
whitestart Only at the beginning of lines, before the first non-white char
t Everywhere except in headlines
exc-hl-bol Everywhere except at the start of a headline
If you don't mind doing this in two steps:
C-c C-p: move the cursor to the previous heading (** Section A in your example)
TAB: fold the section
This method doesn't require any configuration, as long as you get used to it.

How to display the full context of the entries in org-mode agenda tree view

In org-mode's daily/weekly agenda view, is there a way to display the full context of the entries?
My reading of the code is that it finds the first heading above the timestamp and displays that. However, in my case, that heading is often 3-4 levels deep and doesn't make sense without the bullets above it. It also doesn't seem like there are hooks to easily change that. Filtering is trivial, but not changing the fundamental presentation format.
There is no way to display all the context directly in the agenda view, but you can right click on the headline in agenda view and it will show you that headline in the main window in a sparse tree context.
You may have to collapse everything in the main window in order for the right-click-locating to show the sparse-tree view.
That seems pretty close to what you're looking for. To check, do this:
Create desired agenda view.
In main document window collapse everything to just first level headlines.
Right-click on the desired headline in the agenda view. It should show the headline in sparse tree context in the main document window.
There are several things you can do to get better information about context in agenda views, short of using the right-click function described above.
First, you can arrange your headlines themselves so that they give you more context information. It would be possible, e.g., to have numerous 4th level headlines labeled 'Tasks', each which includes tasks related to the headings above in each tree. That's not going to give good context info in agenda view, though, since each line's headline text would be the same (i.e., 'Task') and have no info in context. A simple solution would simply be to make the headlines more specific, e.g., 'Project xxxx Tasks' and 'Project yyy Tasks'.
A different way of getting more context in agenda view would be by using 'categories'. The first column in agenda view is the filename containing the headline by default, but if the headline has a category the category will be shown. To assign a category to a headline and all of its subtree you can add a category property to the main headline, like this:
:PROPERTIES:
:CATEGORY:Project xxx Stuff
:END:
Now agenda view will show 'Project xxx Stuff' in the first column for each of the agenda lines that are gathered from that headlines subtree.
Maybe an agenda is not really what you need. I would use this:
`M-x org-sparse-tree RET D'
then select the date range and navigate through the results.
HTH
Follow-mode (S-f) gets pretty close to what the OP is looking for. Credit to #armando.sano in a comment on another answer.