|
From: | Gregory Heytings |
Subject: | Re: Lexical vs. dynamic: small examples? |
Date: | Sat, 14 Aug 2021 20:23:35 +0000 |
(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, which could be either t or nil. But indeed TIMTOWTDI: for this specific example, another way to do it would be to introduce a conditional. In general however variables can hold more than two values, so for didactic purposes the above is much clearer.
[Prev in Thread] | Current Thread | [Next in Thread] |