summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2014-09-16 09:25:09 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2014-09-16 09:29:28 +0200
commitc8a7e474ec8aaec69379552d5ee011114eb16fbe (patch)
tree5116c0a6ae2b8f9dc5a840bc797b0d83194feb19
parent2afd5fbb09d0117445909796c9c24517f2edd0ae (diff)
downloadorg-mode-c8a7e474ec8aaec69379552d5ee011114eb16fbe.tar.gz
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.
-rwxr-xr-xlisp/org.el16
-rw-r--r--testing/lisp/test-org.el8
2 files changed, 17 insertions, 7 deletions
diff --git a/lisp/org.el b/lisp/org.el
index 14eb41c..bcbe1b7 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 ecbdadf..c1aeaa4 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)