0

Can I prevent an empty line at the end of a plain list item from showing when the item is folded? For example, if I have

+ top

  wooden pole.  fireworks.

+ bottom

can I have it fold into

+ top...
+ botton

instead of

+ top...

+ bottom
1

The function org-list-get-item-end-before-blank excludes the trailing newlines from list items.

The replacement my-org-list-get-item-end-before-blank in the following code avoids that if there are subsequent list items in the same list.

Function org-list-get-item-end-before-blank is used at quite a few places in orgmode. It seems better to me to keep the modification of org-list-get-item-end-before-blank local to org-cycle-internal-local which controls the visibility of items. Therefore the code below does not globally override org-list-get-item-end-before-blank with my-org-list-get-item-end-before-blank via advice-add but overrides org-list-get-item-end-before-blank locally in an :around-advice for org-cycle-internal-local.

(defun my-org-list-get-item-end-before-blank (item struct)
  "Override advice for `org-list-get-item-end-before-blank'.
Avoid skipping backwards empty lines if we are not at the end of the list."
  (save-excursion
    (goto-char (org-list-get-item-end item struct))
    (if (org-list-get-next-item item struct (org-list-prevs-alist struct))
        (forward-line -1)
      (skip-chars-backward " \r\t\n"))
    (point-at-eol)))

(defun ad-org-list-set-item-visibility (oldfun &rest args)
  "Hide empty lines at the end of plain list items.
Around advcie for `org-list-set-item-visibility'
temporarily modifying `org-list-get-item-end-before-blank'
with `my-org-list-get-item-end-before-blank' which see."
  (cl-letf (((symbol-function 'org-list-get-item-end-before-blank)
             #'my-org-list-get-item-end-before-blank))
    (apply oldfun args)))

(advice-add 'org-cycle-internal-local :around #'ad-org-list-set-item-visibility)
(advice-add 'org-list-set-item-visibility :around #'ad-org-list-set-item-visibility)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.