mikemc / neorg-doom

Module for Neorg inspired by Doom Emacs
GNU General Public License v3.0
1 stars 0 forks source link

Create `toggle-heading` keybind #2

Open mikemc opened 8 months ago

mikemc commented 8 months ago

In Doom Emacs, :localleader: h triggers org-toggle-heading, providing a handy way to convert a line(s) into a heading(s). The org-mode documentation is shown below and describes a broad set of functionality. I would be happy to start with being able to toggle the heading status of a single line in normal mode.

Signature (org-toggle-heading &optional NSTARS)

Documentation Convert headings to normal text, or items or text to headings.

If there is no active region, only convert the current line.

With a C-u prefix, convert the whole list at point into heading.

In a region:

  • If the first non blank line is a headline, remove the stars from all headlines in the region.

  • If it is a normal line, turn each and every normal line (i.e., not an heading or an item) in the region into headings. If you want to convert only the first line of this region, use one universal prefix argument.

  • If it is a plain list item, turn all plain list items into headings. The checkboxes are converted to appropriate TODO or DONE keywords (using car or org-done-keywords and org-not-done-keywords when available).

When converting a line into a heading, the number of stars is chosen such that the lines become children of the current entry. However, when a numeric prefix argument is given, its value determines the number of stars to add.

Key Bindings org-mode-map \<emacs-state> M-SPC m h org-mode-map \<insert-state> M-SPC m h org-mode-map \<motion-state> , h org-mode-map \<normal-state> , h org-mode-map \<visual-state> , h

mikemc commented 8 months ago

The version in 14996f5 does not reindent when removing a heading. To properly handle the indentation when removing a focal heading, I should get the indentation level from the previous heading (the heading above the focal heading), then use that to reindent the (former) child text of the (former) focal heading.

mikemc commented 8 months ago

toggle_heading() does not work when at the base document level outside of any heading, as when making the first heading in a new document - it throws an error "attempt to concatenate local 'prefix' (a nil value)"

Edit: This issue is fixed by b6f5619