public inbox for guile-emacs@sourceware.org
 help / color / mirror / Atom feed
From: Keisuke Nishida <kxn30@po.cwru.edu>
To: gerd@gnu.org
Cc: emacs-hackers@gnu.org, guile-emacs@sourceware.cygnus.com
Subject: multibyte string
Date: Tue, 28 Mar 2000 20:40:00 -0000	[thread overview]
Message-ID: <m3u2hqcrsh.fsf_-_@kei.cwru.edu> (raw)
In-Reply-To: <200003281219.OAA02501@online.de>

Gerd Moellmann <gerd@gnu.org> writes:

> On the other hand, I'm not sure one can write a sufficient interface
> between Emacs and the current Guile.  The handling of multibyte text,
> and strings with text properties come to mind.  Can one do something
> meaningful on the Scheme side with multibyte text coming from Emacs?
> Won't text properties be lost when passing them through Scheme?  OTOH,
> I'm not a Guile expert.  Maybe it's doable already, or maybe Ken has
> done worked on this.

This is a rough idea of how to handle multibyte strings within the
current Guile Emacs.

If we call a Lisp function from the Scheme side, it returns a reference
to a Lisp object:

  (lisp-eval '(buffer-string))  => #<lisp-reference "hello">

We can convert this reference to a Scheme string by using the procedure
lispref->scm:

  (lispref->scm (lisp-eval '(buffer-string)))  => "hello"

Since this conversion is inefficient and incomplete, we don't want to
do that.  Instead, we can create a GOOPS (the Guile Object Oriented
Programming System) class to handle Emacs strings:

  (define-class <emacs-string> ...)
  (define hello (make-emacs-string (lisp-eval '(buffer-string))))

  hello         => #<<emacs-string> "hello">

After that, we can define a generic function for each string procedure
so that it calls an appropriate Lisp function:

  (define-method string-ref ((string <emacs-string>) n)
    (lisp-apply 'aref (list (emacs-string-lispref string) n)))

Now we can use string-ref for both Scheme and Lisp strings:

  (string-ref "hello" 0)        => #\h
  (string-ref hello 0)          => #<lisp-reference 104>

We can call any Lisp function as well:

  (define-method insert ((string <emacs-string>))
    (lisp-apply 'insert (list (emacs-string-lispref string))))

  (define-method insert ((string <string>))
    (lisp-apply 'insert (list string)))

  (insert hello)        ;; This inserts "hello"
  (insert "hello")      ;; The same but use a scheme string

Automatic conversion for Scheme procedures can be done this way:

  (define-method eval-string ((string <emacs-string>))
    (eval-string (lispref->scm (emacs-string-lispref string))))

  (eval-string hello)   ;; ERR: Unbound variable: hello

We can handle any Lisp value in this manner.  I guess this solves
most interface problems.  How sweet GOOPS is :)

-- Kei

           reply	other threads:[~2000-03-28 20:40 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <200003281219.OAA02501@online.de>]

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=m3u2hqcrsh.fsf_-_@kei.cwru.edu \
    --to=kxn30@po.cwru.edu \
    --cc=emacs-hackers@gnu.org \
    --cc=gerd@gnu.org \
    --cc=guile-emacs@sourceware.cygnus.com \
    /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).