summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2012-08-18 12:37:39 +0200
committerNicolas Goaziou <n.goaziou@gmail.com>2012-08-18 13:13:31 +0200
commitad94a9433b397f11b1041ae60cc0949a6a56f157 (patch)
tree7a3bf7ed097757af04ee7cedf8dde91ebddea4aa
parent3f57803fb4cbbcc5b7f1c38d6c6c7a287f847753 (diff)
downloadorg-mode-ad94a9433b397f11b1041ae60cc0949a6a56f157.tar.gz
Addendum to 50a434bb9faa23396c2619031bd07a2fa2d30d0b
* lisp/org-element.el (org-element-item-parser): Do not remove tag from body if list isn't descriptive. * lisp/org-list.el (org-insert-item): Only ask about a term for descriptive lists. (org-list-struct, org-list-insert-item): Do not recognize a tag in an ordered list. * testing/lisp/test-org-element.el: Add test.
-rw-r--r--lisp/org-element.el45
-rw-r--r--lisp/org-list.el35
-rw-r--r--testing/lisp/test-org-element.el6
3 files changed, 56 insertions, 30 deletions
diff --git a/lisp/org-element.el b/lisp/org-element.el
index 3109186..c3cef45 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -984,34 +984,39 @@ string instead.
Assume point is at the beginning of the item."
(save-excursion
(beginning-of-line)
+ (looking-at org-list-full-item-re)
(let* ((begin (point))
- (bullet (org-list-get-bullet (point) struct))
- (checkbox (let ((box (org-list-get-checkbox begin struct)))
+ (bullet (org-match-string-no-properties 1))
+ (checkbox (let ((box (org-match-string-no-properties 3)))
(cond ((equal "[ ]" box) 'off)
((equal "[X]" box) 'on)
((equal "[-]" box) 'trans))))
- (counter (let ((c (org-list-get-counter begin struct)))
- (cond
- ((not c) nil)
- ((string-match "[A-Za-z]" c)
- (- (string-to-char (upcase (match-string 0 c)))
- 64))
- ((string-match "[0-9]+" c)
- (string-to-number (match-string 0 c))))))
+ (counter (let ((c (org-match-string-no-properties 2)))
+ (save-match-data
+ (cond
+ ((not c) nil)
+ ((string-match "[A-Za-z]" c)
+ (- (string-to-char (upcase (match-string 0 c)))
+ 64))
+ ((string-match "[0-9]+" c)
+ (string-to-number (match-string 0 c)))))))
(end (save-excursion (goto-char (org-list-get-item-end begin struct))
(unless (bolp) (forward-line))
(point)))
- (contents-begin (progn (looking-at org-list-full-item-re)
- (goto-char (match-end 0))
- (skip-chars-forward " \r\t\n" limit)
- ;; If first line isn't empty,
- ;; contents really start at the text
- ;; after item's meta-data.
- (if (= (point-at-bol) begin) (point)
- (point-at-bol))))
+ (contents-begin
+ (progn (goto-char
+ ;; Ignore tags in un-ordered lists: they are just
+ ;; a part of item's body.
+ (if (and (match-beginning 4)
+ (save-match-data (string-match "[.)]" bullet)))
+ (match-beginning 4)
+ (match-end 0)))
+ (skip-chars-forward " \r\t\n" limit)
+ ;; If first line isn't empty, contents really start
+ ;; at the text after item's meta-data.
+ (if (= (point-at-bol) begin) (point) (point-at-bol))))
(hidden (progn (forward-line)
- (and (not (= (point) end))
- (org-invisible-p2))))
+ (and (not (= (point) end)) (org-invisible-p2))))
(contents-end (progn (goto-char end)
(skip-chars-backward " \r\t\n")
(forward-line)
diff --git a/lisp/org-list.el b/lisp/org-list.el
index 9b254b2..0435641 100644
--- a/lisp/org-list.el
+++ b/lisp/org-list.el
@@ -621,12 +621,15 @@ Assume point is at an item."
;; Return association at point.
(lambda (ind)
(looking-at org-list-full-item-re)
- (list (point)
- ind
- (match-string-no-properties 1) ; bullet
- (match-string-no-properties 2) ; counter
- (match-string-no-properties 3) ; checkbox
- (match-string-no-properties 4))))) ; description tag
+ (let ((bullet (match-string-no-properties 1)))
+ (list (point)
+ ind
+ bullet
+ (match-string-no-properties 2) ; counter
+ (match-string-no-properties 3) ; checkbox
+ ;; Description tag.
+ (and (save-match-data (string-match "[-+*]" bullet))
+ (match-string-no-properties 4)))))))
(end-before-blank
(function
;; Ensure list ends at the first blank line.
@@ -1253,8 +1256,15 @@ This function modifies STRUCT."
(let* ((item (progn (goto-char pos) (goto-char (org-list-get-item-begin))))
(item-end (org-list-get-item-end item struct))
(item-end-no-blank (org-list-get-item-end-before-blank item struct))
- (beforep (and (looking-at org-list-full-item-re)
- (<= pos (match-end 0))))
+ (beforep
+ (progn
+ (looking-at org-list-full-item-re)
+ ;; Do not count tag in a non-descriptive list.
+ (<= pos (if (and (match-beginning 4)
+ (save-match-data
+ (string-match "[.)]" (match-string 1))))
+ (match-beginning 4)
+ (match-end 0)))))
(split-line-p (org-get-alist-option org-M-RET-may-split-line 'item))
(blank-nb (org-list-separating-blank-lines-number
pos struct prevs))
@@ -2187,14 +2197,19 @@ item is invisible."
(org-list-struct)))
(prevs (org-list-prevs-alist struct))
;; If we're in a description list, ask for the new term.
- (desc (when (org-list-get-tag itemp struct)
+ (desc (when (eq (org-list-get-list-type itemp struct prevs)
+ 'descriptive)
(concat (read-string "Term: ") " :: "))))
(setq struct
(org-list-insert-item pos struct prevs checkbox desc))
(org-list-write-struct struct (org-list-parents-alist struct))
(when checkbox (org-update-checkbox-count-maybe))
(looking-at org-list-full-item-re)
- (goto-char (match-end 0))
+ (goto-char (if (and (match-beginning 4)
+ (save-match-data
+ (string-match "[.)]" (match-string 1))))
+ (match-beginning 4)
+ (match-end 0)))
t)))))
(defun org-list-repair ()
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index feeee6b..63faca1 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -890,6 +890,12 @@ DEADLINE: <2012-03-29 thu.>"
:tag
(org-test-with-temp-text "- tag :: description"
(org-element-map (org-element-parse-buffer) 'item 'identity nil t)))))
+ ;; No tags in ordered lists.
+ (should-not
+ (org-element-property
+ :tag
+ (org-test-with-temp-text "1. tag :: description"
+ (org-element-map (org-element-parse-buffer) 'item 'identity nil t))))
;; Check-boxes
(should
(equal