Fix COMMENT keyword when stacked with a regular keyword

* lisp/org.el (org-set-font-lock-defaults): Fix headline fontification
  when keywords are stacked.
(org-toggle-comment): Properly toggle COMMENT keyword when a regular
keyword is already present.
(org-todo, org-agenda-prepare-buffers): Correctly match a commented
heading.
* lisp/org-colview.el (org-columns-capture-view): Correctly match
  a commented heading.

* testing/lisp/test-org.el (test-org/toggle-comment): New test.
This commit is contained in:
Nicolas Goaziou 2014-03-24 21:46:00 +01:00
parent 11f8efcda1
commit fea23d3da2
3 changed files with 82 additions and 24 deletions

View File

@ -1201,8 +1201,6 @@ containing the title row and all other rows. Each row is a list
of fields." of fields."
(save-excursion (save-excursion
(let* ((title (mapcar 'cadr org-columns-current-fmt-compiled)) (let* ((title (mapcar 'cadr org-columns-current-fmt-compiled))
(re-comment (format org-heading-keyword-regexp-format
org-comment-string))
(re-archive (concat ".*:" org-archive-tag ":")) (re-archive (concat ".*:" org-archive-tag ":"))
(n (length title)) row tbl) (n (length title)) row tbl)
(goto-char (point-min)) (goto-char (point-min))
@ -1214,9 +1212,9 @@ of fields."
(/ (1+ (length (match-string 1))) 2) (/ (1+ (length (match-string 1))) 2)
(length (match-string 1))))) (length (match-string 1)))))
(get-char-property (match-beginning 0) 'org-columns-key)) (get-char-property (match-beginning 0) 'org-columns-key))
(when (save-excursion (when (or (org-in-commented-heading-p t)
(goto-char (point-at-bol)) (save-excursion
(or (looking-at re-comment) (beginning-of-line)
(looking-at re-archive))) (looking-at re-archive)))
(org-end-of-subtree t) (org-end-of-subtree t)
(throw 'next t)) (throw 'next t))

View File

@ -6357,9 +6357,11 @@ needs to be inserted at a specific position in the font-lock sequence.")
;; Code ;; Code
'(org-activate-code (1 'org-code t)) '(org-activate-code (1 'org-code t))
;; COMMENT ;; COMMENT
(list (format org-heading-keyword-regexp-format (list (format
(concat "\\(" org-comment-string "\\)")) "^\\*\\(?: +%s\\)?\\(?: +\\[#[A-Z0-9]\\]\\)? +\\(?9:%s\\)\\(?: \\|$\\)"
'(2 'org-special-keyword t)) org-todo-regexp
org-comment-string)
'(9 'org-special-keyword t))
;; Blocks and meta lines ;; Blocks and meta lines
'(org-fontify-meta-lines-and-blocks)))) '(org-fontify-meta-lines-and-blocks))))
(setq org-font-lock-extra-keywords (delq nil org-font-lock-extra-keywords)) (setq org-font-lock-extra-keywords (delq nil org-font-lock-extra-keywords))
@ -12190,17 +12192,17 @@ expands them."
(interactive) (interactive)
(save-excursion (save-excursion
(org-back-to-heading) (org-back-to-heading)
(let (case-fold-search) (looking-at org-complex-heading-regexp)
(cond (goto-char (or (match-end 3) (match-end 2) (match-end 1)))
((looking-at (format org-heading-keyword-regexp-format (skip-chars-forward " \t")
org-comment-string)) (unless (memq (char-before) '(?\s ?\t)) (insert " "))
(goto-char (match-end 1)) (if (org-in-commented-heading-p t)
(looking-at (concat " +" org-comment-string)) (delete-region (point)
(replace-match "" t t) (progn (search-forward " " (line-end-position) 'move)
(when (eolp) (insert " "))) (skip-chars-forward " \t")
((looking-at org-outline-regexp) (point)))
(goto-char (match-end 0)) (insert org-comment-string)
(insert org-comment-string " ")))))) (unless (eolp) (insert " ")))))
(defvar org-last-todo-state-is-todo nil (defvar org-last-todo-state-is-todo nil
"This is non-nil when the last TODO state change led to a TODO state. "This is non-nil when the last TODO state change led to a TODO state.
@ -12315,7 +12317,7 @@ When called through ELisp, arg is also interpreted in the following way:
(save-excursion (save-excursion
(catch 'exit (catch 'exit
(org-back-to-heading t) (org-back-to-heading t)
(when (looking-at (concat "^\\*+ " org-comment-string)) (when (org-in-commented-heading-p t)
(org-toggle-comment) (org-toggle-comment)
(setq commentp t)) (setq commentp t))
(if (looking-at org-outline-regexp) (goto-char (1- (match-end 0)))) (if (looking-at org-outline-regexp) (goto-char (1- (match-end 0))))
@ -18243,11 +18245,11 @@ When a buffer is unmodified, it is just killed. When modified, it is saved
(if (org-at-heading-p t) (if (org-at-heading-p t)
(add-text-properties (point-at-bol) (org-end-of-subtree t) pa)))) (add-text-properties (point-at-bol) (org-end-of-subtree t) pa))))
(goto-char (point-min)) (goto-char (point-min))
(setq re (format org-heading-keyword-regexp-format (setq re (format "^\\* .*\\<%s\\>" org-comment-string))
org-comment-string))
(while (re-search-forward re nil t) (while (re-search-forward re nil t)
(add-text-properties (when (save-match-data (org-in-commented-heading-p t))
(match-beginning 0) (org-end-of-subtree t) pc)))) (add-text-properties
(match-beginning 0) (org-end-of-subtree t) pc)))))
(goto-char pos))))) (goto-char pos)))))
(setq org-todo-keywords-for-agenda (setq org-todo-keywords-for-agenda
(org-uniquify org-todo-keywords-for-agenda)) (org-uniquify org-todo-keywords-for-agenda))

View File

@ -27,6 +27,64 @@
;;; Comments ;;; Comments
(ert-deftest test-org/toggle-comment ()
"Test `org-toggle-comment' specifications."
;; Simple headline.
(should
(equal "* Test"
(org-test-with-temp-text "* COMMENT Test"
(org-toggle-comment)
(buffer-string))))
(should
(equal "* COMMENT Test"
(org-test-with-temp-text "* Test"
(org-toggle-comment)
(buffer-string))))
;; Headline with a regular keyword.
(should
(equal "* TODO Test"
(org-test-with-temp-text "* TODO COMMENT Test"
(org-toggle-comment)
(buffer-string))))
(should
(equal "* TODO COMMENT Test"
(org-test-with-temp-text "* TODO Test"
(org-toggle-comment)
(buffer-string))))
;; Empty headline.
(should
(equal "* "
(org-test-with-temp-text "* COMMENT"
(org-toggle-comment)
(buffer-string))))
(should
(equal "* COMMENT"
(org-test-with-temp-text "* "
(org-toggle-comment)
(buffer-string))))
;; Headline with a single keyword.
(should
(equal "* TODO "
(org-test-with-temp-text "* TODO COMMENT"
(org-toggle-comment)
(buffer-string))))
(should
(equal "* TODO COMMENT"
(org-test-with-temp-text "* TODO"
(org-toggle-comment)
(buffer-string))))
;; Headline with a keyword, a priority cookie and contents.
(should
(equal "* TODO [#A] Headline"
(org-test-with-temp-text "* TODO [#A] COMMENT Headline"
(org-toggle-comment)
(buffer-string))))
(should
(equal "* TODO [#A] COMMENT Headline"
(org-test-with-temp-text "* TODO [#A] Headline"
(org-toggle-comment)
(buffer-string)))))
(ert-deftest test-org/comment-dwim () (ert-deftest test-org/comment-dwim ()
"Test `comment-dwim' behaviour in an Org buffer." "Test `comment-dwim' behaviour in an Org buffer."
;; No region selected, no comment on current line and line not ;; No region selected, no comment on current line and line not