From c8a7e474ec8aaec69379552d5ee011114eb16fbe Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Tue, 16 Sep 2014 09:25:09 +0200 Subject: [PATCH] Fix `org-hide-block-toggle' return value * lisp/org.el (org-hide-block-toggle-maybe): Do not return a non-nil value when toggling failed. (org-hide-block-toggle): Update docstring. * testing/lisp/test-org.el (test-org/hide-block-toggle-maybe): New test. --- lisp/org.el | 16 +++++++++------- testing/lisp/test-org.el | 8 ++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 14eb41cb5..bcbe1b7ae 100755 --- a/lisp/org.el +++ b/lisp/org.el @@ -7323,15 +7323,16 @@ Optional arguments START and END can be used to limit the range." (defun org-hide-block-toggle-maybe () "Toggle visibility of block at point. -Do not throw an error. Return t when toggling is successful." +Unlike to `org-hide-block-toggle', this function does not throw +an error. Return a non-nil value when toggling is successful." (interactive) - (ignore-errors (org-hide-block-toggle) t)) + (and (ignore-errors (org-hide-block-toggle)) t)) (defun org-hide-block-toggle (&optional force) "Toggle the visibility of the current block. When optional argument FORCE is `off', make block visible. If it is non-nil, hide it unconditionally. Throw an error when not at -a block." +a block. Return a non-nil value when toggling is successful." (interactive) (let ((element (org-element-at-point))) (unless (memq (org-element-type element) @@ -7350,8 +7351,7 @@ a block." (cond ;; Do nothing when not before or at the block opening line or ;; at the block closing line. - ((let ((eol (line-end-position))) - (and (> eol start) (/= eol end)))) + ((let ((eol (line-end-position))) (and (> eol start) (/= eol end))) nil) ((and (not (eq force 'off)) (not (memq t (mapcar (lambda (o) @@ -7372,9 +7372,11 @@ a block." ;; a visible part of the buffer. (when (> (line-beginning-position) start) (goto-char start) - (beginning-of-line)))) + (beginning-of-line)) + ;; Signal successful toggling. + t)) ((or (not force) (eq force 'off)) - (dolist (ov overlays) + (dolist (ov overlays t) (when (memq ov org-hide-block-overlays) (setq org-hide-block-overlays (delq ov org-hide-block-overlays))) (when (eq (overlay-get ov 'invisible) 'org-hide-block) diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index ecbdadf26..c1aeaa4f6 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -1951,6 +1951,14 @@ Text. (org-hide-block-toggle) (get-char-property (point) 'invisible)))) +(ert-deftest test-org/hide-block-toggle-maybe () + "Test `org-hide-block-toggle-maybe' specifications." + (should + (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:" + (org-hide-block-toggle-maybe))) + (should-not + (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe)))) + (provide 'test-org) -- 2.11.4.GIT