emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Insert TODO or plain heading depending on context
@ 2010-08-05 15:43 Nathan Neff
  2010-08-10 21:41 ` Nathan Neff
  0 siblings, 1 reply; 4+ messages in thread
From: Nathan Neff @ 2010-08-05 15:43 UTC (permalink / raw)
  To: emacs-orgmode

Sorry for a rudimentary question, but someone almost certainly has
done this before:

I'd like define a function that would:
a) Create a new heading if the cursor is on a heading or the body of a heading.
or
b) Create a new TODO heading if the cursor is on a TODO heading or the body
of a TODO heading.

Essentially, it would be a "smart" function to either press M-Return
or M-S-Return,
depending on the context.

I realize I can press M-Return to always create a new heading, and
M-S-Return to always create a new TODO, but I'd like to eliminate
an extra keypress for the most common cases.

Any ideas?

Thanks,
--Nate

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Insert TODO or plain heading depending on context
  2010-08-05 15:43 Insert TODO or plain heading depending on context Nathan Neff
@ 2010-08-10 21:41 ` Nathan Neff
  2010-08-10 22:07   ` Jan Böcker
  0 siblings, 1 reply; 4+ messages in thread
From: Nathan Neff @ 2010-08-10 21:41 UTC (permalink / raw)
  To: emacs-orgmode

Sorry for the bump -- maybe I'll phrase the question differently ----

Is there a function in org-mode that returns the TODO
status of the heading that the cursor is currently in?

Thanks,
--Nate

On Thu, Aug 5, 2010 at 10:43 AM, Nathan Neff <nathan.neff@gmail.com> wrote:
> Sorry for a rudimentary question, but someone almost certainly has
> done this before:
>
> I'd like define a function that would:
> a) Create a new heading if the cursor is on a heading or the body of a heading.
> or
> b) Create a new TODO heading if the cursor is on a TODO heading or the body
> of a TODO heading.
>
> Essentially, it would be a "smart" function to either press M-Return
> or M-S-Return,
> depending on the context.
>
> I realize I can press M-Return to always create a new heading, and
> M-S-Return to always create a new TODO, but I'd like to eliminate
> an extra keypress for the most common cases.
>
> Any ideas?
>
> Thanks,
> --Nate
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Re: Insert TODO or plain heading depending on context
  2010-08-10 21:41 ` Nathan Neff
@ 2010-08-10 22:07   ` Jan Böcker
  2010-08-10 22:52     ` Nathan Neff
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Böcker @ 2010-08-10 22:07 UTC (permalink / raw)
  To: Nathan Neff; +Cc: emacs-orgmode

On 08/10/2010 11:41 PM, Nathan Neff wrote:
> Is there a function in org-mode that returns the TODO
> status of the heading that the cursor is currently in?
> 

Yes, try "org-get-todo-state". (Found this using C-h f, typing "org",
then using I-Search in the completion buffer.)
This returns something like this:

#("NEXT" 0 4 (fontified t org-category #("org-dev" 0 7 (fontified t face
org-property-value org-category "projects")) face org-todo))

or nil if there is no TODO state.

This syntax is new to me (elisp noob here), but the elisp reference told
me it's just a string with text properties.

The following code seems to accomplish your goal:

(defun jb/smart-insert-heading ()
  (if (org-get-todo-state)
	   (call-interactively 'org-insert-todo-heading)
	 (call-interactively 'org-insert-heading)))

HTH, Jan

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Re: Insert TODO or plain heading depending on context
  2010-08-10 22:07   ` Jan Böcker
@ 2010-08-10 22:52     ` Nathan Neff
  0 siblings, 0 replies; 4+ messages in thread
From: Nathan Neff @ 2010-08-10 22:52 UTC (permalink / raw)
  To: Jan Böcker, emacs-orgmode

On Tue, Aug 10, 2010 at 5:07 PM, Jan Böcker <jan.boecker@jboecker.de> wrote:
> On 08/10/2010 11:41 PM, Nathan Neff wrote:
>> Is there a function in org-mode that returns the TODO
>> status of the heading that the cursor is currently in?
>>
>
> Yes, try "org-get-todo-state". (Found this using C-h f, typing "org",
> then using I-Search in the completion buffer.)
> This returns something like this:
>
> #("NEXT" 0 4 (fontified t org-category #("org-dev" 0 7 (fontified t face
> org-property-value org-category "projects")) face org-todo))
>
> or nil if there is no TODO state.
>
> This syntax is new to me (elisp noob here), but the elisp reference told
> me it's just a string with text properties.
>
> The following code seems to accomplish your goal:
>
> (defun jb/smart-insert-heading ()
>  (if (org-get-todo-state)
>           (call-interactively 'org-insert-todo-heading)
>         (call-interactively 'org-insert-heading)))
>
> HTH, Jan
>

Thanks Jan, this helped a lot!  I appreciate the C-h f reminder -- I
have searched
through org.el and didn't come up with the right search terms.  This
should help me in
the future.

BTW, your function works perfectly!

Thanks,
--Nate

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-08-10 23:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-05 15:43 Insert TODO or plain heading depending on context Nathan Neff
2010-08-10 21:41 ` Nathan Neff
2010-08-10 22:07   ` Jan Böcker
2010-08-10 22:52     ` Nathan Neff

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).