Permalink
Browse files

Provide more consistent regexps for headlines

* lisp/org-agenda.el (org-search-view): Simplify regexp.
(org-agenda-get-todos): Use new format string.
* lisp/org-archive.el (org-archive-all-done): Simplify regexp.
* lisp/org-ascii.el (org-export-as-ascii): More accurate regexp.
* lisp/org-colview-xemacs.el (org-columns-capture-view): Use new
  format string and new string.
* lisp/org-colview.el (org-columns-capture-view): Use new format
  string and new string.
* lisp/org-docbook.el (org-export-as-docbook): More accurate
  regexp.  Also use new regexp to match generic headlines.
* lisp/org-exp.el (org-export-protect-quoted-subtrees): More accurate
  regexp.  Also use new regexp to match generic headlines.
* lisp/org-html.el (org-export-as-html): More accurate regexp.  Also
  use new regexp to match generic headlines.
* lisp/org-mouse.el (org-mouse-match-todo-keyword): Removed unused
  and now erroneous function.
* lisp/org.el (org-heading-regexp, org-heading-keyword-regexp-format):
  New variables.
(org-set-regexps-and-options): Create regexps according to the
following rule: use spaces only to separate elements from an headline,
while allowing mixed tabs and spaces for any indentation job.
(org-nl-done-regexp, org-looking-at-done-regexp): Removed variables.
(org-set-font-lock-defaults): Fontify again headlines with a keyword
and no other text.  Use new format strings.
(org-get-heading, org-toggle-comment, org-prepare-agenda-buffers,
org-toggle-fixed-width-section): Use new format string.
(org-todo): More accurate regexps.
(org-point-at-end-of-empty-headline): Simplify regexp.
(org-insert-heading): Headline can sometimes be nil.

This patch attempts to reduce the number of hard-coded headlines, by
providing two format strings and one generic string to cover most of
the cases of headline construction.
  • Loading branch information...
1 parent 440ec7e commit dfcb6faef11a2439b56b18a6289803361d402130 Nicolas Goaziou committed Aug 24, 2011
Showing with 147 additions and 120 deletions.
  1. +19 −16 lisp/org-agenda.el
  2. +1 −1 lisp/org-archive.el
  3. +2 −2 lisp/org-ascii.el
  4. +3 −2 lisp/org-colview-xemacs.el
  5. +3 −2 lisp/org-colview.el
  6. +4 −3 lisp/org-docbook.el
  7. +4 −2 lisp/org-exp.el
  8. +4 −3 lisp/org-html.el
  9. +0 −7 lisp/org-mouse.el
  10. +107 −82 lisp/org.el
View
@@ -3887,7 +3887,7 @@ in `org-agenda-text-search-extra-files'."
(if (not regexps+)
(setq regexp org-outline-regexp-bol)
(setq regexp (pop regexps+))
- (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
+ (if hdl-only (setq regexp (concat org-outline-regexp-bol " .*?"
regexp))))
(setq files (org-agenda-files nil 'ifmode))
(when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
@@ -4593,18 +4593,21 @@ the documentation of `org-diary'."
'help-echo
(format "mouse-2 or RET jump to org file %s"
(abbreviate-file-name buffer-file-name))))
- (regexp (concat "^\\*+[ \t]+\\("
- (if org-select-this-todo-keyword
- (if (equal org-select-this-todo-keyword "*")
- org-todo-regexp
- (concat "\\<\\("
- (mapconcat 'identity
- (org-split-string
- org-select-this-todo-keyword "|") "\\|")
- "\\)\\>"))
- org-not-done-regexp)
- "[^\n\r]*\\)"))
- marker priority category org-category-pos tags todo-state ee txt beg end)
+ (regexp (format org-heading-keyword-regexp-format
+ (cond
+ ((and org-select-this-todo-keyword
+ (equal org-select-this-todo-keyword "*"))
+ org-todo-regexp)
+ (org-select-this-todo-keyword
+ (concat "\\("
+ (mapconcat 'identity
+ (org-split-string
+ org-select-this-todo-keyword
+ "|")
+ "\\|") "\\)"))
+ (t org-not-done-regexp))))
+ marker priority category org-category-pos tags todo-state
+ ee txt beg end)
(goto-char (point-min))
(while (re-search-forward regexp nil t)
(catch :skip
@@ -4616,11 +4619,11 @@ the documentation of `org-diary'."
(goto-char (1+ beg))
(or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
(throw :skip nil)))
- (goto-char (match-beginning 1))
+ (goto-char (match-beginning 2))
(setq marker (org-agenda-new-marker (match-beginning 0))
category (org-get-category)
org-category-pos (get-text-property (point) 'org-category-position)
- txt (match-string 1)
+ txt (match-string 2)
tags (org-get-tags-at (point))
txt (org-agenda-format-item "" txt category tags)
priority (1+ (org-get-priority txt))
@@ -4632,7 +4635,7 @@ the documentation of `org-diary'."
'type "todo" 'todo-state todo-state)
(push txt ee)
(if org-agenda-todo-list-sublevels
- (goto-char (match-end 1))
+ (goto-char (match-end 2))
(org-end-of-subtree 'invisible))))
(nreverse ee)))
View
@@ -404,7 +404,7 @@ sibling does not exist, it will be created at the end of the subtree."
If the cursor is not on a headline, try all level 1 trees. If
it is on a headline, try all direct children.
When TAG is non-nil, don't move trees, but mark them with the ARCHIVE tag."
- (let ((re (concat org-outline-regexp-bol "+" org-not-done-regexp)) re1
+ (let ((re org-not-done-heading-regexp) re1
(rea (concat ".*:" org-archive-tag ":"))
(begm (make-marker))
(endm (make-marker))
View
@@ -283,7 +283,7 @@ publishing directory."
"UNTITLED"))
(email (plist-get opt-plist :email))
(language (plist-get opt-plist :language))
- (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
+ (quote-re0 (concat "^\\(" org-quote-string "\\)\\( +\\|[ \t]*$\\)"))
(todo nil)
(lang-words nil)
(region
@@ -406,7 +406,7 @@ publishing directory."
txt))
(setq txt (replace-match "" t t txt)))
(if (string-match quote-re0 txt)
- (setq txt (replace-match "" t t txt)))
+ (setq txt (replace-match "" t t txt 1)))
(if org-export-with-section-numbers
(setq txt (concat (org-section-number level)
@@ -1317,12 +1317,13 @@ of fields."
(if (featurep 'xemacs)
(save-excursion
(let* ((title (mapcar 'cadr org-columns-current-fmt-compiled))
- (re-comment (concat "\\*+[ \t]+" org-comment-string "\\>"))
+ (re-comment (format org-heading-keyword-regexp-format
+ org-comment-string))
(re-archive (concat ".*:" org-archive-tag ":"))
(n (length title)) row tbl)
(goto-char (point-min))
- (while (re-search-forward "^\\(\\*+\\) " nil t)
+ (while (re-search-forward org-heading-regexp nil t)
(catch 'next
(when (and (or (null maxlevel)
(>= maxlevel
View
@@ -1152,11 +1152,12 @@ containing the title row and all other rows. Each row is a list
of fields."
(save-excursion
(let* ((title (mapcar 'cadr org-columns-current-fmt-compiled))
- (re-comment (concat "\\*+[ \t]+" org-comment-string "\\>"))
+ (re-comment (format org-heading-keyword-regexp-format
+ org-comment-string))
(re-archive (concat ".*:" org-archive-tag ":"))
(n (length title)) row tbl)
(goto-char (point-min))
- (while (re-search-forward "^\\(\\*+\\) " nil t)
+ (while (re-search-forward org-heading-regexp nil t)
(catch 'next
(when (and (or (null maxlevel)
(>= maxlevel
View
@@ -498,8 +498,9 @@ publishing directory."
;; We will use HTML table formatter to export tables to DocBook
;; format, so need to set html-table-tag here.
(html-table-tag (plist-get opt-plist :html-table-tag))
- (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
- (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
+ (quote-re0 (concat "^ *" org-quote-string "\\( +\\|[ \t]*$\\)"))
+ (quote-re (format org-heading-keyword-regexp-format
+ org-quote-string))
(inquote nil)
(infixed nil)
(inverse nil)
@@ -969,7 +970,7 @@ publishing directory."
(push (cons num 1) footref-seen))))))
(cond
- ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
+ ((string-match "\\(\\*+\\)\\(?: +\\(.*?\\)\\)?[ \t]*$" line)
;; This is a headline
(setq level (org-tr-level (- (match-end 1) (match-beginning 1)
level-offset))
View
@@ -1638,7 +1638,8 @@ from the buffer."
(defun org-export-protect-quoted-subtrees ()
"Mark quoted subtrees with the protection property."
- (let ((org-re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
+ (let ((org-re-quote (format org-heading-keyword-regexp-format
+ org-quote-string)))
(goto-char (point-min))
(while (re-search-forward org-re-quote nil t)
(goto-char (match-beginning 0))
@@ -1932,7 +1933,8 @@ table line. If it is a link, add it to the line containing the link."
(defun org-export-remove-comment-blocks-and-subtrees ()
"Remove the comment environment, and also commented subtrees."
- (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
+ (let ((re-commented (format org-heading-keyword-regexp-format
+ org-comment-string))
case-fold-search)
;; Remove comment environment
(goto-char (point-min))
View
@@ -1175,8 +1175,9 @@ PUB-DIR is set, use this as the publishing directory."
(plist-get opt-plist :link-home)))
(dummy (setq opt-plist (plist-put opt-plist :title title)))
(html-table-tag (plist-get opt-plist :html-table-tag))
- (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
- (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
+ (quote-re0 (concat "^ *" org-quote-string "\\( +\\|[ \t]*$\\)"))
+ (quote-re (format org-heading-keyword-regexp-format
+ org-quote-string))
(inquote nil)
(infixed nil)
(inverse nil)
@@ -1647,7 +1648,7 @@ lang=\"%s\" xml:lang=\"%s\">
t t line))))))
(cond
- ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
+ ((string-match "\\(\\*+\\)\\(?: +\\(.*?\\)\\)?[ \t]*$" line)
;; This is a headline
(setq level (org-tr-level (- (match-end 1) (match-beginning 1)
level-offset))
View
@@ -631,13 +631,6 @@ This means, between the beginning of line and the point."
(set-match-data ',match)
(apply ',function rest)))))
-(defun org-mouse-match-todo-keyword ()
- (save-excursion
- (org-back-to-heading)
- (if (looking-at org-outline-regexp) (goto-char (match-end 0)))
- (or (looking-at (concat " +" org-todo-regexp " *"))
- (looking-at " \\( *\\)"))))
-
(defun org-mouse-yank-link (click)
(interactive "e")
;; Give temporary modes such as isearch a chance to turn off.
Oops, something went wrong.

0 comments on commit dfcb6fa

Please sign in to comment.