This is the mail archive of the guile@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]

Emacs with Guile


Hello,

I'm trying embedding Guile in Emacs.  This is not Guile-based Emacs,
but rather Emacs with Guile.  That is, Emacs now has both Lisp and
Scheme interpreters independently; programmers can write their code
either in Emacs Lisp or in Guile Scheme, or even in both.  My patch
provides some means to exchange objects between Lisp and Scheme.

Emacs now starts in Scheme Interaction mode:

  ---- *scratch* (Scheme Interaction) ------------
  (define (hello) "Hello, World")
  done
  (hello)
  "Hello, World"

  (use-modules (emacs emacs))
  done
  (define message (emacs-import-function 'message))
  done
  (define (hello) (message "Hello, World"))
  done
  (emacs-export-command 'hello ())
  hello
  ------------------------------------------------

And typing `M-x hello' shows "Hello, World" in the minibuffer.
This means that we are now ready to extend Emacs by using Scheme :)
Actually, the Scheme Interaction mode above is written in Scheme.

I'd like to briefly explain how this works.  I have implemented
essentially two primitives: guile-eval for Emacs Lisp, and emacs-eval
for Guile Scheme.  One can use these primitives as follows:

  ---- Emacs Lisp ----------    ---- Guile Scheme --------
  (guile-eval '(+ 1 2)) => 3    (emacs-eval '(+ 1 2)) => 3
  --------------------------    --------------------------

The argument of guile-eval is converted into a Scheme object
internally and passed to the Scheme evaluator.  The result is
converted back into a Lisp object and returned.  The opposite
is done with emacs-eval.  Using these primitives (and some
others), most operations between Lisp and Scheme can be done
without any problem.  (There is some restriction, though.)

So, this is a very simple implementation.  My patch is less than
1000 lines.  But I guess this is enough useful, and the right way
to integrate Guile with Emacs until the real Guile-based Emacs is
available.  I wonder why this approach has not existed yet.  Is
there any problem?  (Or maybe I just don't know such a work?)

My patch is available at:

  http://home.cwru.edu/~kxn30/emacs-20.6-with-guile.diff.gz

This is a patch to GNU Emacs 20.6.  I used the Guile 1.3.5 from
the current CVS.  I have not tried any other versions, but the
same thing can be easily done even with other Emacs such as XEmacs.

So far I have implemented only these functions: scheme-interaction-
mode, guile-scheme-mode, scheme-eval-last-sexp, scheme-eval-print-
last-sexp, and scheme-eval-define.  I'm going to implement further
functions, such as scheme-apropos, scheme-complete-symbol, scheme-
describe-object, scheme-find-function, etc.  A debugger like elisp's
one would be a challenging work.

Since we can now use GOOPS with Emacs programming, reorganization
of Emacs functions might be a good idea.  Every Emacs object can be
considered in terms of object oriented programming.  Since we can
also use GTK+ with Emacs (by using guile-gtk), some better GUI can
be adopted.  Applying keyword arguments for those functions which
have hundreds of optional arguments would be another redesigning
approach.  Why don't we design a whole new set of Emacs functions
in Scheme and map them to the current primitives?  We can extend
Emacs without changing anything of the current core, and start the
Emacs of next generation.  After enough translation is done, the
current Lisp evaluator can be replaced by Guile in order.

I guess there are some people who are interested in doing this.
I would appreciate it if someone could work together.  Any comments
are welcome.

Thanks,
Keisuke Nishida

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