Fix `+org-fix-blank-lines'

This commit is contained in:
Case Duckworth 2022-04-24 15:00:41 -05:00
parent 56b2c9fb54
commit d4c3d79770
1 changed files with 35 additions and 32 deletions

View File

@ -143,38 +143,41 @@ N is passed to the functions."
Optional PREFIX argument operates on the entire buffer. Optional PREFIX argument operates on the entire buffer.
Drawers are included with their headings." Drawers are included with their headings."
(interactive "P") (interactive "P")
(org-map-entries (lambda () (let ((org-element-use-cache nil))
(org-with-wide-buffer (org-map-entries (lambda ()
;; `org-map-entries' narrows the buffer, which (let ((beg (org-entry-beginning-position))
;; prevents us from seeing newlines before the (end (org-entry-end-position)))
;; current heading, so we do this part widened. (org-with-wide-buffer
(while (not (looking-back "\n\n" nil)) ;; `org-map-entries' narrows the buffer, which
;; Insert blank lines before heading. ;; prevents us from seeing newlines before the
(insert "\n"))) ;; current heading, so we do this part widened.
(let ((end (org-entry-end-position))) (while (not (looking-back "\n\n" nil))
;; Insert blank lines before entry content ;; Insert blank lines before heading.
(forward-line) (insert "\n")))
(while (and (org-at-planning-p)
(< (point) (point-max))) ;; Insert blank lines before entry content
;; Skip planning lines (forward-line)
(forward-line)) (while (and (org-at-planning-p)
(while (re-search-forward (< (point) (point-max)))
org-drawer-regexp end t) ;; Skip planning lines
;; Skip drawers. You might think that (forward-line))
;; `org-at-drawer-p' would suffice, but for (while (re-search-forward
;; some reason it doesn't work correctly when org-drawer-regexp end t)
;; operating on hidden text. This works, taken ;; Skip drawers. You might think that
;; from `org-agenda-get-some-entry-text'. ;; `org-at-drawer-p' would suffice, but for
(re-search-forward "^[ \t]*:END:.*\n?" end t) ;; some reason it doesn't work correctly when
(goto-char (match-end 0))) ;; operating on hidden text. This works, taken
(unless (or (= (point) (point-max)) ;; from `org-agenda-get-some-entry-text'.
(org-at-heading-p) (re-search-forward "^[ \t]*:END:.*\n?" end t)
(looking-at-p "\n")) (goto-char (match-end 0)))
(insert "\n")))) (unless (or (= (point) (point-max))
t (org-at-heading-p)
(if prefix (looking-at-p "\n"))
nil (insert "\n"))))
'tree))) t
(if prefix
nil
'tree))))
;;; org-count-words ;;; org-count-words