My preferred implementation
This alternative solution will not act as a toggle, but it will directly convert Heading
to * TODO Heading
on hitting C-c C-t
(The Shift bindings will not work here).
The advantage of this approach is that you do not need to remember a new function or binding just for this special plain text to TODO conversion; the C-c C-t
default binding for org-todo
will work in DWIM fashion.
For instance, both of the below conversions happen when using the same C-c C-t
binding:
Heading▮ -- (C-c C-t)--> * TODO Heading▮
* Heading▮ -- (C-c C-t)--> * TODO Heading▮
Implementation
(defun modi/org-first-convert-to-heading (orig-fun &rest args)
(let ((is-heading))
(save-excursion
(forward-line 0)
(when (looking-at "^\\*")
(setq is-heading t)))
(unless is-heading
(org-toggle-heading))
(apply orig-fun args)))
(advice-add 'org-todo :around #'modi/org-first-convert-to-heading)
You need to be using emacs 24.4+ for the above advice system to work.
Toggle current line between a non-heading and TODO
heading
Below function will work on a non-empty line as follows:
If the line contains
Heading▮
M-x my/org-toggle-heading-and-todo
will convert that to,
* TODO Heading▮
Calling that function again will convert it back to,
Heading▮
Defining my/org-toggle-heading-and-todo
(defun my/org-toggle-heading-and-todo ()
"Toggles the current line between a non-heading and TODO heading."
(interactive)
(let ((is-heading))
(save-excursion
(forward-line 0)
(when (looking-at "^\\*")
(setq is-heading t)))
(if is-heading
(progn
(org-todo 'none) ; remove TODO
(org-toggle-heading)) ; remove heading
(progn
(org-toggle-heading) ; convert to heading
(org-todo 'nextset))))) ; add TODO
Cycle only the TODO
states
While the point is anywhere on the heading, S-right
/S-left
will cycle through all the TODO
states. This works even if shift-select-mode
is t
. The key is to have the point/cursor on the heading. I also noticed that the org-treat-S-cursor-todo-selection-as-state-change
is t
by default (and that's why the shift bindings for changing TODO
states work).
Example:
Below, the point is on the heading
* Heading▮
After pressing S-right
, I get,
* TODO Heading▮
After pressing S-left
, I once again get,
* Heading▮
Reference
My org version as of writing this is 8.2.10.
abc
or a list element- abc
to* abc
using the default bindingC-c *
.C-c -
will convert to a list element instead of heading.