* Form to store/recover buffer modified state?
@ 2003-08-28 20:08 Joakim Hove
2003-09-03 1:29 ` Jesper Harder
0 siblings, 1 reply; 5+ messages in thread
From: Joakim Hove @ 2003-08-28 20:08 UTC (permalink / raw)
Hello,
I have some buffer manipulating[1] functions which are wrapped in a
construct like this:
(let ((modified (buffer-modified-p)))
;;
(lots of code)
;;
(if (not modified) (set-buffer-modifed-p nil)))
To ensure that the buffer is not marked as modified when the function
has finished executing. Is there a special form, i.e. resembling
(save-excursion ) to achieve this?
regards Joakim
[1] The manipulations in question are typically text properties,
i.e. manipulations which should not be saved.
--
/--------------------------------------------------------------------\
/ Joakim Hove / hove@bccs.no / (55 5) 84076 | \
| Unifob AS, Avdeling for Beregningsvitenskap (BCCS) | Stabburveien 18 |
| CMU | 5231 Paradis |
\ Thormøhlensgt.55, 5020 Bergen. | 55 91 28 18 /
\--------------------------------------------------------------------/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Form to store/recover buffer modified state?
2003-08-28 20:08 Form to store/recover buffer modified state? Joakim Hove
@ 2003-09-03 1:29 ` Jesper Harder
2003-09-03 7:06 ` Joakim Hove
2003-09-05 16:18 ` Stefan Monnier
0 siblings, 2 replies; 5+ messages in thread
From: Jesper Harder @ 2003-09-03 1:29 UTC (permalink / raw)
Joakim Hove <hove@bccs.no> writes:
> I have some buffer manipulating[1] functions which are wrapped in a
> construct like this:
>
> (let ((modified (buffer-modified-p)))
> ;;
> (lots of code)
> ;;
> (if (not modified) (set-buffer-modifed-p nil)))
>
> To ensure that the buffer is not marked as modified when the function
> has finished executing. Is there a special form, i.e. resembling
> (save-excursion ) to achieve this?
I don't think there's an existing special form. But you can always
create you own macro that works like a special form. Something like:
(defmacro save-modified (&rest body)
(let ((temp (make-symbol "modified")))
`(let ((,temp (buffer-modified-p)))
(unwind-protect
(progn
,@body)
(unless ,temp
(set-buffer-modified-p nil))))))
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Form to store/recover buffer modified state?
2003-09-03 1:29 ` Jesper Harder
@ 2003-09-03 7:06 ` Joakim Hove
2003-09-03 15:48 ` Jesper Harder
2003-09-05 16:18 ` Stefan Monnier
1 sibling, 1 reply; 5+ messages in thread
From: Joakim Hove @ 2003-09-03 7:06 UTC (permalink / raw)
Jesper Harder <harder@myrealbox.com> writes:
> (defmacro save-modified (&rest body)
> (let ((temp (make-symbol "modified")))
> `(let ((,temp (buffer-modified-p)))
> (unwind-protect
> (progn
> ,@body)
> (unless ,temp
> (set-buffer-modified-p nil))))))
Thanks a lot, it works like intended, but (e)lisp code containing the
"magic" characters "@", "," and "`" is beyond me. I will try to
decipher it and see what I can learn!
Thanks again :-)
Joakim
--
/--------------------------------------------------------------------\
/ Joakim Hove / hove@bccs.no / (55 5) 84076 | \
| Unifob AS, Avdeling for Beregningsvitenskap (BCCS) | Stabburveien 18 |
| CMU | 5231 Paradis |
\ Thormøhlensgt.55, 5020 Bergen. | 55 91 28 18 /
\--------------------------------------------------------------------/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Form to store/recover buffer modified state?
2003-09-03 7:06 ` Joakim Hove
@ 2003-09-03 15:48 ` Jesper Harder
0 siblings, 0 replies; 5+ messages in thread
From: Jesper Harder @ 2003-09-03 15:48 UTC (permalink / raw)
Joakim Hove <hove@bccs.no> writes:
> Jesper Harder <harder@myrealbox.com> writes:
>
>> (defmacro save-modified (&rest body)
>> (let ((temp (make-symbol "modified")))
>> `(let ((,temp (buffer-modified-p)))
>> (unwind-protect
>> (progn
>> ,@body)
>> (unless ,temp
>> (set-buffer-modified-p nil))))))
>
> Thanks a lot, it works like intended, but (e)lisp code containing the
> "magic" characters "@", "," and "`" is beyond me.
The backquote constructs aren't essential to the macro. They just
make it easier to write (and read, IMHO).
You could also write the macro this way without using backquote:
(defmacro save-modified (&rest body)
(let ((temp (make-symbol "modified")))
(list 'let (list (list temp (list 'buffer-modified-p)))
(list 'unwind-protect
(append '(progn)
body)
(list 'unless temp
(list 'set-buffer-modified-p nil))))))
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Form to store/recover buffer modified state?
2003-09-03 1:29 ` Jesper Harder
2003-09-03 7:06 ` Joakim Hove
@ 2003-09-05 16:18 ` Stefan Monnier
1 sibling, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2003-09-05 16:18 UTC (permalink / raw)
>> (let ((modified (buffer-modified-p)))
>> ;;
>> (lots of code)
>> ;;
>> (if (not modified) (set-buffer-modifed-p nil)))
Note that it's recommended to use restore-buffer-modified-p
in such a case.
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2003-09-05 16:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-28 20:08 Form to store/recover buffer modified state? Joakim Hove
2003-09-03 1:29 ` Jesper Harder
2003-09-03 7:06 ` Joakim Hove
2003-09-03 15:48 ` Jesper Harder
2003-09-05 16:18 ` Stefan Monnier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).