On Sat, Aug 14, 2021 at 11:05:53PM +0200, Emanuel Berg via Users list for the GNU Emacs text editor wrote: > Gregory Heytings wrote: > > >>> (defvar saved-buffer-read-only) > >>> (defun delete-whitespace-at-eol () > >>> (interactive) > >>> (setq saved-buffer-read-only buffer-read-only) > >>> (setq buffer-read-only nil) > >>> (save-excursion (replace-regexp " *$" "" nil (point-min) (point-max))) > >>> (setq buffer-read-only saved-buffer-read-only)) > >> > >> OK, but you don't need to store the old value in a global variable... > >> > > Of course you do, you need to restore the original value [...] > > But there is still no need to use a global variable... That's not the point. You perhaps don't want to trample on one. The let-binding helps you with that. In both cases. Cheers - t