Deprecate `org-flag-drawer'

* testing/lisp/test-org.el (test-org/flag-drawer): Remove tests.
* lisp/org-clock.el (org-clock-jump-to-current-clock):
* lisp/org.el (org-cycle-hide-drawers): Use `org-hide-drawer-toggle'
instead.
(org-insert-drawer)
(org-hide-drawer-toggle): Use `org-flag-region' instead.
(org-flag-drawer): move...
* lisp/org-compat.el (org-flag-drawer): ... here.
This commit is contained in:
Nicolas Goaziou 2020-04-18 12:01:45 +02:00
parent e6cd5a50d1
commit b4f77b1f9a
4 changed files with 34 additions and 62 deletions

View File

@ -1021,7 +1021,7 @@ CLOCK is a cons cell of the form (MARKER START-TIME)."
(let ((element (org-element-at-point)))
(when (eq (org-element-type element) 'drawer)
(when (> (org-element-property :end element) (car clock))
(org-flag-drawer nil element))
(org-hide-drawer-toggle 'off nil element))
(throw 'exit nil)))))))))))
(defun org-clock-resolve (clock &optional prompt-fn last-valid fail-quietly)

View File

@ -623,6 +623,36 @@ use of this function is for the stuck project list."
(declare (obsolete "use `org-align-tags' instead." "Org 9.2"))
(org-align-tags t))
(defun org-flag-drawer (flag &optional element beg end)
"When FLAG is non-nil, hide the drawer we are at.
Otherwise make it visible.
When optional argument ELEMENT is a parsed drawer, as returned by
`org-element-at-point', hide or show that drawer instead.
When buffer positions BEG and END are provided, hide or show that
region as a drawer without further ado."
(declare (obsolete "use `org-hide-drawer-toggle' instead." "Org 9.4"))
(if (and beg end) (org-flag-region beg end flag 'org-hide-drawer)
(let ((drawer
(or element
(and (save-excursion
(beginning-of-line)
(looking-at-p "^[ \t]*:\\(\\(?:\\w\\|[-_]\\)+\\):[ \t]*$"))
(org-element-at-point)))))
(when (memq (org-element-type drawer) '(drawer property-drawer))
(let ((post (org-element-property :post-affiliated drawer)))
(org-flag-region
(save-excursion (goto-char post) (line-end-position))
(save-excursion (goto-char (org-element-property :end drawer))
(skip-chars-backward " \t\n")
(line-end-position))
flag 'org-hide-drawer)
;; When the drawer is hidden away, make sure point lies in
;; a visible part of the buffer.
(when (invisible-p (max (1- (point)) (point-min)))
(goto-char post)))))))
(defmacro org-with-silent-modifications (&rest body)
(declare (obsolete "use `with-silent-modifications' instead." "Org 9.2")
(debug (body)))

View File

@ -6036,33 +6036,12 @@ a list of strings specifying which drawers should not be hidden."
(unless (member-ignore-case (match-string 1) exceptions)
(let ((drawer (org-element-at-point)))
(when (memq (org-element-type drawer) '(drawer property-drawer))
(org-flag-drawer t drawer)
(org-hide-drawer-toggle t nil drawer)
;; Make sure to skip drawer entirely or we might flag
;; it another time when matching its ending line with
;; `org-drawer-regexp'.
(goto-char (org-element-property :end drawer))))))))))
(defun org-flag-drawer (flag &optional drawer beg end)
"When FLAG is non-nil, hide the drawer we are at.
Otherwise make it visible.
When optional argument DRAWER is a parsed drawer, as returned by
`org-element-at-point', hide or show that drawer instead.
When buffer positions BEG and END are provided, hide or show that
region as a drawer without further ado.
The function assumes either DRAWER, or BEG and END are non-nil."
(let ((beg (save-excursion
(goto-char (or beg
(org-element-property :post-affiliated drawer)))
(line-end-position)))
(end (save-excursion
(goto-char (or end (org-element-property :end drawer)))
(skip-chars-backward " \t\n")
(line-end-position))))
(org-flag-region beg end flag 'org-hide-drawer)))
(defun org-hide-drawer-toggle (&optional force no-error element)
"Toggle the visibility of the current drawer.
@ -6095,7 +6074,7 @@ Return a non-nil value when toggling is successful."
'org-hide-drawer)
nil)
(t t))))
(org-flag-drawer flag element))
(org-flag-region start end flag 'org-hide-drawer))
;; When the drawer is hidden away, make sure point is left
;; in a visible part of the buffer.
(when (invisible-p (max (1- (point)) (point-min)))
@ -12996,7 +12975,7 @@ drawer is immediately hidden."
(inhibit-read-only t))
(unless (bobp) (insert "\n"))
(insert ":PROPERTIES:\n:END:")
(org-flag-drawer t nil (line-end-position 0) (point))
(org-flag-region (line-end-position 0) (point) t 'org-hide-drawer)
(when (or (eobp) (= begin (point-min))) (insert "\n"))
(org-indent-region begin (point))))))

View File

@ -7235,43 +7235,6 @@ CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
;;; Visibility
(ert-deftest test-org/flag-drawer ()
"Test `org-flag-drawer' specifications."
;; Hide drawer.
(should
(org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
(org-flag-drawer t (org-element-at-point))
(get-char-property (line-end-position) 'invisible)))
(should
(org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
(org-flag-drawer t nil (point-min) (point-max))
(get-char-property (line-end-position) 'invisible)))
;; Show drawer.
(should-not
(org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
(org-flag-drawer t nil (point-min) (point-max))
(org-flag-drawer nil nil (point-min) (point-max))
(get-char-property (line-end-position) 'invisible)))
(should-not
(org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
(org-flag-drawer t nil (point-min) (point-max))
(org-flag-drawer nil (org-element-at-point))
(get-char-property (line-end-position) 'invisible)))
;; Hide drawer remotely.
(should
(org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
(let ((drawer (save-excursion (search-forward ":D2")
(org-element-at-point))))
(org-flag-drawer t drawer)
(get-char-property (progn (search-forward ":D2") (line-end-position))
'invisible))))
(should-not
(org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
(let ((drawer (save-excursion (search-forward ":D2")
(org-element-at-point))))
(org-flag-drawer t drawer)
(get-char-property (line-end-position) 'invisible)))))
(ert-deftest test-org/hide-drawer-toggle ()
"Test `org-hide-drawer-toggle' specifications."
;; Error when not at a drawer.