about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2022-04-24 15:00:41 -0500
committerCase Duckworth2022-04-24 15:00:41 -0500
commitd4c3d7977009c4011a831e2de7756b5fd642f555 (patch)
treebf570519bf0a2c6aaf730020d906055e4756c745
parentCorrect backward-kill-word behavior (diff)
downloademacs-d4c3d7977009c4011a831e2de7756b5fd642f555.tar.gz
emacs-d4c3d7977009c4011a831e2de7756b5fd642f555.zip
Fix `+org-fix-blank-lines'
-rw-r--r--lisp/+org.el67
1 files changed, 35 insertions, 32 deletions
diff --git a/lisp/+org.el b/lisp/+org.el index e39bdc1..9af2dda 100644 --- a/lisp/+org.el +++ b/lisp/+org.el
@@ -143,38 +143,41 @@ N is passed to the functions."
143Optional PREFIX argument operates on the entire buffer. 143Optional PREFIX argument operates on the entire buffer.
144Drawers are included with their headings." 144Drawers are included with their headings."
145 (interactive "P") 145 (interactive "P")
146 (org-map-entries (lambda () 146 (let ((org-element-use-cache nil))
147 (org-with-wide-buffer 147 (org-map-entries (lambda ()
148 ;; `org-map-entries' narrows the buffer, which 148 (let ((beg (org-entry-beginning-position))
149 ;; prevents us from seeing newlines before the 149 (end (org-entry-end-position)))
150 ;; current heading, so we do this part widened. 150 (org-with-wide-buffer
151 (while (not (looking-back "\n\n" nil)) 151 ;; `org-map-entries' narrows the buffer, which
152 ;; Insert blank lines before heading. 152 ;; prevents us from seeing newlines before the
153 (insert "\n"))) 153 ;; current heading, so we do this part widened.
154 (let ((end (org-entry-end-position))) 154 (while (not (looking-back "\n\n" nil))
155 ;; Insert blank lines before entry content 155 ;; Insert blank lines before heading.
156 (forward-line) 156 (insert "\n")))
157 (while (and (org-at-planning-p) 157
158 (< (point) (point-max))) 158 ;; Insert blank lines before entry content
159 ;; Skip planning lines 159 (forward-line)
160 (forward-line)) 160 (while (and (org-at-planning-p)
161 (while (re-search-forward 161 (< (point) (point-max)))
162 org-drawer-regexp end t) 162 ;; Skip planning lines
163 ;; Skip drawers. You might think that 163 (forward-line))
164 ;; `org-at-drawer-p' would suffice, but for 164 (while (re-search-forward
165 ;; some reason it doesn't work correctly when 165 org-drawer-regexp end t)
166 ;; operating on hidden text. This works, taken 166 ;; Skip drawers. You might think that
167 ;; from `org-agenda-get-some-entry-text'. 167 ;; `org-at-drawer-p' would suffice, but for
168 (re-search-forward "^[ \t]*:END:.*\n?" end t) 168 ;; some reason it doesn't work correctly when
169 (goto-char (match-end 0))) 169 ;; operating on hidden text. This works, taken
170 (unless (or (= (point) (point-max)) 170 ;; from `org-agenda-get-some-entry-text'.
171 (org-at-heading-p) 171 (re-search-forward "^[ \t]*:END:.*\n?" end t)
172 (looking-at-p "\n")) 172 (goto-char (match-end 0)))
173 (insert "\n")))) 173 (unless (or (= (point) (point-max))
174 t 174 (org-at-heading-p)
175 (if prefix 175 (looking-at-p "\n"))
176 nil 176 (insert "\n"))))
177 'tree))) 177 t
178 (if prefix
179 nil
180 'tree))))
178 181
179;;; org-count-words 182;;; org-count-words
180 183