fangle-dev
[Top][All Lists]
Advanced

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

Re: [Fangle-dev] Exporting fangle chunks from TeXmacs


From: Sam Liddicott
Subject: Re: [Fangle-dev] Exporting fangle chunks from TeXmacs
Date: Tue, 22 Jan 2013 14:16:53 +0000

I've added an extract-all option to the menu, like this:

(define (fangle-initialize)
  (define-group enumerate-tag nf-chunk)
  (define-group automatic-section-tag list-of-chunks)
  (menu-extend automatic-menu
    ("List of Fangle chunks" (make-aux* "the-index*" "nf-chunk" "Code Index"))
   )
  (menu-extend texmacs-extra-menu
    (=> "Fangle"
      ("List of Fangle chunks" (make-aux* "the-index*" "nf-chunk" "Code Index"))
      ("Extract All" (fangle-extract-all))
    )
  )
)

(define (fangle-extract-all)
  (let* ((name (string-append (url->system (current-buffer)) ".txt"))
         (tmp-name (string-append name "~")) )
    (export-buffer-main (current-buffer) tmp-name "verbatim" (list :overwrite))
    (system-2 "fangle-refresh" name tmp-name)
  )
)

(plugin-configure fangle
  (:require #t)
  (:initialize (fangle-initialize)))

where a new bash script fangle-refresh is:
#! /bin/bash

diff "$1" "$2" &>/dev/null && { rm "$2"; exit; }

fangle -R "" < "$2" | sed -e 's/^[<][<]//;s/[>][>]$//;/^\.\//!d' -e 's/^\.\//\.\//' | \
while read file
do fangle -R"$file" < "$2" > "$file"
done &&
mv "$2" "$1"


I had to use a new script fangle-refresh because the scheme command system takes only a single long string, and for separate arguments only system-1 or system-2 exist for 1 and 2 arguments.

When I remember how I'll add a shortcut key to invoke fangle-extract-all.

I was surprised at how few scsh primitive's were available in texmacs.

Sam


On Tue, Oct 2, 2012 at 12:53 PM, Michael Lachmann <address@hidden> wrote:
I'm working with fangle in TeXmacs, and I'm trying to make it easier
to extract chunks...

currently I use the following command:
--
(define (fangle-extract part)
  (with file (url->unix (url-temp))
    (with file2 (if extract-remote (url->unix (url-temp)) part)
      (export-buffer file)
      (with res  (system
                  (string-append "fangle -R " part " " file " >" file2
                                 " 2>/tmp/fang.err")
                  )
        (with res2  (if (and extract-remote (= res 0))
                        (system (string-append
                                 "scp " file2 " " rem-path "/" part ) )
                         0 )
          (delete-file file)
          (if extract-remote (delete-file file2) )
          (if (and extract-remote (= res 0)) (list res res2)
              (if (= res 0) "ok" (eval-system "cat /tmp/fang.err") ))
    ) ) ) ) )
-- (this is fairly bad scheme code, I'm still learning -but it works for me...)
and then, I define
(define extract-remote #t) or (define extract-remote #f)
depending on if I want to copy the result to a remote location,
and
(define rem-path "bionc02:projects/Neandertal/resampling")
For the remote path.
Then I insert a scheme session in the file, and issue the command:

Scheme] (fangle-extract "name-of-chunk.C")

Which will either extract the chunk to TeXmacs current directory, or
to a remote directory (I work a lot on remote servers)

What I'd like to do is for the chunk name to be determined automatically.
What I thought is that after or in a chunk, that chunk will be
exported, and that one
can somehow define a chunk to be the "main" chunk, and there will be a
command to export that.

Miguel from the TeXmacs-dev mailing list said:

> However, you have the choice of redefining your nf-chunk macro to set an
> environment variable (say, "current-nf-chunk" to the value you want, then
> read that variable at any point in your document to decide where you are.

I'm not totally sure how to do that... do I just add
<assign|current-nf-chunk|name> inside nf-chunk, or do I need to do
other things?

I also thought about some system where you can unfold nf-ref to what
they represent, or open all such references in a chunk. I think it
should be fairly easy to do this in scheme, so we'd have some version
of fangle in scheme.
One question that I had was that if you wouldn't use scheme, but the
original fangle, it would be nice if I could ask fangle to extract
just the 3rd part of a multipart chunk - because when I am near such a
part, I'd want to just extract it, and not the whole document.

Michael



reply via email to

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