Skip to Content.
Sympa Menu

texmacs-users - Re: [TeXmacs] Show path of current file within text?

Subject: mailing-list for TeXmacs Users

List archive

Re: [TeXmacs] Show path of current file within text?


Chronological Thread 
  • From: Henri Lesourd <address@hidden>
  • To: Norbert Nemec <address@hidden>
  • Cc: address@hidden
  • Subject: Re: [TeXmacs] Show path of current file within text?
  • Date: Wed, 16 Mar 2005 19:09:02 +0100

Thanks for the hint. Unfortunately, my experience with TeXmacs does not suffice to use this information. :-(

My first try so far was
<extern|get-name-buffer>
which gives me "insecure script" or - if I switch off security - "?"

Is there any special trick about it?

It seems that by default, (get-name-buffer) is considered as insecure,
I dont know why. One can, as you did, turn security off to use it in a
macro, but you go in another problem, which is that the type of the result
of (get-name-buffer) is <url>, not <tree>. Consequently, this result is
displayed as a "?" in the document.

How did I found that the type of the result of (get-name-buffer) is <url> ?
I tried "(get-name-buffer)" in a Scheme session :
[[
scheme] (get-name-buffer)
<url /home/henri/test.tm> <<<----- the type is <url ...>
scheme] _
]])

You can also use more than only a function name in an <extern>, namely Scheme
code contained in a (lambda) instruction. For example :
[[
<extern|(lambda () (+ 2 2))>
]]

gives :
[[
4
]]

Now we can write a macro to do the job :
[[
<assign|the-pathname|<macro|(lambda () (url->string (get-name-buffer)))>>
]]

The macro above uses the (url->string) routine that converts an object from the
<url> type to the <string> type. Once converted this way, it's OK.

(To know the name of the available TeXmacs primitives, look in
src/src/Guile/Glue/build-glue-basic(or editor, or server).scm).

But unfortunately, the macro above doesn't work yet, because the symbol ">"
that appears in "url->string" is a special character from the TeXmacs point of
view : if you look in the source, the macro is encoded this way :
[[
<assign|the-pathname|<macro|<extern|(lambda () (url-\<gtr\>string (get-name-buffer)))>>>
]]

so because of this f*****g encoding, TeXmacs calls the "(url-\<gtr\>string)" routine
instead of the real "(url->string)" !

So the final trick is (the macro below should be one-lined in TeXmacs) :

<assign|the-pathname|<macro|<extern|(lambda () ((eval-string
(string-append "url-" (make-string 1 (string-ref "\<gtr\>" 4)) "string"))
(get-name-buffer)))>>>

Then :
[[
<the-pathname>
]]

gives you what you want :-)

Best, Henri

P.S. : The attached .tm file contains the macro and some examples.

P.S(2) : You can find a (work in progress) tutorial which explains in detail how
to write macros, macros in Scheme, and how to package all these things in
plugins at http://www.ags.uni-sb.de/~henri/texmacs/. <http://www.ags.uni-sb.de/%7Ehenri/texmacs/aTeXmacsTutorial.pdf>




Archive powered by MHonArc 2.6.19.

Top of Page