From 755367f3624093ca3344953d8b045a5eaf0a95f6 Mon Sep 17 00:00:00 2001 From: Bastien Guerry Date: Sun, 13 Sep 2020 18:36:15 +0200 Subject: [PATCH] org.el (org-end-of-meta-data): Allow to skip only standard drawers * lisp/org.el (org-end-of-meta-data): Allow to skip only standard drawers, i.e. properties and logbook drawers. * lisp/org-crypt.el (org-at-encrypted-entry-p) (org-encrypt-entry): Use `org-end-of-meta-data' so that standard drawers are all skipped, including logbook drawers. Reported-by: Nicolas Goaziou See https://orgmode.org/list/87d02qgj6u.fsf@nicolasgoaziou.fr and https://debbugs.gnu.org/cgi/bugreport.cgi?bug=43094 for the reason of the previous fix c93983613d. --- lisp/org-crypt.el | 4 ++-- lisp/org.el | 32 +++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/lisp/org-crypt.el b/lisp/org-crypt.el index 671d978c3..187560c55 100644 --- a/lisp/org-crypt.el +++ b/lisp/org-crypt.el @@ -145,7 +145,7 @@ and END are buffer positions delimiting the encrypted area." (org-with-wide-buffer (unless (org-before-first-heading-p) (org-back-to-heading t) - (org-end-of-meta-data t) + (org-end-of-meta-data 'standard) (let ((case-fold-search nil) (banner-start (rx (seq bol (zero-or-more (any "\t ")) @@ -215,7 +215,7 @@ Assume `epg-context' is set." (let ((start-heading (point)) (crypt-key (org-crypt-key-for-heading)) (folded? (org-invisible-p (line-beginning-position)))) - (org-end-of-meta-data t) + (org-end-of-meta-data 'standard) (let ((beg (point)) (folded-heading (and folded? diff --git a/lisp/org.el b/lisp/org.el index 5fb01b594..6e2de0d00 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -20495,26 +20495,40 @@ If there is no such heading, return nil." (defun org-end-of-meta-data (&optional full) "Skip planning line and properties drawer in current entry. -When optional argument FULL is non-nil, also skip empty lines, -clocking lines and regular drawers at the beginning of the -entry." + +When optional argument FULL is t, also skip planning information, +clocking lines and any kind of drawer. + +When FULL is non-nil but not t, skip planning information, +clocking lines and only non-regular drawers, i.e. properties and +logbook drawers." (org-back-to-heading t) (forward-line) + ;; Skip planning information. (when (looking-at-p org-planning-line-re) (forward-line)) + ;; Skip property drawer. (when (looking-at org-property-drawer-re) (goto-char (match-end 0)) (forward-line)) + ;; When FULL is not nil, skip more. (when (and full (not (org-at-heading-p))) (catch 'exit (let ((end (save-excursion (outline-next-heading) (point))) (re (concat "[ \t]*$" "\\|" org-clock-line-re))) (while (not (eobp)) - (cond ((looking-at-p org-drawer-regexp) - (if (re-search-forward "^[ \t]*:END:[ \t]*$" end t) - (forward-line) - (throw 'exit t))) - ((looking-at-p re) (forward-line)) - (t (throw 'exit t)))))))) + (cond ;; Skip clock lines. + ((looking-at-p re) (forward-line)) + ;; Skip logbook drawer. + ((looking-at-p org-logbook-drawer-re) + (if (re-search-forward "^[ \t]*:END:[ \t]*$" end t) + (forward-line) + (throw 'exit t))) + ;; When FULL is t, skip regular drawer too. + ((and (eq full t) (looking-at-p org-drawer-regexp)) + (if (re-search-forward "^[ \t]*:END:[ \t]*$" end t) + (forward-line) + (throw 'exit t))) + (t (throw 'exit t)))))))) (defun org--line-fully-invisible-p () "Return non-nil if the current line is fully invisible."