I wrote a wrapper for the existing export function. My wrapper adds an appropriate bibliography: link, calls the original export function and then removes the bibliography: link. In summary, the function modifies the buffer, but undoes those modifications (without actually using undo).

Is it safe to put the body of such a function inside with-silent-modifications?

  • Here is link to a related thread that has answers and links (in the comments) of ways to use the buffer contents with a temporary buffer or a cloned buffer: emacs.stackexchange.com/questions/31719/… If the buffer-undo-list is also cloned, then it may be necessary to use something like (let ((buffer-undo-list t)) ...) to preserve the list. I voted to close this current thread because using with-silent-modifications is a matter of personal preference, and people may like it or not like it for a variety of reasons.
    – lawlist
    Jul 11, 2017 at 13:21
  • @lawlist I do not want to clone the buffer or use a temporary one. I think that this is an unnecessary complication in this case and might interfere with the name used for the exported file. Also, not keeping buffer-undo-list is not the only thing achieved by with-silent-modifications. The latter also makes sure that the buffer is considered to be unmodified (if it was such before the modification). Jul 11, 2017 at 14:55
  • 2
    @lawlist That you prefer to not use with-silent-modifications is not a valid reason to close all threads about it! Jul 11, 2017 at 15:10

1 Answer 1


Yes, it should be safe (assuming you're careful enough to make sure that the buffer is really unchanged in the end).

But be careful: if the code that is run while the buffer is modified is complex enough you might get into trouble (e.g. it might fill the syntax-ppss cache with data which won't be flushed when you undo the changes). Even worse if the code runs external processes asynchronously, in which case the effect of with-silent-modifications might leak to code that doesn't expect it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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