>From 2a362b5785c4391d7df427ef9f9b64e74122316b Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Thu, 3 Oct 2013 22:57:02 +0200 Subject: [PATCH 1/2] org-element: Remove folding status in parsed data * lisp/org-element.el (org-element-center-block-parser, org-element-drawer-parser, org-element-dynamic-block-parser, org-element-item-parser, org-element-quote-block-parser, org-element-comment-block-parser, org-element-export-block-parser, org-element-verse-block-parser, org-element-special-block-parser, org-element-example-block-parser, org-element-headline-parser, org-element-inlinetask-parser): Remove :hiddenp property. * lisp/org.el (org-end-of-line, org-down-element): Use an equivalent of :hiddenp property. * testing/lisp/test-org-element.el: Remove tests. The property is removed because it is buggy (e.g., when there's a link just after a block opening line). Also, folding status cannot be cached since it doesn't trigger a buffer change. --- lisp/org-element.el | 101 +++++++++++++-------------------------- lisp/org.el | 4 +- testing/lisp/test-org-element.el | 93 ++++------------------------------- 3 files changed, 44 insertions(+), 154 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index 807fdb4..ef3eb46 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -493,8 +493,8 @@ keyword and CDR is a plist of affiliated keywords along with their value. Return a list whose CAR is `center-block' and CDR is a plist -containing `:begin', `:end', `:hiddenp', `:contents-begin', -`:contents-end', `:post-blank' and `:post-affiliated' keywords. +containing `:begin', `:end', `:contents-begin', `:contents-end', +`:post-blank' and `:post-affiliated' keywords. Assume point is at the beginning of the block." (let ((case-fold-search t)) @@ -510,7 +510,6 @@ Assume point is at the beginning of the block." (and (< (point) block-end-line) (point)))) (contents-end (and contents-begin block-end-line)) - (hidden (org-invisible-p2)) (pos-before-blank (progn (goto-char block-end-line) (forward-line) (point))) @@ -521,7 +520,6 @@ Assume point is at the beginning of the block." (nconc (list :begin begin :end end - :hiddenp hidden :contents-begin contents-begin :contents-end contents-end :post-blank (count-lines pos-before-blank end) @@ -545,7 +543,7 @@ keyword and CDR is a plist of affiliated keywords along with their value. Return a list whose CAR is `drawer' and CDR is a plist containing -`:drawer-name', `:begin', `:end', `:hiddenp', `:contents-begin', +`:drawer-name', `:begin', `:end', `:contents-begin', `:contents-end', `:post-blank' and `:post-affiliated' keywords. Assume point is at beginning of drawer." @@ -564,7 +562,6 @@ Assume point is at beginning of drawer." (and (< (point) drawer-end-line) (point)))) (contents-end (and contents-begin drawer-end-line)) - (hidden (org-invisible-p2)) (pos-before-blank (progn (goto-char drawer-end-line) (forward-line) (point))) @@ -576,7 +573,6 @@ Assume point is at beginning of drawer." (list :begin begin :end end :drawer-name name - :hiddenp hidden :contents-begin contents-begin :contents-end contents-end :post-blank (count-lines pos-before-blank end) @@ -602,9 +598,9 @@ keyword and CDR is a plist of affiliated keywords along with their value. Return a list whose CAR is `dynamic-block' and CDR is a plist -containing `:block-name', `:begin', `:end', `:hiddenp', -`:contents-begin', `:contents-end', `:arguments', `:post-blank' -and `:post-affiliated' keywords. +containing `:block-name', `:begin', `:end', `:contents-begin', +`:contents-end', `:arguments', `:post-blank' and +`:post-affiliated' keywords. Assume point is at beginning of dynamic block." (let ((case-fold-search t)) @@ -624,7 +620,6 @@ Assume point is at beginning of dynamic block." (and (< (point) block-end-line) (point)))) (contents-end (and contents-begin block-end-line)) - (hidden (org-invisible-p2)) (pos-before-blank (progn (goto-char block-end-line) (forward-line) (point))) @@ -637,7 +632,6 @@ Assume point is at beginning of dynamic block." :end end :block-name name :arguments arguments - :hiddenp hidden :contents-begin contents-begin :contents-end contents-end :post-blank (count-lines pos-before-blank end) @@ -720,11 +714,10 @@ CONTENTS is the contents of the footnote-definition." Return a list whose CAR is `headline' and CDR is a plist containing `:raw-value', `:title', `:alt-title', `:begin', -`:end', `:pre-blank', `:hiddenp', `:contents-begin' and -`:contents-end', `:level', `:priority', `:tags', -`:todo-keyword',`:todo-type', `:scheduled', `:deadline', -`:closed', `:quotedp', `:archivedp', `:commentedp' and -`:footnote-section-p' keywords. +`:end', `:pre-blank', `:contents-begin' and `:contents-end', +`:level', `:priority', `:tags', `:todo-keyword',`:todo-type', +`:scheduled', `:deadline', `:closed', `:quotedp', `:archivedp', +`:commentedp' and `:footnote-section-p' keywords. The plist also contains any property set in the property drawer, with its name in upper cases and colons added at the @@ -791,7 +784,6 @@ Assume point is at beginning of the headline." (contents-begin (save-excursion (skip-chars-forward " \r\t\n" end) (and (/= (point) end) (line-beginning-position)))) - (hidden (org-invisible-p2)) (contents-end (and contents-begin (progn (goto-char end) (skip-chars-backward " \r\t\n") @@ -818,7 +810,6 @@ Assume point is at beginning of the headline." :pre-blank (if (not contents-begin) 0 (count-lines pos-after-head contents-begin)) - :hiddenp hidden :contents-begin contents-begin :contents-end contents-end :level level @@ -904,10 +895,10 @@ CONTENTS is the contents of the element." "Parse an inline task. Return a list whose CAR is `inlinetask' and CDR is a plist -containing `:title', `:begin', `:end', `:hiddenp', -`:contents-begin' and `:contents-end', `:level', `:priority', -`:raw-value', `:tags', `:todo-keyword', `:todo-type', -`:scheduled', `:deadline', `:closed' and `:post-blank' keywords. +containing `:title', `:begin', `:end', `:contents-begin' and +`:contents-end', `:level', `:priority', `:raw-value', `:tags', +`:todo-keyword', `:todo-type', `:scheduled', `:deadline', +`:closed' and `:post-blank' keywords. The plist also contains any property set in the property drawer, with its name in upper cases and colons added at the @@ -965,7 +956,6 @@ Assume point is at beginning of the inline task." (match-beginning 0)))) (contents-begin (progn (forward-line) (and task-end (< (point) task-end) (point)))) - (hidden (and contents-begin (org-invisible-p2))) (contents-end (and contents-begin task-end)) (before-blank (if (not task-end) (point) (goto-char task-end) @@ -980,7 +970,6 @@ Assume point is at beginning of the inline task." (list :raw-value raw-value :begin begin :end end - :hiddenp hidden :contents-begin contents-begin :contents-end contents-end :level (nth 1 components) @@ -1047,8 +1036,8 @@ STRUCT is the structure of the plain list. Return a list whose CAR is `item' and CDR is a plist containing `:bullet', `:begin', `:end', `:contents-begin', `:contents-end', -`:checkbox', `:counter', `:tag', `:structure', `:hiddenp' and -`:post-blank' keywords. +`:checkbox', `:counter', `:tag', `:structure' and `:post-blank' +keywords. When optional argument RAW-SECONDARY-P is non-nil, item's tag, if any, will not be parsed as a secondary string, but as a plain @@ -1088,8 +1077,6 @@ Assume point is at the beginning of the item." ;; 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)))) (contents-end (progn (goto-char end) (skip-chars-backward " \r\t\n") (forward-line) @@ -1108,7 +1095,6 @@ Assume point is at the beginning of the item." :contents-end (max contents-begin contents-end) :checkbox checkbox :counter counter - :hiddenp hidden :structure struct :post-blank (count-lines contents-end end))))) (org-element-put-property @@ -1299,8 +1285,8 @@ keyword and CDR is a plist of affiliated keywords along with their value. Return a list whose CAR is `property-drawer' and CDR is a plist -containing `:begin', `:end', `:hiddenp', `:contents-begin', -`:contents-end', `:post-blank' and `:post-affiliated' keywords. +containing `:begin', `:end', `:contents-begin', `:contents-end', +`:post-blank' and `:post-affiliated' keywords. Assume point is at the beginning of the property drawer." (save-excursion @@ -1317,7 +1303,6 @@ Assume point is at the beginning of the property drawer." (and (< (point) drawer-end-line) (point)))) (contents-end (and contents-begin drawer-end-line)) - (hidden (org-invisible-p2)) (pos-before-blank (progn (goto-char drawer-end-line) (forward-line) (point))) @@ -1328,7 +1313,6 @@ Assume point is at the beginning of the property drawer." (nconc (list :begin begin :end end - :hiddenp hidden :contents-begin contents-begin :contents-end contents-end :post-blank (count-lines pos-before-blank end) @@ -1352,8 +1336,8 @@ keyword and CDR is a plist of affiliated keywords along with their value. Return a list whose CAR is `quote-block' and CDR is a plist -containing `:begin', `:end', `:hiddenp', `:contents-begin', -`:contents-end', `:post-blank' and `:post-affiliated' keywords. +containing `:begin', `:end', `:contents-begin', `:contents-end', +`:post-blank' and `:post-affiliated' keywords. Assume point is at the beginning of the block." (let ((case-fold-search t)) @@ -1370,7 +1354,6 @@ Assume point is at the beginning of the block." (and (< (point) block-end-line) (point)))) (contents-end (and contents-begin block-end-line)) - (hidden (org-invisible-p2)) (pos-before-blank (progn (goto-char block-end-line) (forward-line) (point))) @@ -1381,7 +1364,6 @@ Assume point is at the beginning of the block." (nconc (list :begin begin :end end - :hiddenp hidden :contents-begin contents-begin :contents-end contents-end :post-blank (count-lines pos-before-blank end) @@ -1437,9 +1419,8 @@ keyword and CDR is a plist of affiliated keywords along with their value. Return a list whose CAR is `special-block' and CDR is a plist -containing `:type', `:begin', `:end', `:hiddenp', -`:contents-begin', `:contents-end', `:post-blank' and -`:post-affiliated' keywords. +containing `:type', `:begin', `:end', `:contents-begin', +`:contents-end', `:post-blank' and `:post-affiliated' keywords. Assume point is at the beginning of the block." (let* ((case-fold-search t) @@ -1460,7 +1441,6 @@ Assume point is at the beginning of the block." (and (< (point) block-end-line) (point)))) (contents-end (and contents-begin block-end-line)) - (hidden (org-invisible-p2)) (pos-before-blank (progn (goto-char block-end-line) (forward-line) (point))) @@ -1472,7 +1452,6 @@ Assume point is at the beginning of the block." (list :type type :begin begin :end end - :hiddenp hidden :contents-begin contents-begin :contents-end contents-end :post-blank (count-lines pos-before-blank end) @@ -1660,8 +1639,8 @@ keyword and CDR is a plist of affiliated keywords along with their value. Return a list whose CAR is `comment-block' and CDR is a plist -containing `:begin', `:end', `:hiddenp', `:value', `:post-blank' -and `:post-affiliated' keywords. +containing `:begin', `:end', `:value', `:post-blank' and +`:post-affiliated' keywords. Assume point is at comment block beginning." (let ((case-fold-search t)) @@ -1674,7 +1653,6 @@ Assume point is at comment block beginning." (let* ((begin (car affiliated)) (post-affiliated (point)) (contents-begin (progn (forward-line) (point))) - (hidden (org-invisible-p2)) (pos-before-blank (progn (goto-char contents-end) (forward-line) (point))) @@ -1688,7 +1666,6 @@ Assume point is at comment block beginning." (list :begin begin :end end :value value - :hiddenp hidden :post-blank (count-lines pos-before-blank end) :post-affiliated post-affiliated) (cdr affiliated))))))))) @@ -1778,9 +1755,8 @@ their value. Return a list whose CAR is `example-block' and CDR is a plist containing `:begin', `:end', `:number-lines', `:preserve-indent', -`:retain-labels', `:use-labels', `:label-fmt', `:hiddenp', -`:switches', `:value', `:post-blank' and `:post-affiliated' -keywords." +`:retain-labels', `:use-labels', `:label-fmt', `:switches', +`:value', `:post-blank' and `:post-affiliated' keywords." (let ((case-fold-search t)) (if (not (save-excursion (re-search-forward "^[ \t]*#\\+END_EXAMPLE[ \t]*$" limit t))) @@ -1821,7 +1797,6 @@ keywords." (post-affiliated (point)) (block-ind (progn (skip-chars-forward " \t") (current-column))) (contents-begin (progn (forward-line) (point))) - (hidden (org-invisible-p2)) (value (org-element--remove-indentation (org-unescape-code-in-string (buffer-substring-no-properties @@ -1844,7 +1819,6 @@ keywords." :retain-labels retain-labels :use-labels use-labels :label-fmt label-fmt - :hiddenp hidden :post-blank (count-lines pos-before-blank end) :post-affiliated post-affiliated) (cdr affiliated))))))))) @@ -1870,8 +1844,8 @@ keyword and CDR is a plist of affiliated keywords along with their value. Return a list whose CAR is `export-block' and CDR is a plist -containing `:begin', `:end', `:type', `:hiddenp', `:value', -`:post-blank' and `:post-affiliated' keywords. +containing `:begin', `:end', `:type', `:value', `:post-blank' and +`:post-affiliated' keywords. Assume point is at export-block beginning." (let* ((case-fold-search t) @@ -1887,7 +1861,6 @@ Assume point is at export-block beginning." (let* ((begin (car affiliated)) (post-affiliated (point)) (contents-begin (progn (forward-line) (point))) - (hidden (org-invisible-p2)) (pos-before-blank (progn (goto-char contents-end) (forward-line) (point))) @@ -1902,7 +1875,6 @@ Assume point is at export-block beginning." :end end :type type :value value - :hiddenp hidden :post-blank (count-lines pos-before-blank end) :post-affiliated post-affiliated) (cdr affiliated))))))))) @@ -2325,9 +2297,9 @@ their value. Return a list whose CAR is `src-block' and CDR is a plist containing `:language', `:switches', `:parameters', `:begin', -`:end', `:hiddenp', `:number-lines', `:retain-labels', -`:use-labels', `:label-fmt', `:preserve-indent', `:value', -`:post-blank' and `:post-affiliated' keywords. +`:end', `:number-lines', `:retain-labels', `:use-labels', +`:label-fmt', `:preserve-indent', `:value', `:post-blank' and +`:post-affiliated' keywords. Assume point is at the beginning of the block." (let ((case-fold-search t)) @@ -2378,13 +2350,11 @@ Assume point is at the beginning of the block." (not (string-match "-k\\>" switches))))) ;; Indentation. (block-ind (progn (skip-chars-forward " \t") (current-column))) - ;; Get visibility status. - (hidden (progn (forward-line) (org-invisible-p2))) ;; Retrieve code. (value (org-element--remove-indentation (org-unescape-code-in-string (buffer-substring-no-properties - (point) contents-end)) + (progn (forward-line) (point)) contents-end)) (and preserve-indent block-ind))) (pos-before-blank (progn (goto-char contents-end) (forward-line) @@ -2407,7 +2377,6 @@ Assume point is at the beginning of the block." :retain-labels retain-labels :use-labels use-labels :label-fmt label-fmt - :hiddenp hidden :value value :post-blank (count-lines pos-before-blank end) :post-affiliated post-affiliated) @@ -2552,7 +2521,7 @@ their value. Return a list whose CAR is `verse-block' and CDR is a plist containing `:begin', `:end', `:contents-begin', `:contents-end', -`:hiddenp', `:post-blank' and `:post-affiliated' keywords. +`:post-blank' and `:post-affiliated' keywords. Assume point is at beginning of the block." (let ((case-fold-search t)) @@ -2564,8 +2533,7 @@ Assume point is at beginning of the block." (save-excursion (let* ((begin (car affiliated)) (post-affiliated (point)) - (hidden (progn (forward-line) (org-invisible-p2))) - (contents-begin (point)) + (contents-begin (progn (forward-line) (point))) (pos-before-blank (progn (goto-char contents-end) (forward-line) (point))) @@ -2578,7 +2546,6 @@ Assume point is at beginning of the block." :end end :contents-begin contents-begin :contents-end contents-end - :hiddenp hidden :post-blank (count-lines pos-before-blank end) :post-affiliated post-affiliated) (cdr affiliated))))))))) diff --git a/lisp/org.el b/lisp/org.el index 5ff9969..dc869ab 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -22810,7 +22810,7 @@ the cursor is already beyond the end of the headline." (goto-char (match-end 0)) (goto-char (match-beginning 1)))) (call-interactively move-fun)))) - ((org-element-property :hiddenp element) + ((outline-invisible-p (line-end-position)) ;; If element is hidden, `move-end-of-line' would put point ;; after it. Use `end-of-line' to stay on current line. (call-interactively 'end-of-line)) @@ -23511,7 +23511,7 @@ Move to the previous element at the same level, when possible." (forward-char)) ((memq (org-element-type element) org-element-greater-elements) ;; If contents are hidden, first disclose them. - (when (org-element-property :hiddenp element) (org-cycle)) + (when (outline-invisible-p (line-end-position)) (org-cycle)) (goto-char (or (org-element-property :contents-begin element) (user-error "No content for this element")))) (t (user-error "No inner element"))))) diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index ea4f649..ce9803f 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -273,14 +273,6 @@ Some other text (should (org-test-with-temp-text "#+begin_center\nText\n#+end_center" (org-element-map (org-element-parse-buffer) 'center-block 'identity))) - ;; Test folded block. - (org-test-with-temp-text "#+BEGIN_CENTER\nText\n#+END_CENTER" - (org-cycle) - (should - (org-element-property - :hiddenp - (org-element-map - (org-element-parse-buffer) 'center-block 'identity nil t)))) ;; Ignore incomplete block. (should-not (org-test-with-temp-text "#+BEGIN_CENTER" @@ -393,14 +385,6 @@ Some other text (org-test-with-temp-text "#+begin_comment\nText\n#+end_comment" (org-element-map (org-element-parse-buffer) 'comment-block 'identity))) - ;; Test folded block. - (org-test-with-temp-text "#+BEGIN_COMMENT\nText\n#+END_COMMENT" - (org-cycle) - (should - (org-element-property - :hiddenp - (org-element-map - (org-element-parse-buffer) 'comment-block 'identity nil t)))) ;; Ignore incomplete block. (should-not (org-test-with-temp-text "#+BEGIN_COMMENT" @@ -457,15 +441,6 @@ Some other text (org-test-with-temp-text "#+BEGIN: myblock :param1 val1 :param2 val2\nText\n#+END:" (org-element-map (org-element-parse-buffer) 'dynamic-block 'identity))) - ;; Folded view - (org-test-with-temp-text - "#+BEGIN: myblock :param1 val1 :param2 val2\nText\n#+END:" - (org-cycle) - (should - (org-element-property - :hiddenp - (org-element-map - (org-element-parse-buffer) 'dynamic-block 'identity nil t)))) ;; Ignore case. (should (org-test-with-temp-text @@ -518,11 +493,6 @@ Some other text (should (org-test-with-temp-text "#+BEGIN_EXAMPLE\nText\n#+END_EXAMPLE" (org-element-map (org-element-parse-buffer) 'example-block 'identity))) - ;; Test folded block. - (should - (org-test-with-temp-text "#+BEGIN_EXAMPLE\nText\n#+END_EXAMPLE" - (org-cycle) - (org-element-property :hiddenp (org-element-at-point)))) ;; Ignore incomplete block. (should-not (eq 'example-block @@ -682,17 +652,6 @@ Some other text '(("LATEX" . org-element-export-block-parser)))) (org-element-parse-buffer)) 'export-block 'identity))) - ;; Test folded block. - (org-test-with-temp-text "#+BEGIN_LATEX\nText\n#+END_LATEX" - (org-cycle) - (should - (org-element-property - :hiddenp - (org-element-map - (let ((org-element-block-name-alist - '(("LATEX" . org-element-export-block-parser)))) - (org-element-parse-buffer)) - 'export-block 'identity nil t)))) ;; Ignore case. (should (org-test-with-temp-text "#+begin_latex\nText\n#+end_latex" @@ -1111,17 +1070,6 @@ DEADLINE: <2012-03-29 thu.>" (org-element-map (org-element-parse-buffer) 'item (lambda (item) (org-element-property :checkbox item)))))) - ;; Folded state. - (org-test-with-temp-text "* Headline -- item - - paragraph below" - (forward-line) - (let ((org-cycle-include-plain-lists t)) (org-cycle)) - (should - (org-element-property - :hiddenp - (org-element-map (org-element-parse-buffer) 'item 'identity nil t)))) ;; Item starting with special syntax. (should (equal '(("- item")) @@ -1592,14 +1540,6 @@ Outside list" (should (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE" (org-element-map (org-element-parse-buffer) 'quote-block 'identity))) - ;; Test folded block. - (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE" - (org-cycle) - (should - (org-element-property - :hiddenp - (org-element-map - (org-element-parse-buffer) 'quote-block 'identity nil t)))) ;; Ignore incomplete block. (should-not (org-test-with-temp-text "#+BEGIN_QUOTE" @@ -1674,11 +1614,6 @@ Outside list" (org-test-with-temp-text "#+BEGIN_SPECIAL\nText\n#+END_SPECIAL" (forward-line) (org-element-type (org-element-at-point))))) - ;; Test folded block. - (should - (org-test-with-temp-text "#+BEGIN_SPECIAL\nText\n#+END_SPECIAL" - (org-cycle) - (org-element-property :hiddenp (org-element-at-point)))) ;; Ignore incomplete block. (should-not (eq 'special-block @@ -1701,11 +1636,6 @@ Outside list" (should (org-test-with-temp-text "#+BEGIN_SRC org\nText\n#+END_SRC" (org-element-map (org-element-parse-buffer) 'src-block 'identity))) - ;; Test folded block. - (should - (org-test-with-temp-text "#+BEGIN_SRC org\nText\n#+END_SRC" - (org-cycle) - (org-element-property :hiddenp (org-element-at-point)))) ;; Ignore incomplete block. (should-not (org-test-with-temp-text "#+BEGIN_SRC" @@ -1978,29 +1908,22 @@ Outside list" (ert-deftest test-org-element/verse-block-parser () "Test `verse-block' parser." ;; Standard test. - (org-test-with-temp-text "#+BEGIN_VERSE\nVerse block\n#+END_VERSE" - (should + (should + (org-test-with-temp-text "#+BEGIN_VERSE\nVerse block\n#+END_VERSE" (org-element-map (org-element-parse-buffer) 'verse-block 'identity))) ;; Ignore case. - (org-test-with-temp-text "#+begin_verse\nVerse block\n#+end_verse" - (should + (should + (org-test-with-temp-text "#+begin_verse\nVerse block\n#+end_verse" (org-element-map (org-element-parse-buffer) 'verse-block 'identity))) - ;; Parse folding. - (org-test-with-temp-text "#+BEGIN_VERSE\nVerse block\n#+END_VERSE" - (org-hide-block-all) - (should - (org-element-property - :hiddenp - (org-element-map - (org-element-parse-buffer) 'verse-block 'identity nil t)))) ;; Parse objects in verse blocks. - (org-test-with-temp-text "#+BEGIN_VERSE\nVerse \\alpha\n#+END_VERSE" - (should (org-element-map (org-element-parse-buffer) 'entity 'identity))) + (should + (org-test-with-temp-text "#+BEGIN_VERSE\nVerse \\alpha\n#+END_VERSE" + (org-element-map (org-element-parse-buffer) 'entity 'identity))) ;; Ignore incomplete verse block. (should-not (org-test-with-temp-text "#+BEGIN_VERSE" (org-element-map - (org-element-parse-buffer) 'verse-block 'identity nil t)))) + (org-element-parse-buffer) 'verse-block 'identity nil t)))) -- 1.8.4