There exist functions to set tags, keywords, and priority values (org-set-tags-to, org-todo, and org-priority respectively), but what about setting the heading (item) itself?

For example:

*** TODO [#B] Some existing heading                      :URGENT:

(my/org-set-heading "The new heading")

*** TODO [#B] The new heading                            :URGENT:

Setting the heading is non-trivial; the logic needs to be mindful of outline folding, heading stars, the priority label, and tags-- at the very least. Is there an org function that accomplishes this (or a 3rd-party library that includes one)?

I haven't found any org functions that accomplish this, but my apropos-fu has certainly failed me before.

A fairly thorough search suggests that I'll need to employ org-complex-heading-regexp, special care to the subtree/folding, and possibly a patch request.


2 Answers 2


Here is a way to get there with org-dp (https://github.com/tj64/org-dp, and its on MELPA):

(require 'org-dp)

(let ((hl (progn

   nil ;; type.
   (buffer-substring (org-element-property :contents-begin hl)
             (org-element-property :contents-end hl))
   t ;; replace
   '(:title "new headline")

You could wrap this in a function that sets the title to what you want. I think org-dp-rewire is what you want.

  • This does the trick in setting the heading, but creates an issue of its own. It inserts an org 'NAME' keyword (#+NAME: ) line immediately before the modified heading. Do you observe this same behavior?
    – ebpa
    Dec 6, 2016 at 1:40
  • no I don't see that. I am using org 9, and org-dp from MELPA today. Dec 6, 2016 at 2:05
  • 1
    I just noticed if the headline has a NAME property then I see that. I am not sure what to do about that. Maybe raise it as an issue with org-dp. Dec 6, 2016 at 2:20
  • Nice catch! 👏👏 I was in the process of upgrading to 9 and hadn't started troubleshooting yet. Indeed the headings have "name" properties. I'll create an issue on org-dp. The org name keyword probably needs a prefixed syntax in org-dp.
    – ebpa
    Dec 6, 2016 at 2:27

Out of the box org-mode provides a function called org-edit-headline, which changes the title and doesn't mess with todo state, priority or tags.

(org-edit-headline "The new heading")

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.