[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Texmacs-dev] Making a subtree red
From: |
Henri Lesourd |
Subject: |
Re: [Texmacs-dev] Making a subtree red |
Date: |
Thu, 26 Jul 2007 15:19:47 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030821 |
Michael Klein wrote:
Hello List,
I came up with the following code to make a subtree red:
(tree-set! (path->tree '(0 0)) 0 (quasiquote (with "color "red"
,(tree-ref (path->tree (quote (0 0))) 0))))
Is this a good way to do it when the paths are known?
What you are doing here is making red the *first subtree* of the first
line. But it doesn't work if the first line has no subtree (e.g., it
contains
only a string). Is this what you want ?
Below is some code to turn the 1st line of the current buffer red :
[[
(let* ((buffer-no (car (cursor-path)))
(t (path->tree `(,buffer-no)))
)
(tree-set! t 0 `(with "color "red" ,(tree-ref t 0))))
]]
Another thing you could take care of is not adding more (with ...)
embeddings when there is already one if you perform the operation
several times.
Here is a routine for getting an the inside subtree if it is
surrounded by (with "color" <X> ...) :
[[
(define (inside-subtree t)
(if (and (eq? (tree-label t) 'with)
(equal? (tree->stree (tree-ref t 0)) "color")
)
(tree-ref t (- (tree-arity t) 1))
t))
]]
and then you do :
[[
(let* ((buffer-no (car (cursor-path)))
(t (path->tree `(,buffer-no)))
)
(tree-set! t 0 `(with "color "red" ,(inside-subtree (tree-ref t 0)))))
]]
Best, Henri