I'm trying to create a regexp that will work for two (2) kinds of situations -- an org headline and maybe a second line containing a deadline and/or scheduled (if they exists). I've tried variations using question-marks throughout the second line of the regexp, but to no avail. As soon as I include the regexp for the second line, the heading with Someday ...
is excluded. The second line looks like this: \n\\(?: +\\(DEADLINE\\|SCHEDULED\\)\\): <\\([^>]+\\)>\\(?: +\\(DEADLINE\\|SCHEDULED\\)\\): <\\([^>]+\\)>
The goal, please, would be to select both of the following examples:
** Active [#A] 0 @ Contains a deadline and is scheduled. :event:lawlist:
DEADLINE: <2013-12-21 Sat 17:00> SCHEDULED: <2013-12-21 Sat>
** Active [#B] 0 @ Contains a deadline, but is not scheduled. :event:lawlist:
DEADLINE: <2013-12-22 Sun 08:00>
** Someday [#D] 0 @ No deadline, and not scheduled. :lawlist:
(defvar lawlist-super-duper-regexp "^\\(\\*+\\)\\(?: +\\(Active\\|Someday\\)\\)?\\(?: +\\(\\[#.\\]\\)\\)?\\(?: +\\(.*?\\)\\)??\\(?:[ ]+\\(:[[:alnum:]_@#%:]+:\\)\\)?[ ]*\n\\(?: +\\(DEADLINE\\|SCHEDULED\\)\\): <\\([^>]+\\)>\\(?: +\\(DEADLINE\\|SCHEDULED\\)\\): <\\([^>]+\\)>"
"Custom match every element of the headline, plus every element of second line with a deadline or scheduled.")
EDIT (December 17, 2013): First working draft . . .
EDIT (December 18, 2013): I broke something during the last 24 hours, so I'm posting the working code again just in case the broken solution was inadvertently posted yesterday.
(defvar lawlist-org-heading-regexp "^\\(\\*+\\)\\(?: +\\(.*?\\)\\)?[ \t]*\\(\n.*DEADLINE.*$\\)"
"Custom match org headline, plus the second line with a deadline.")
(defvar lawlist-super-duper-regexp "^\\(\\*+\\)\\(?: +\\(Active\\|Next Action\\|Reference\\|Someday\\|Delegated\\|None\\)\\)?\\(?: +\\(\\[#.\\]\\)\\)?\\(?: +\\(.*?\\)\\)??\\(?:[ ]+\\(:[[:alnum:]_@#%:]+:\\)\\)?[ ]*\\(?:\n\\)\\(?: +\\(DEADLINE:\\|SCHEDULED:\\)\\)?\\(?: +\\(<\\)\\([^>]+\\)\\(>\\)\\)?\\(?: +\\(DEADLINE:\\|SCHEDULED:\\)\\)?\\(?: +\\(<\\)\\([^>]+\\)\\(>\\)\\)?"
"Custom match every element of the headline, plus every element of second line with a deadline or scheduled (if they exist).")
(defun org-get-super-duper-heading ()
(when (looking-at lawlist-super-duper-regexp)
(concat
(when (not (equal (match-string 1) nil))
(match-string 1))
(when (not (equal (match-string 2) nil))
(concat " " (match-string 2)))
(when (not (equal (match-string 3) nil))
(concat " " (match-string 3)))
(when (not (equal (match-string 4) nil))
(concat " " (match-string 4)))
(when (not (equal (match-string 5) nil))
(concat " " (match-string 5)))
(when (not (equal (match-string 6) nil))
(concat "\n " (match-string 6)))
(when (not (equal (match-string 7) nil))
(concat " " (match-string 7)))
(when (not (equal (match-string 8) nil))
(match-string 8))
(when (not (equal (match-string 9) nil))
(match-string 9))
(when (not (equal (match-string 10) nil))
(concat " " (match-string 10)))
(when (not (equal (match-string 11) nil))
(concat " " (match-string 11)))
(when (not (equal (match-string 12) nil))
(match-string 12))
(when (not (equal (match-string 13) nil))
(match-string 13)))))
(defun lawlist-org-get-heading (&optional no-tags no-todo)
"Return the heading of the current entry, without the stars.
When NO-TAGS is non-nil, don't include tags.
When NO-TODO is non-nil, don't include TODO keywords."
(save-excursion
(org-back-to-heading t)
(cond
((and no-tags no-todo)
(looking-at org-complex-heading-regexp)
(match-string 4))
(no-tags
(looking-at (concat org-outline-regexp
"\\(.*?\\)"
"\\(?:[ \t]+:[[:alnum:]:_@#%]+:\\)?[ \t]*$"))
(match-string 1))
(no-todo
(looking-at org-todo-line-regexp)
(match-string 3))
(t (looking-at org-heading-regexp)
(concat
(match-string 1)
" "
(match-string 2)
(if (and (looking-at lawlist-org-heading-regexp) (match-string 3))
(match-string 3)) )))))