texmacs-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Texmacs-dev] Scheme to Prolog


From: Joris van der Hoeven
Subject: Re: [Texmacs-dev] Scheme to Prolog
Date: Wed, 14 Feb 2007 13:38:44 +0100
User-agent: Mutt/1.5.9i

On Wed, Feb 14, 2007 at 01:29:50PM +0100, Henri Lesourd wrote:
> Michael Klein wrote:
> 
> >Hello List,
> >
> >I'am trying to write an extension which uses Prolog. At the moment I 
> >want to understand how I can access the active Document in Scheme. I 
> >found the-buffer in a discussion. I tried to use it but got an unbound 
> >variable error. Is there a module I  need to load? Can anybody give me 
> >a hint how to use tree_to_texmacs? What I need is to transform the 
> >tree to a Prolog representation without losing the information on the 
> >origanl tree, so that I can send back editing commands to texmacs.
> >
> The basic tree primitives you can use for accessing trees in TeXmacs are :
> :: (path->tree PATH) -> TREE ;; (tree->path TREE) -> PATH
> :: (tree-label TREE) -> SYMBOL
> :: (tree-arity TREE) -> INTEGER
> :: (tree-ref TREE INTEGER) -> TREE
> :: (tree-set! TREE INTEGER TREE) -> VOID
> :: (cursor-path)
> 
> Explanation : trees in the document are characterized by their *path*,
> which is a list of integers that tells exactly how to descend from the
> root of all the trees inside TeXmacs to the tree you want.
[...]
> Currently, "(path->tree '())" gives you a tuple
> with contains all the buffers (i.e., the "root
> of all the trees"), therefore, you don't need
> to use redundant functions like (the-buffer)
> or anything like that, just get the root tree
> and access it the way you want by means
> of (tree-ref ...).

A few precisions nevertheless:

1) I don't think that functions like buffer-tree are "redudant":
this is the *clean* way to get the current buffer tree.
In the future, it might very well be that the corresponding
path has length > 1.

2) It is good style *not* to work with paths when not necessary.
Indeed, trees in the document *know* about their position and
the tree API (tree-set!, tree-ref, etc.) allows you to directly
modify them. Sometimes, paths are useful though. For instance,
in the piece of code

        (insert-go-to '(frac "1" "1+") '(2 2))

the cursor is explicitly positioned after the "+" using a path.
But it is better to avoid them when adressing pieces of
the document and directly use trees instead.

Best wishes, Joris




reply via email to

[Prev in Thread] Current Thread [Next in Thread]