2

It is very simple to define a simple generalized setter for buffer-modified-p:

(gv-define-simple-setter buffer-modified-p set-buffer-modified-p)

That enables constructs like:

(with-current-buffer "test.cc"
  (cl-letf (((buffer-modified-p) t))
    (save-buffer)))

If test.cc is out-of-sync it is saved even if (buffer-modified-p) returns nil. The old status of (buffer-modified-p) is unconditionally restored afterwards.

I use that in a special case where there is a special save function which unsets buffer-modified-p but does not save the buffer in the file associated with buffer-file-name.

Question: Is that generalized setter already defined in some existing library?

Note, I know about with-buffer-modified-unmodified from bookmarks.el. But, that is not quite what I want.

1
  • +1. Seems like maybe there should be a simple way to ask this of Emacs. At least for predefined setters, maybe C-h v help could/should mention the known setter(s). If you think so, maybe file an enhancement request (?).
    – Drew
    Commented Aug 2, 2019 at 21:34

0

Your Answer

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

Browse other questions tagged or ask your own question.