1

I use a hook to delete trailing whitespace on saving files:

(use-package emacs
  :hook (before-save . delete-trailing-whitespace))

This works well in 99% of cases. However, if I am trying to create a presentation using an org-file then the above command will also delete the required whitespace immediately following the org header which begins with an asterisk. Therefore, the headings will not be properly exported when trying to create the presentation.

E.g. this works:

*[space]
Praesent augue.  Aliquam erat volutpat.  Nunc eleifend leo vitae magna.  In id erat non orci commodo lobortis.  Proin neque massa, cursus ut, gravida ut, lobortis eget, lacus.  Sed diam.  Praesent fermentum tempor tellus.  Nullam tempus.

This does not:

*
Praesent augue.  Aliquam erat volutpat.  Nunc eleifend leo vitae magna.  In id erat non orci commodo lobortis.  Proin neque massa, cursus ut, gravida ut, lobortis eget, lacus.  Sed diam.  Praesent fermentum tempor tellus.  Nullam tempus.  Mauris ac felis vel velit tristique

How could I add an exception to the hook so that org-headings are unaffected.

  • 1
    I don't think you can modify the behaviour of delete-trailing-whitespace to do what you want, so maybe modify the hook to add some dummy text to empty headlines, then run `delete-trailing-whitespace, then delete the dummy text. But why not make it a point not to have empty headlines? – NickD Jan 17 at 14:55

Your Answer

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

Browse other questions tagged or ask your own question.