texmacs-dev
[Top][All Lists]
Advanced

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

Re: [Texmacs-dev] How to create a convertor like texmacs->verbatim


From: Miguel de Benito Delgado
Subject: Re: [Texmacs-dev] How to create a convertor like texmacs->verbatim
Date: Wed, 27 Jul 2011 23:15:18 +0200

Hi,

  I'm not sure if it could help, but in a recent post about bookmarks I posted some scheme code which lists all tags of a given kind in a document. Might this not be used to list all the R input lines? Just a possibility, I wouldn't know...
________________
Miguel de  Benito.


On Wed, Jul 27, 2011 at 15:54, Michael Lachmann <address@hidden> wrote:
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 mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/texmacs-dev


reply via email to

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