Lisp HUG Maillist Archive

Porting Paredit to LispWorks

I asked this question earlier, but I figured that a little more  
information (and a more attention-grabbing subject line :-) might be  
more helpful.

I'd like to port Taylor Campbell's paredit-mode from GNU Emacs to the  
LispWorks IDE.  The port looks to be fairly straightforward, except  
for one function: parse-partial-sexp.  It is a C function in GNU  
Emacs, but I can't turn up anything similar to it in LispWorks.  I  
could go ahead and translate this function (and the functions it  
calls) from C to Lisp, but I'd like to see if there's anything  
already available in LispWorks, since I'm very lazy.  It returns a  
nine-element list describing the state of the s-expression parser in  
some region between FROM and TO.  The C source is fairly hairy (to  
put it mildly), so I'd love it if I could avoid making sense of it.

Once the Paredit port is working, I'll be sure to post the source here.

Thanks,
Bill Atkins



Here's the documentation for the function from GNU Emacs:

parse-partial-sexp is a built-in function in `C source code'.
(parse-partial-sexp from to &optional targetdepth stopbefore oldstate
commentstop)

Parse Lisp syntax starting at from until to; return status of parse  
at to.
Parsing stops at to or when certain criteria are met;
point is set to where parsing stops.
If fifth arg oldstate is omitted or nil,
parsing assumes that from is the beginning of a function.
Value is a list of elements describing final state of parsing:
0. depth in parens.
1. character address of start of innermost containing list; nil if none.
2. character address of start of last complete sexp terminated.
3. non-nil if inside a string.
     (it is the character that will terminate the string,
      or t if the string should be terminated by a generic string  
delimiter.)
4. nil if outside a comment, t if inside a non-nestable comment,
     else an integer (the current comment nesting).
5. t if following a quote character.
6. the minimum paren-depth encountered during this scan.
7. t if in a comment of style b; symbol `syntax-table' if the comment
     should be terminated by a generic comment delimiter.
8. character address of start of comment or string; nil if not in one.
9. Intermediate data for continuation of parsing (subject to change).
If third arg targetdepth is non-nil, parsing stops if the depth
in parentheses becomes equal to targetdepth.
Fourth arg stopbefore non-nil means stop when come to
any character that starts a sexp.
Fifth arg oldstate is a list like what this function returns.
It is used to initialize the state of the parse.  Elements number 1,  
2, 6
and 8 are ignored; you can leave off element 8 (the last) entirely.
Sixth arg commentstop non-nil means stop at the start of a comment.
If it is symbol `syntax-table', stop after the start of a comment or a
string, or after end of a comment or a string.


Re: Porting Paredit to LispWorks


Am 22.10.2006 um 00:45 schrieb Bill Atkins:

>
> I asked this question earlier, but I figured that a little more  
> information (and a more attention-grabbing subject line :-) might  
> be more helpful.
>
> I'd like to port Taylor Campbell's paredit-mode from GNU Emacs to  
> the LispWorks IDE.  The port looks to be fairly straightforward,  
> except for one function: parse-partial-sexp.  It is a C function in  
> GNU Emacs, but I can't turn up anything similar to it in  
> LispWorks.  I could go ahead and translate this function (and the  
> functions it calls) from C to Lisp, but I'd like to see if there's  
> anything already available in LispWorks, since I'm very lazy.  It  
> returns a nine-element list describing the state of the s- 
> expression parser in some region between FROM and TO.  The C source  
> is fairly hairy (to put it mildly), so I'd love it if I could avoid  
> making sense of it.
>
> Once the Paredit port is working, I'll be sure to post the source  
> here.

I've thought about porting Paredit (or creating something similar)  
too. I also ran into the missing PARSE-PARTIAL-SEXP. The LW editor  
provides some parsing constructs - but there seem to be some problems  
with them. The form-movement doesn't seem to realize when the cursor  
is within a string for example. AFAIR I've seen a utility function in  
Edi's lw-add-ons which tests if the cursor is within a string - but  
this doesn't seem to work either. I've written a little tokenizer  
which tries to find out what kind of token is under the cursor. This  
seems to work for not too extreme cases but I still wonder if there  
might be any better LW provided means. In my parser I grab the  
current definition as a string and tokenize it into a list of tokens  
with start and end positions.

ciao,
Jochen


Re: Porting Paredit to LispWorks

On Mon, 23 Oct 2006 00:33:47 +0200, Jochen Schmidt <js@codeartist.org> wrote:

> AFAIR I've seen a utility function in Edi's lw-add-ons which tests
> if the cursor is within a string - but this doesn't seem to work
> either.

It's IN-STRING-P in commands.lisp and it's a hack which only works in
simple cases:

  (defun in-string-p ()
    (save-excursion
      (backward-form-command nil)
      (eql #\" (char-before))))

Specifically, it does not work if the string contains spaces.  It is
only used for the "Indent and Complete Symbol" command to complete to
filenames instead of Lisp expressions if one is within a string.  ISTR
that GNU Emacs with SLIME has the same problems.  Obviously, I'd also
be happy if someone would find a better solution.

Cheers,
Edi.


Updated at: 2020-12-10 08:47 UTC