13

Q:  How can org-mode be configured so that (org-entry-get nil "title") returns the headline title?

I have seen three variations of org-entry-get where the string argument title is in all lowercase, all uppercase, or initial caps. The default org-mode configuration does not return anything in all three cases:

** Active [#A] 0 @ index. :lawlist:
  DEADLINE: <2016-12-31 Sat>
  :PROPERTIES:
  :Effort:
  :Hash: 8ae546845cebbc4d25ccdcf23eade44e
  :ToodledoFolder: TASKS
  :ToodledoGoal:
  :ToodledoID: 394554265
  :ToodledoLocation:
  :END:

(setq org-todo-keywords '((sequence
  "Active(a)"
  "Next Action(n)"
  "Canceled(c)"
  "Hold(h)"
  "Reference(r)"
  "Delegated(d)"
  "Waiting(w)"
  "Postponed(P)"
  "Someday(s)"
  "Planning(p)"
  "|"
  "None(N)")))

Here is a function I found that uses org-get-heading if org-entry-get fails:

(let ((title (if (org-entry-get nil "title")
                 (org-entry-get nil "title")
                 (org-get-heading t t))))
  (substring-no-properties title))

And, here is yet another method: (org-element-property :title (org-element-at-point))

2 Answers 2

18

First to fix terminology, I think you are asking for the "heading" of the entry. "Title" usually refers to the document title in org-mode.

With org-mode version 9.0.3 there is a function to retrieve elements of the heading, `org-heading-components', which returns a list whose 5th element is the title. Thus the title my be retrieved by

(nth 4 (org-heading-components))

However, org-mode also maps the heading to a property. Its name is not quite logical, but running org-entry-properties reveals that it is stored under ITEM. Thus you are looking for

(org-entry-get nil "ITEM")
3
  • When the org-todo-keywords is defined, (nth 4 (org-heading-components)) will return "0 @ index.". However, (org-entry-get nil "ITEM") still returns nil.
    – lawlist
    Commented Jan 8, 2017 at 18:23
  • "0 @ index." is correct. What were you hoping for? Also, you must be doing something wrong. (org-entry-get nil "ITEM") also returns "0 @ index." for me. Commented Jan 8, 2017 at 21:40
  • 1
    @John Kitchin -- thank you for confirming the expected behavior. It turns out that the version of org-mode that ships with Emacs 25.1.1 is 8.2.10 and it does not support extracting "ITEM" with org-entry-get. The most recent version of org-mode that can be installed separately is 9.0.3 and it does indeed support this feature. I have posted an alternative answer explaining the issue, but will accept the answer by @Andrew Swann because most people will opt to simply upgrade to the latest version of org-mode.
    – lawlist
    Commented Jan 9, 2017 at 2:43
2

The current stable version of Emacs as of 01/08/2017 is 25.1.1, which was released on or about 09/20/2016. The version of org-mode that ships with the aforementioned version of Emacs is 8.2.10. The current stable of release of org-mode as of 01/08/2017 is 9.0.3.

As to org-mode version 8.2.10, "ITEM" is not a member of org-special-properties by default. As to org-mode version 8.2.10, the function org-entry-properties does not have a subsection specifically allocated to extracting the "ITEM". Here is what the missing snippet would look like if someone wanted to add this feature -- the logical place to plug this snippet in would be between the section dealing with "PRIORITY" and the section dealing with "FILE":

(when (or (not specific) (string= specific "ITEM"))
  (let ((case-fold-search nil))
    (when (looking-at org-complex-heading-regexp)
      (push (cons "ITEM"
                  (let ((title (match-string-no-properties 4)))
                    (if (org-string-nw-p title)
                      (org-remove-tabs title)
                      "")))
            props))))

As to org-mode version 9.0.3, "ITEM" is a member of org-special-properties by default. As to org-mode version 9.0.3, the function org-entry-properties already has a dedication section to deal with "ITEM" -- said function has also evolved in other aspects since 8.2.10 (e.g., catch 'exit and throw exit ...).

Since most people will likely upgrade to the most recent version of org-mode, @lawlist will accept the answer of @Andrew Swann.

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.