Org mode insert heading behaving stranglely - emacs

I probably have some broken config but I can't figure out what I set to break this.
If I have an outline like
* Heading
** Subheading1
** Subheading2
If I hit M-return or C-return when the cursor is at subheading1 I end up with
* Heading
** Subheading1
**
** Subheading2
It should be producing a new subheading, but instead produces something indented which is not treated as a sub heading.
Anyone know how I broke my org mode?

Related

Emacs org-mode: wrong indentation and missing stars

After updating org to the latest version (configuration unchanged), I face the problem that the structure is not displayed properly.
In text mode, the structure looks like this:
* heading 1
** heading 2
*** heading 3
**** heading 4
In Org-mode, with org-indent-mode switched on, it looks different (note: switching org-indent-mode off does only change indentation, not the look):
* heading 1
* heading 2
heading 3
heading 4
It seems, that for some reason the indentation for heading 3 and subsequent headings is broken. org-current-level returns the correct level for each heading.
This behaviour is reproducable with a clean org file.
System is org 9.1.3, emacs 25.1.1 on Win10.

Is there some kind of narrow-to-context in org-mode?

Org's narrow-to-subtree is wonderful, but sometimes I also want to see the chain of parent nodes, without all the uncle nodes.
For example, given this tree:
* a
** a.a <- extraneous great uncle
** a.b
*** a.b.a <- extraneous uncle
*** a.b.b <- want to see context for this
**** a.b.b.a
**** a.b.b.b
I want to narrow my view to see this:
* a
** a.b
*** a.b.b <- want to see context for this
**** a.b.b.a
**** a.b.b.b
How can I make this happen?
AFAIK, there is no such narrowing facility - but the function org-display-outline-path will display "a/a.b" for the heading in question, i.e. the outline path of headings above your current heading. You can add the function to the modeline indicator if you want it to be permanently visible - or perhaps use the (normally absent) header line which has more space to grow. Try with this file:
* foo
#+BEGIN_SRC emacs-lisp
(setq header-line-format '(:eval (org-display-outline-path)))
#+END_SRC
#+RESULTS:
: (:eval (org-display-outline-path))
** bar
*** baz
Evaluate the code block to set the header-line-format-variable and then see what the header line says when the cursor is on the "** bar" header or the "*** baz" header.

How do I move text back to just under the parent level

* Parent
Some text under this level
** Headline below parent
** Another Headline at the same level
I don't want this text to be a headline but be indented same as the text under the parent level without being a headline. Cannot do this.
I just cannot re-indent this text just below the parent level here
* Another top-level headline
Is there any way in org-mode to re-indent plain text back to the same indent level as the plain text just under the parent level but below several headlines under the parent?
I am trying to do something like this:
* A Section
Introductory text.....
** Subsection 1
** Subsection 2
Further Reading
Now, that "Further Reading" is not a headline, I don't want it to be one. However, I cannot "get out of" Subsection 2: Anything I type below it is a part of it. Perhaps I need to structure this some other way such as using lists instead of headlines.
There is no way to do this in org, currently - there is no syntax that ends a subheader to return you to the previous level. But you could add a subsection at the same level - e.g. in your example,
* A Section
Introductory text.....
** Subsection 1
Subsection 1 text
** Subsection 2
Subsection 2 text
** Further Reading
Some further reading
It might be nice if org had some syntax, like **-, that would end a subsection, but I'm not sure how involved a change that would be - probably pretty extensive.

Orgmode: Show number of children under heading

I have a heading in my orgmode file. It is automatically updated periodically with new children. I want the heading line to show the number of children.
So if I have one child it would say something like (1)
* Heading (1)
** Subheading
After it gets updated with another subheading the number should automatically be changed to (2)
* Heading (2)
** Subheading
** A new added subheading
I want it to do this because the toplevel heading will normally be collapsed. I want to be able to see if any new children were added to it without having to expand it
What's most similar to what you're searching are called statistics cookies. They're described at the end of this page in the manual. At first meant for lists, but that can also count headlines. Just put [/] at the end of your header, like so :
* Main header [/]
** sub-header 1
** sub-header 2
** sub-header 3
And press C-c C-c on the cookie to update it (make it update its count). What you do need to add to what you describe to be your use-case is TODO keywords to your headers, because what the cookie will count is how many are done over how many are to do. Therefore I suggest you mark them all as DONE, like so :
* Main header [3/3]
** DONE sub-header 1
** DONE sub-header 2
** DONE sub-header 3
Then, the counter will show you what you want.
You could probably adapt these cookies' code to meet your precise needs.

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.