From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kalle Olavi Niemitalo To: Keisuke Nishida Cc: guile-emacs@sourceware.cygnus.com Subject: Re: Emacs Scheme interface Date: Wed, 29 Mar 2000 02:33:00 -0000 Message-id: <87snxagkf9.fsf@PC486.Niemitalo.LAN> References: <87ln33uu6l.fsf@PC486.Niemitalo.LAN> X-SW-Source: 2000-q1/msg00073.html Keisuke Nishida writes: > I think everything in Scheme should be organized in the way of Scheme, > including the naming style. Naming style -- do you mean the question marks, or something else? > Does Guile have any macro like `save-excursion'? Actually, Guile has `save-module-excursion' which takes a thunk parameter. So I suppose `save-excursion' should take a thunk, and the convenient macro (if we provide one) should be called something else like `begin-save-excursion'. > Maybe the new (emacs macro) should provide those convenient macros? That would be convenient. :-) Here is a mostly tested implementation. I did not commit this to CVS because I suppose this shouldn't be in 0.3 yet. ;;; (emacs emacs) (define (lisp-macro->procedure lisp-macro) "Return a procedure which calls LISP-MACRO. The returned procedure accepts one argument, THUNK. It calls LISP-MACRO with one argument: a form which comes back to Scheme and calls THUNK." (lambda (thunk) "Call some Lisp macro, passing it a form which calls THUNK." (lisp-eval `(,lisp-macro (scheme-eval '(',thunk)))))) (define (lisp-macro-1->procedure lisp-macro) "Return a procedure which calls LISP-MACRO. The returned procedure accepts two arguments, PARAM and THUNK. It calls LISP-MACRO with two arguments: the quoted PARAM, and a form which comes back to Scheme and calls THUNK." (lambda (param thunk) "Call some Lisp macro, passing it PARAM and a form which calls THUNK." (lisp-eval `(,lisp-macro ',param (scheme-eval '(',thunk)))))) ;;; (emacs import) (define-public save-excursion (lisp-macro->procedure 'save-excursion)) (define-public with-current-buffer (lisp-macro-1->procedure 'with-current-buffer)) ;;; (emacs macro) (define-macro (define-begin-macro macro-name procedure) "Define a macro MACRO-NAME which calls PROCEDURE with a thunk. The thunk evaluates the macro arguments when called. MACRO-NAME is an unevaluated symbol. PROCEDURE is any expression evaluating to a procedure, such as a variable. It is evaluated where `define-begin-macro' is called." `(define-macro ,macro-name (let ((procedure-val ,procedure)) (lambda body "Call some procedure with a thunk which evaluates BODY." `(',procedure-val (lambda () ,@body)))))) (define-macro (define-begin-macro-1 macro-name procedure) "Define a macro MACRO-NAME which calls PROCEDURE with a parameter and a thunk. The thunk evaluates the other arguments when called. MACRO-NAME is an unevaluated symbol. PROCEDURE is any expression evaluating to a procedure, such as a variable. It is evaluated where `define-begin-macro-1' is called." `(define-macro ,macro-name (let ((procedure-val ,procedure)) (lambda (param . body) "Call some procedure with PARAM and a thunk which evaluates BODY." `(',procedure-val ,param (lambda () ,@body)))))) (define-macro (define-public-begin-macro macro-name procedure) "Like `define-begin-macro', but also export MACRO-NAME." `(begin (define-begin-macro ,macro-name ,procedure) (export ,macro-name))) (define-macro (define-public-begin-macro-1 macro-name procedure) "Like `define-begin-macro-1', but also export MACRO-NAME." `(begin (define-begin-macro-1 ,macro-name ,procedure) (export ,macro-name))) (define-public-begin-macro begin-save-excursion save-excursion) (define-public-begin-macro-1 begin-with-current-buffer with-current-buffer)