[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Texmacs-dev] How to create a convertor like texmacs->verbatim
From: |
Michael Lachmann |
Subject: |
Re: [Texmacs-dev] How to create a convertor like texmacs->verbatim |
Date: |
Wed, 27 Jul 2011 12:12:01 +0200 |
Ok, I think I really don't understand what is going on.
The code to pipe the selection through an external command I took from
examples/plugins/substitute
Here is what it looks like:
----
(define (substitute-substitute)
(import-from (utils plugins plugin-eval))
(if (selection-active-any?)
(let* ((t (tree->stree (selection-tree)))
(uu (plugin-eval "substitute" "default" t)))
;; (clipboard-copy "primary")
(insert (stree->tree uu))
)))
(kbd-map
("C-9" (substitute-substitute)))
(plugin-configure substitute
(:require (url-exists-in-path? "substitute.bin"))
(:launch "substitute.bin")
(:session "Substitute"))
---
It works. I press ctrl-9, and the selection is piped through my command
(substitute.bin). But, when the expression is more complicated, I get nothing.
So if selection is "Hello There", I get the text "Hello There".
if selection is "$x^100$" (i.e. a formula), I get "x^100".
If selection is "$x^100$ Hello There" (i.e. formula + text), I get nothing
(i.e. I get an empty string).
If selection spans several input/output cells in an R session, I get nothing.
What could the problem be? Above, I call (let* ((t (tree->stree
(selection-tree)))
What does tree->stree do? I was assuming it turns a tree into a string
representation of the tree. Why do I then get an empty string?
Thanks for listening!
Michael
On 27 Jul 2011, at 2:19AM, Michael Lachmann wrote:
> I am trying to make it easier to work with R in TeXmacs. What often happens
> is that in an interactive session I type
> in many commands one after the other - each in its own input. at some point
> everything works, and I'd like to just copy them all into a script, or maybe
> into one multiline input.
>
> So, I'd like to be able to select text, and copy just the R part. That would
> be parts between
> <|input>
> and
> </input>
>
> Since I don't know scheme well, or maybe not at all, I thought to pipe
> selection through an external program.
>
> To do that, I first duplicated the end of
> progs/convert/rewrite/init-rewrite.scm into my init-r.scm (the part that
> deals with converting to verbatim), and modified verbatim to read verbatimR.
> I did manage to have that pipe though an external program. But I am
> encountering a strange problem:
> When I select regular text, and do edit->copy to->verbatimR
>
> all works well, the text I select is piped to the external program.
>
> However, if I select several input/output fields from an R session, then I
> seem to get nothing. Even for a simple expression with a formula in it,
> nothing is copied.
>
> Below is the code - this just duplicates the functionality of "verbatim",
> with a new name "verbatimR". (i.e. no piping to external program, yet)
>
> This code works for simple text, but not for complicated text, and I don't
> understand why...
>
> -------
> (tm-define (texmacs->verbatimR x . opts)
> (if (list-1? opts) (set! opts (car opts)))
> (let* ((wrap? (== (assoc-ref opts "texmacs->verbatimR:wrap") "on"))
> (enc (or (assoc-ref opts "texmacs->verbatimR:encoding") "iso-8859-1")))
> (cpp-texmacs->verbatim x wrap? enc)))
>
> (tm-define (verbatimR->texmacs x . opts)
> (if (list-1? opts) (set! opts (car opts)))
> (let* ((wrap? (== (assoc-ref opts "verbatimR->texmacs:wrap") "on"))
> (enc (or (assoc-ref opts "verbatimR->texmacs:encoding") "iso-8859-1")))
> (cpp-verbatim->texmacs x wrap? enc)))
>
> (tm-define (verbatimR-snippet->texmacs x . opts)
> (if (list-1? opts) (set! opts (car opts)))
> (let* ((wrap? (== (assoc-ref opts "verbatimR->texmacs:wrap") "on"))
> (enc (or (assoc-ref opts "verbatimR->texmacs:encoding") "iso-8859-1")))
> (cpp-verbatim-snippet->texmacs x wrap? enc)))
>
>
> (define-format verbatimR
> (:name "VerbatimR")
> (:suffix "txtR"))
>
> (converter verbatimR-document texmacs-tree
> (:function-with-options verbatimR->texmacs)
> (:option "verbatimR->texmacs:wrap" "off")
> (:option "verbatimR->texmacs:encoding" "utf-8"))
>
> (converter verbatimR-snippet texmacs-tree
> (:function-with-options verbatimR-snippet->texmacs)
> (:option "verbatimR->texmacs:wrap" "off")
> (:option "verbatimR->texmacs:encoding" "utf-8"))
>
> (converter texmacs-tree verbatimR-document
> (:function-with-options texmacs->verbatimR)
> (:option "texmacs->verbatimR:wrap" "off")
> (:option "texmacs->verbatimR:encoding" "utf-8"))
>
> (converter texmacs-tree verbatimR-snippet
> (:function-with-options texmacs->verbatimR)
> (:option "texmacs->verbatimR:wrap" "off")
> (:option "texmacs->verbatimR:encoding" "utf-8"))
> ------------
>
>
> Does anyone have an idea what the problem is?
>
> Thanks,
> Michael
>
>
>
> _______________________________________________
> Texmacs-dev mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/texmacs-dev
>
>
>
- [Texmacs-dev] How to create a convertor like texmacs->verbatim, Michael Lachmann, 2011/07/26
- Re: [Texmacs-dev] How to create a convertor like texmacs->verbatim,
Michael Lachmann <=
- Re: [Texmacs-dev] How to create a convertor like texmacs->verbatim, Michael Lachmann, 2011/07/27
- Re: [Texmacs-dev] How to create a convertor like texmacs->verbatim, Miguel de Benito Delgado, 2011/07/27
- Re: [Texmacs-dev] How to create a convertor like texmacs->verbatim, Michael Lachmann, 2011/07/27
- Re: [Texmacs-dev] How to create a convertor like texmacs->verbatim, Michael Lachmann, 2011/07/27
- Re: [Texmacs-dev] How to create a convertor like texmacs->verbatim, Sam Liddicott, 2011/07/28
- Re: [Texmacs-dev] How to create a convertor like texmacs->verbatim, Miguel de Benito Delgado, 2011/07/29
- Re: [Texmacs-dev] How to create a convertor like texmacs->verbatim, Michael Lachmann, 2011/07/29
- Re: [Texmacs-dev] How to create a convertor like texmacs->verbatim, Miguel de Benito Delgado, 2011/07/29