summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2014-10-16 09:27:10 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2014-10-28 14:23:53 +0100
commit95c2c7f38cdaa7cea5f36ffa9c55da8bc86b0b00 (patch)
tree11f47a20403430a93b849bfbff9a517f64bc6703
parent03745338277e450e5989a29850114c735b19cf7a (diff)
downloadorg-mode-95c2c7f38cdaa7cea5f36ffa9c55da8bc86b0b00.tar.gz
Update custom properties handling
* lisp/org.el (org-toggle-custom-properties-visibility): Improve correctness and speed. * testing/lisp/test-org.el (test-org/custom-properties): New test.
-rwxr-xr-xlisp/org.el35
-rw-r--r--testing/lisp/test-org.el47
2 files changed, 68 insertions, 14 deletions
diff --git a/lisp/org.el b/lisp/org.el
index 13c3b5b..8995608 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -6405,21 +6405,28 @@ needs to be inserted at a specific position in the font-lock sequence.")
"Display or hide properties in `org-custom-properties'."
(interactive)
(if org-custom-properties-overlays
- (progn (mapc 'delete-overlay org-custom-properties-overlays)
+ (progn (mapc #'delete-overlay org-custom-properties-overlays)
(setq org-custom-properties-overlays nil))
- (unless (not org-custom-properties)
- (save-excursion
- (save-restriction
- (widen)
- (goto-char (point-min))
- (while (re-search-forward org-property-re nil t)
- (mapc (lambda(p)
- (when (equal p (substring (match-string 1) 1 -1))
- (let ((o (make-overlay (match-beginning 0) (1+ (match-end 0)))))
- (overlay-put o 'invisible t)
- (overlay-put o 'org-custom-property t)
- (push o org-custom-properties-overlays))))
- org-custom-properties)))))))
+ (when org-custom-properties
+ (org-with-wide-buffer
+ (goto-char (point-min))
+ (let ((regexp (org-re-property (regexp-opt org-custom-properties) t t)))
+ (while (re-search-forward regexp nil t)
+ (let ((end (cdr (save-match-data (org-get-property-block)))))
+ (when (and end (< (point) end))
+ ;; Hide first custom property in current drawer.
+ (let ((o (make-overlay (match-beginning 0) (1+ (match-end 0)))))
+ (overlay-put o 'invisible t)
+ (overlay-put o 'org-custom-property t)
+ (push o org-custom-properties-overlays))
+ ;; Hide additional custom properties in the same drawer.
+ (while (re-search-forward regexp end t)
+ (let ((o (make-overlay (match-beginning 0) (1+ (match-end 0)))))
+ (overlay-put o 'invisible t)
+ (overlay-put o 'org-custom-property t)
+ (push o org-custom-properties-overlays)))))
+ ;; Each entry is limited to a single property drawer.
+ (outline-next-heading)))))))
(defun org-fontify-entities (limit)
"Find an entity to fontify."
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 3970fb1..6617ebc 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -1302,6 +1302,53 @@ drops support for Emacs 24.1 and 24.2."
(org-babel-next-src-block)
(should (equal '(2 1) (org-babel-execute-src-block)))))
+(ert-deftest test-org/custom-properties ()
+ "Test custom properties specifications."
+ ;; Standard test.
+ (should
+ (let ((org-custom-properties '("FOO")))
+ (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
+ (org-toggle-custom-properties-visibility)
+ (org-invisible-p2))))
+ ;; Properties are case-insensitive.
+ (should
+ (let ((org-custom-properties '("FOO")))
+ (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
+ (org-toggle-custom-properties-visibility)
+ (org-invisible-p2))))
+ (should
+ (let ((org-custom-properties '("foo")))
+ (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
+ (org-toggle-custom-properties-visibility)
+ (org-invisible-p2))))
+ ;; Multiple custom properties in the same drawer.
+ (should
+ (let ((org-custom-properties '("FOO" "BAR")))
+ (org-test-with-temp-text
+ "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
+ (org-toggle-custom-properties-visibility)
+ (and (org-invisible-p2)
+ (not (progn (forward-line) (org-invisible-p2)))
+ (progn (forward-line) (org-invisible-p2))))))
+ ;; Hide custom properties with an empty value.
+ (should
+ (let ((org-custom-properties '("FOO")))
+ (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
+ (org-toggle-custom-properties-visibility)
+ (org-invisible-p2))))
+ ;; Do not hide fake properties.
+ (should-not
+ (let ((org-custom-properties '("FOO")))
+ (org-test-with-temp-text ":FOO: val\n"
+ (org-toggle-custom-properties-visibility)
+ (org-invisible-p2))))
+ (should-not
+ (let ((org-custom-properties '("A")))
+ (org-test-with-temp-text
+ "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
+ (org-toggle-custom-properties-visibility)
+ (org-invisible-p2)))))
+
;;; Mark Region