From 95c2c7f38cdaa7cea5f36ffa9c55da8bc86b0b00 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Thu, 16 Oct 2014 09:27:10 +0200 Subject: [PATCH] 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. --- lisp/org.el | 35 +++++++++++++++++++++-------------- testing/lisp/test-org.el | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 14 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 13c3b5b64..899560873 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 3970fb1b5..6617ebcab 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: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: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: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: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: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:A: 2\n:END:" + (org-toggle-custom-properties-visibility) + (org-invisible-p2))))) + ;;; Mark Region -- 2.11.4.GIT