On 30 Jul 2011, at 12:55AM, Miguel de Benito Delgado wrote: > If you need to pipe data between your program and texmacs, then the best way > is a plugin. Search the documentation for "plugin" and read for instance > "Background evaluations" and "Mathematical and customized input". That ought > to be just what you need.
That's where I started... I tried using the "substitute.bin" example. but it didn't work. : > 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. Oh, but you wrote I should look in "Mathematical and customized input".... yes, you are right!! That's why I get nothing....I need to provide my own serializer. I'll try that... > Of course, you could also keep banging your head against the painful Scheme > wall (I know it hurts). Then I must point out that the reason why you are not > getting all of the lines in the selection might be that only the active > prompt is of <input> type. In a scheme session I have right here open by my > side, every line above the prompt (i.e. those commands I already evaluated) > are <unfolded-io> tags. Although probably you already realized this... :) Yes, I did. One strange thing that I haven't figured out yet is where the R input is supposed to be in the <unfolded-io> tag. In R, it seems it is in the one-before-last <|unfolded-io> tag. In Scheme, it seems to be in the </unfolded-io> tag. I'm not sure if that is because the R interface does something wrong.... The </unfolded-io> tag in the R session contains the prompt. Anyway, I think I managed to finally make it work, though I still pipe it to an external command, and that commend then puts it in the clipboard. > > Best, > ________________ > Miguel de Benito. > > > On Thu, Jul 28, 2011 at 01:29, Michael Lachmann <lachm...@eva.mpg.de> wrote: > Ok, the following works: > --- > (kbd-map ("C-8" > (let* ( > (f (url-concretize (url-temp))) > (p (open-output-file f)) > ) > (write (selection-tree) p) > (close-output-port p) > (eval-system (string-append "convert_pb2R.pl " f)) > ) ) ) > --- > This will save the current selection to a temporary file, then run > convert_pb2R on it. convert_pb2R will then put the converted text onto the > clipboard, which then I can insert into the buffer. This still uses the > command pbcopy to put the string back into the selection buffer (though it > should be possible from TeXmacs), and analyzing the tree from withing TeXmacs > would be much more elegant... > > Comments welcome. > Thanks! > > Michael > > > On 28 Jul 2011, at 12:28AM, Michael Lachmann wrote: > >> >> On 27 Jul 2011, at 11:15PM, Miguel de Benito Delgado wrote: >> >>> 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... >> >> Here is my feeble attempt: >> >> (kbd-map ("C-8" >> (for-each (lambda (item) >> (display (tree->string (tree-ref item 0)))) >> (selection-tree) >> ) >> ) >> ) >> >> But, it doesn't work. I get an error: >> In procedure for-each in expression (for-each (lambda # #) >> (selection-tree)): >> Wrong type argument in position 2: <tree <math|x<rsup|2>> Hello> >> >> Which is kind of funny, since the error statement contains the string I'd >> like to get :) all I want is a string like that: >> >> <tree <math|x<rsup|2>> Hello> >> >> MIchael >> >> P.S. Just a comment. I think there is a bug in the scheme session, in that >> expressions such as "tree->string" are converted to >> "tree-<gtr>string", and then you get an error that that function is not >> defined. >> >> >>> ________________ >>> Miguel de Benito. >>> >>> >>> On Wed, Jul 27, 2011 at 15:54, Michael Lachmann <lachm...@eva.mpg.de> 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 >>> Texmacs-dev@gnu.org >>> https://lists.gnu.org/mailman/listinfo/texmacs-dev >>> >>> _______________________________________________ >>> Texmacs-dev mailing list >>> Texmacs-dev@gnu.org >>> https://lists.gnu.org/mailman/listinfo/texmacs-dev >> >> _______________________________________________ >> Texmacs-dev mailing list >> Texmacs-dev@gnu.org >> https://lists.gnu.org/mailman/listinfo/texmacs-dev > > > _______________________________________________ > Texmacs-dev mailing list > Texmacs-dev@gnu.org > https://lists.gnu.org/mailman/listinfo/texmacs-dev > > > _______________________________________________ > Texmacs-dev mailing list > Texmacs-dev@gnu.org > https://lists.gnu.org/mailman/listinfo/texmacs-dev
_______________________________________________ Texmacs-dev mailing list Texmacs-dev@gnu.org https://lists.gnu.org/mailman/listinfo/texmacs-dev