0

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?

Drew
  • 75,699
  • 9
  • 109
  • 225
AlwaysLearning
  • 749
  • 4
  • 14
  • 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: https://emacs.stackexchange.com/questions/31719/something-like-save-excursion-that-saves-the-complete-buffer-state 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 '17 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). – AlwaysLearning Jul 11 '17 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! – AlwaysLearning Jul 11 '17 at 15:10

1 Answers1

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.

Stefan
  • 26,154
  • 3
  • 46
  • 84