public inbox for guile-emacs@sourceware.org
 help / color / mirror / Atom feed
* special forms (save-excursion)
@ 2000-03-14 12:46 Kalle Olavi Niemitalo
  2000-03-14 13:32 ` Keisuke Nishida
  2000-03-14 14:11 ` Keisuke Nishida
  0 siblings, 2 replies; 15+ messages in thread
From: Kalle Olavi Niemitalo @ 2000-03-14 12:46 UTC (permalink / raw)
  To: Keisuke Nishida; +Cc: guile-emacs

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)))))))

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2000-03-15 15:14 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-14 12:46 special forms (save-excursion) Kalle Olavi Niemitalo
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

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).