kjones@talos.pm.com (Kyle Jones) (06/27/90)
Kimball P Collins writes: > The %% (toggle-read-only) capability of emacs does not meet my needs > because I want the capability of changing the buffer. > > I am looking into implementing an additional feature, which has @@ on > the mode line in a different spot (different from where (**, %%) are) > and allows you to write into the buffer, but won't let the buffer be > saved. This is somewhat like making a buffer into another scratch > buffer for as long as it is in @@ mode. > > For this, I need to > > * write toggle-buffer-offer-save You'll need to do a bit more than just toggle buffer-offer-save. Emacs will ask to save any buffer that has a filename associated with it (via buffer-file-name). So your toggle function will need to set/reset the value of buffer-file-name for file buffers. > * add mode-line-buffer-offer-save to mode-line so that it > prints "@@" or "--" depending on the value of > mode-line-modified, or another variable > > The problem is that mode-line is not flexible about functions that can > be called for it. In fact, no user-specified functions can be called during mode-line-format processing. (I suspect that this restriction exists so that the display routines and other routines that call them needn't worry about garbage collection.) But you can control the mode-line based on the value of Lisp variables, and that's all you need here. Try this: (setq-default mode-line-modified (cons '(buffer-file-name "----" (buffer-offer-save "----" "--@@")) mode-line-modified))
kpc00@ccc.amdahl.com (Kimball P Collins) (06/28/90)
In article <1990Jun27.145013.29422@talos.pm.com> kjones@talos.pm.com (Kyle Jones) writes: >You'll need to do a bit more than just toggle buffer-offer-save. >Emacs will ask to save any buffer that has a filename associated >with it (via buffer-file-name). So your toggle function will >need to set/reset the value of buffer-file-name for file buffers. Quite right. I ended up writing (toggle-buffer-saveable) (perhaps "-saveability" would be a better name since there is no associated Boolean variable). I did not implement an alist to be able to restore the original file name since it would potentially get messy when set-visited-file-name or rename-buffer happen before one toggles saveability back on, etc. A Boolean variable for saveability in emacs might be a nice change to have for version 19. > >Try this: > >(setq-default mode-line-modified > (cons '(buffer-file-name "----" > (buffer-offer-save "----" "--@@")) > mode-line-modified)) Thanks very much. The above setq-default seems to work fine, but I wonder about the purpose of purecopy in the loaddefs.el defconst for this variable. Can it be set without overwriting memory anyplace? Would it be beneficial to defconst the variable again? -- Neither representing Amdahl nor necessarily myself.
holley@sono.UUCP (Greg Holley) (07/06/90)
Note: This stream (with its rather unintuitive title) concernt a possible EMACS mode that would allow editing of a buffer, but never write changes to a file. This is different from the current read-only mode, which doesn't allow the buffer to be changed. It seems to me that the best way to implement this would be via write-file-hooks. Simply write a routine that checks a boolean variable to see if the buffer in question is non-writeable, and return t if non-writeable. Then call that routine via write-file-hooks. -- --Greg Holley sun!sono!holley holley%sono@sun.com "My tale is so strange that, were it written with needles on the interior corner of an eye, yet would it prove a lesson to the circumspect."
merlyn@iwarp.intel.com (Randal Schwartz) (07/07/90)
In article <793@sono.UUCP>, holley@sono (Greg Holley) writes: | Note: This stream (with its rather unintuitive title) concernt a | possible EMACS mode that would allow editing of a buffer, but never | write changes to a file. This is different from the current read-only | mode, which doesn't allow the buffer to be changed. | | It seems to me that the best way to implement this would be via | write-file-hooks. Simply write a routine that checks a boolean variable | to see if the buffer in question is non-writeable, and return t if | non-writeable. Then call that routine via write-file-hooks. Or even simpler, just (setq buffer-file-name nil). Too easy. -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/
kpc00@JUTS.ccc.amdahl.com (Kimball P Collins) (07/07/90)
In article <793@sono.UUCP> holley@sono.UUCP (Greg Holley) writes:
It seems to me that the best way to implement this would be via
write-file-hooks. Simply write a routine that checks a boolean
variable to see if the buffer in question is non-writeable, and
return t if non-writeable. Then call that routine via
write-file-hooks.
This is a good idea, since it avoids having to lose or store the
associated file name for a buffer. But it would require more hacking
to have it work automatically for help buffers, mail buffers (for
which I use "++", by the way, since they are writable but have no
associated file name to begin with), and the like. The previous
solution, which uses the associated file name, works automatically.
The hacking required there is some means of storing the file name for
when "@@" mode is toggled back off.
--
Neither representing any company nor, necessarily, myself.