This is the mail archive of the guile-emacs@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: special forms (save-excursion)


Kalle Olavi Niemitalo <tosi@ees2.oulu.fi> writes:

> Why not?  It's expanded to:
> 
> (let ((start (point)))
>   (emacs-eval `(save-excursion
>                  (,(lambda ()
>                      (goto-char start))))))

Oh, sorry, I was careless.  Yes, you are right.  If we had Lisp-side
Scheme values with some more extensions, it would work.

> The Emacs evaluator would have to be changed to call the
> equivalent of guile-apply if the function being called is a
> Scheme object.  I don't know how difficult that is.  If it is too
> much work, the version with an explicit guile-eval could be used.
> This is really the only difference between the versions.

Right.  I guess it's not very difficult to patch the evaluator,
but I would choose the latter since it is easier to implement.
We can switch to the other one anytime later on.

Could you work on adding the new Lisp type to Emacs?  I'm doing
other stuff right now.

> > OK, I'll try to add the type soon.  I guess you can define a new
> > macro `import-lisp-macro'.
> 
> That could be used for all the `save-' macros / special forms.
> But others like `when' and `condition-case' take their parameters
> in different ways and would have to be handled separately.
> Perhaps the importing macro should be called
> `import-lisp-body-macro' because it applies only to macros whose
> parameters form a single body.  Then there could be
> `import-lisp-1-body-macro' for things like `with-current-buffer'
> which take one normal parameter and a body.

I see.  How about this form?

  (import-lisp-body-macro save-execution)
  (import-lisp-body-macro with-current-buffer #t 2)

The second argument can be a Scheme name of the macro unless it is #t.
The third argument is the number of arguments of the macro (1 is default).

> Should I use defmacro instead of syntax-rules?  I like
> syntax-rules more, but it seems slower.

I think faster one is better.  This is not a complex syntax and
easy to maintain.

> How do I define documentation strings for Guile macros?

I have no idea yet.  We can extend our implementation later on.

> >   lisp-variable-ref, lisp-variable-set!,
> >   import-lisp-function, import-lisp-variable
> 
> Are they used like this?
> (lisp-variable-set! (import-lisp-variable 'buffer-read-only) 't)

Like this:

  (import-lisp-variable buffer-read-only)
  (set! (buffer-read-only) t)

or

  (lisp-variable-set! 'buffer-read-only 't)

How this looks like?  This is my current implementation.

------------------------------------------------------------------------
(define-module (emacs emacs))

(define-public t 't)
(define-public nil 'nil)

(define-public (lisp-false? sexp) (or (eq? sexp ()) (eq? sexp nil)))
(define-public (lisp-true? sexp) (not (lisp-false? sexp)))

(define-public (lisp-variable-ref symbol)
  (lisp-eval symbol))

(define-public (lisp-variable-set! symbol value)
  (lisp-eval `(setq ,symbol ,value)))

(define-macro (import-lisp-variable-1 variable . rest)
  (let ((name (if (pair? rest) (car rest) variable)))
    `(define ,name (make-procedure-with-setter
		    (lambda () (lisp-variable-ref ',variable))
		    (lambda (value) (lisp-variable-set! ',variable value))))))
(define-public import-lisp-variable import-lisp-variable-1)

(define-macro (import-lisp-function-1 name)
  (if (lisp-true? (lisp-apply 'functionp (list name)))
      `(define ,name (lambda args (lisp-apply ,name args)))
      (lisp-apply 'error (list "No such function: %s" name))))
(define-public import-lisp-function import-lisp-function-1)
------------------------------------------------------------------------

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]