From: Kalle Olavi Niemitalo <tosi@stekt.oulu.fi>
To: Keisuke Nishida <kxn30@po.cwru.edu>
Cc: guile-emacs@sourceware.cygnus.com
Subject: special forms (save-excursion)
Date: Tue, 14 Mar 2000 12:46:00 -0000 [thread overview]
Message-ID: <87n1o1p9kt.fsf@PC486.Niemitalo.LAN> (raw)
How are you going to handle special forms in guile-emacs?
They can't be wrapped as easily as normal functions.
Will their C source be rewritten for Guile?
Below is a macro implementation of save-excursion.
I have tested it with:
(define (test)
(save-excursion
(goto-char (point-min))
(insert "hah")))
I also tried moving the mark-active-var binding to a separate let
between define-syntax and syntax-rules, but that didn't work out.
=================================================================
(use-syntax (ice-9 syncase))
(use-modules (emacs emacs)
(emacs import))
(define set-marker (emacs-import-function 'set-marker))
(define make-marker (emacs-import-function 'make-marker))
(define mark-marker (emacs-import-function 'mark-marker))
(define-syntax save-excursion
(syntax-rules ()
((save-excursion body ...)
(let ((mark-active-var (global-variable 'mark-active))
(outer-buffer *unspecified*)
(outer-point (make-marker))
(outer-mark (make-marker))
(outer-mark-active *unspecified*)
(inner-buffer #f) ; used as a first-time flag
(inner-point (make-marker))
(inner-mark (make-marker))
(inner-mark-active *unspecified*))
(dynamic-wind
(lambda ()
;; save outer state
(set! outer-buffer (current-buffer))
(set-marker outer-point (point))
(set-marker outer-mark (mark-marker))
(set! outer-mark-active (global-ref mark-active-var))
;; restore inner state, if any
(cond (inner-buffer
(set-buffer inner-buffer)
(goto-char inner-point)
(set-marker (mark-marker) inner-mark)
(global-set! mark-active-var inner-mark-active))))
(lambda ()
body ...)
(lambda ()
;; save inner state
(set! inner-buffer (current-buffer))
(set-marker inner-point (point))
(set-marker inner-mark (mark-marker))
(set! inner-mark-active (global-ref mark-active-var))
;; restore outer state
(set-buffer outer-buffer)
(goto-char outer-point)
(set-marker (mark-marker) outer-mark)
(global-set! mark-active-var outer-mark-active)))))))
next reply other threads:[~2000-03-14 12:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-03-14 12:46 Kalle Olavi Niemitalo [this message]
2000-03-14 13:32 ` Keisuke Nishida
2000-03-14 14:11 ` Keisuke Nishida
2000-03-14 14:17 ` Keisuke Nishida
2000-03-15 0:34 ` Kalle Olavi Niemitalo
2000-03-15 3:32 ` Keisuke Nishida
2000-03-15 5:11 ` Kalle Olavi Niemitalo
2000-03-15 5:43 ` Keisuke Nishida
2000-03-15 6:12 ` Kalle Olavi Niemitalo
2000-03-15 11:37 ` guile-emacs GC (was special forms) Kalle Olavi Niemitalo
2000-03-15 12:18 ` Keisuke Nishida
2000-03-15 13:48 ` Jim Blandy
2000-03-15 15:14 ` Keisuke Nishida
2000-03-15 11:30 ` special forms (save-excursion) Kalle Olavi Niemitalo
2000-03-15 12:42 ` Keisuke Nishida
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87n1o1p9kt.fsf@PC486.Niemitalo.LAN \
--to=tosi@stekt.oulu.fi \
--cc=guile-emacs@sourceware.cygnus.com \
--cc=kxn30@po.cwru.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).