[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 15:54:13 +0200 |
I managed to do what I asked for, though it is a hack, and currently only works
on a mac.
Attached is a perl script. It should be saved as convert_pb2R.pl somewhere in
the path.
Then, add this to my-init-texmacs.scm:
(kbd-map ("R R ." (shell "convert_pb2R.pl")
(clipboard-paste "primary")
))
What you can do then is select several input/output cells in an R session (or
even several R sessions). Copy them.
Then go to the place you want to insert them (for example an empty input cell)
and type "RR.". TeXmacs will insert only the R commands in the copied cells.
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>
>
---
#!/usr/bin/perl
open(PB, "pbpaste|") ;
$in_section = 0 ;
$sec_name = "" ;
$section = "" ;
$clip = "" ;
while( <PB> ) {
$line =~ s/\s*$// ;
$line = $_ ;
# print "line: $line |||\n" ;
if( $line =~ s/[<][|]([^>]*)[>]// ) {
$in_section = 1 ;
$prev_section = $section ;
$section = "" ;
}
if( $line =~ s/[<]\/([^>]*)[>]// ) {
$in_section = 0 ;
if( $1 eq "input" ) {
$clip .= $section ;
}
if( $1 eq "unfolded-io" ) {
$clip .= $prev_section ;
}
}
if( $in_section == 1 ) {
if( !($line =~ /^\s*$/ ) ) {
$line =~ s/^ // ;
$line =~ s/\\ / /g ;
$section = $section . $line."\n\n" ;
}
}
}
close(PB) ;
open(PB,"|pbcopy") ;
print PB $clip ;
close(PB) ;
----
- [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, 2011/07/27
- Re: [Texmacs-dev] How to create a convertor like texmacs->verbatim,
Michael Lachmann <=
- 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