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



_______________________________________________
Texmacs-dev mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/texmacs-dev

Reply via email to