* Re: How to Determine the Current File Name and Line Number in the ConTeXt Source?
@ 2009-07-03 14:22 Tad Ashlock
2009-07-03 15:23 ` Hans Hagen
2009-07-06 12:52 ` Taco Hoekwater
0 siblings, 2 replies; 7+ messages in thread
From: Tad Ashlock @ 2009-07-03 14:22 UTC (permalink / raw)
To: ntg-context
Hans Hagen wrote:
> Tad Ashlock wrote:
> > Is there a convenient way within a Lua block to determine the current
> > file name and line number of the source file being processed by
ConTeXt?
[snip]
> i have no time now to figure out while filenames are not known but
> here's a (wikifyable) hack:
[snip]
> line = status.linenumber,
> file = status.filename
From the luatex 0.40.6 sources
(luatex/source/texk/web2c/luatexdir/lua/lstatslib.c):
----------------------------------------------------------
/* hack, I really should implement the makecstring */
char *getfilename(void)
{
integer t;
t = get_current_name();
if (t > (1 << 21))
return makecstring(t);
else
return xstrdup("");
}
----------------------------------------------------------
Looks like we're always getting the xstrdup() branch of the conditional.
Hans, would you like me to submit this as a luatex bug?
Tad
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to Determine the Current File Name and Line Number in the ConTeXt Source?
2009-07-03 14:22 How to Determine the Current File Name and Line Number in the ConTeXt Source? Tad Ashlock
@ 2009-07-03 15:23 ` Hans Hagen
2009-07-06 12:52 ` Taco Hoekwater
1 sibling, 0 replies; 7+ messages in thread
From: Hans Hagen @ 2009-07-03 15:23 UTC (permalink / raw)
To: mailing list for ConTeXt users
Tad Ashlock wrote:
> Hans Hagen wrote:
> > Tad Ashlock wrote:
> > > Is there a convenient way within a Lua block to determine the current
> > > file name and line number of the source file being processed by
> ConTeXt?
>
> [snip]
>
> > i have no time now to figure out while filenames are not known but
> > here's a (wikifyable) hack:
> [snip]
> > line = status.linenumber,
> > file = status.filename
>
> From the luatex 0.40.6 sources
> (luatex/source/texk/web2c/luatexdir/lua/lstatslib.c):
> ----------------------------------------------------------
> /* hack, I really should implement the makecstring */
> char *getfilename(void)
> {
> integer t;
> t = get_current_name();
> if (t > (1 << 21))
> return makecstring(t);
> else
> return xstrdup("");
> }
> ----------------------------------------------------------
>
> Looks like we're always getting the xstrdup() branch of the conditional.
>
> Hans, would you like me to submit this as a luatex bug?
taco reads this mail anyway so this suits as bug report
Hans
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
| www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to Determine the Current File Name and Line Number in the ConTeXt Source?
2009-07-03 14:22 How to Determine the Current File Name and Line Number in the ConTeXt Source? Tad Ashlock
2009-07-03 15:23 ` Hans Hagen
@ 2009-07-06 12:52 ` Taco Hoekwater
1 sibling, 0 replies; 7+ messages in thread
From: Taco Hoekwater @ 2009-07-06 12:52 UTC (permalink / raw)
To: mailing list for ConTeXt users
Tad Ashlock wrote:
>
> Looks like we're always getting the xstrdup() branch of the conditional.
Probably because you are not reading from a file at that level,
but from a token list. Do you want filename to be a file even
if the current input is not directly from a file at all
(doable, but less meaningful)?
Best wishes,
Taco
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to Determine the Current File Name and Line Number in the ConTeXt Source?
2009-07-07 18:09 Tad Ashlock
@ 2009-07-08 8:27 ` Taco Hoekwater
0 siblings, 0 replies; 7+ messages in thread
From: Taco Hoekwater @ 2009-07-08 8:27 UTC (permalink / raw)
To: mailing list for ConTeXt users
Tad Ashlock wrote:
>
> Now you say that ConTeXt may not be reading from a file at that level.
> That I can accept (being a non-expert), but status.linenumber always
> returns the correct line number for the ConTeXt file being processed
> (even if the file is being \input from another file). It seems to me
> that if the line number within the source file is accurate, then the
> file's name should be accurate, too.
I've patched status.filename so that it will behave like that starting
with the next beta.
Best wishes,
Taco
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to Determine the Current File Name and Line Number in the ConTeXt Source?
@ 2009-07-07 18:09 Tad Ashlock
2009-07-08 8:27 ` Taco Hoekwater
0 siblings, 1 reply; 7+ messages in thread
From: Tad Ashlock @ 2009-07-07 18:09 UTC (permalink / raw)
To: mailing list for ConTeXt users
Taco Hoekwater wrote:
> Tad Ashlock wrote:
> >
> > Looks like we're always getting the xstrdup() branch of the conditional.
>
> Probably because you are not reading from a file at that level,
> but from a token list. Do you want filename to be a file even
> if the current input is not directly from a file at all
> (doable, but less meaningful)?
>
> Best wishes,
> Taco
Hi Taco,
I'm far from an expert in this realm, but since you asked what *I*
want... :)
My intention is to associate status.filename and status.linenumber
together. That is, I would read and save their values consecutively in
the same Lua function so that they would refer to the ConTeXt source
line currently being processed by the ConTeXt engine.
Now you say that ConTeXt may not be reading from a file at that level.
That I can accept (being a non-expert), but status.linenumber always
returns the correct line number for the ConTeXt file being processed
(even if the file is being \input from another file). It seems to me
that if the line number within the source file is accurate, then the
file's name should be accurate, too.
Thank you,
Tad
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to Determine the Current File Name and Line Number in the ConTeXt Source?
2009-07-01 11:01 Tad Ashlock
@ 2009-07-01 14:26 ` Hans Hagen
0 siblings, 0 replies; 7+ messages in thread
From: Hans Hagen @ 2009-07-01 14:26 UTC (permalink / raw)
To: mailing list for ConTeXt users
Tad Ashlock wrote:
> Is there a convenient way within a Lua block to determine the current
> file name and line number of the source file being processed by ConTeXt?
>
> For example: (test.tex)
> ---------------------------------
> \def\ShowLineNumber{%
> \ctxlua{print('current line number:', tex.current_line_number())
> print('current file:', tex.current_file_name())}}
> \starttext
> a line
> \ShowLineNumber
> another line
>
> \ShowLineNumber
> \stoptext
> ---------------------------------
>
> With the following displayed:
> ---------------------------------
> current line number: 6
> current file: test.tex
> current line number: 9
> current file: test.tex
> ---------------------------------
>
> I've considered hooking into the open_read_file callback and tracking
> the file name and line number (via reader) myself. But that seems a bit
> heavy handed if the file name and line number information are available
> more directly. And since that information is needed for error
> reporting, I'm thinking there's a good chance it is accessible.
>
> (Just in case you're interested, the purpose of this is to be able to
> assemble code segments during the ConTeXt processing into external files
> with #line directives ala the C preprocessor. That way if the
> subsequent compilation of the external file results in an error, the
> error message can refer back to the line of code in the ConTeXt source
> file. This is part of the literate programming module that Kevin
> Robbins has been describing in another thread.)
i have no time now to figure out while filenames are not known but
here's a (wikifyable) hack:
\starttext
% needs to be added to buff-ini.lua
%
% function buffers.raw(name)
% return data[name] or { }
% end
\startluacode
local locations = { }
function document.set_number(name)
locations[name] = {
line = status.linenumber,
file = status.filename
}
end
function document.add_number(name)
local b, l = buffers.raw(name), locations[name]
if b and l then
for i=1,#b do
b[i] = string.gsub(b[i],"# line: <number>","# line: "
.. l.line + 2)
end
end
end
\stopluacode
\ctxlua{document.set_number("oeps")}
\startbuffer[oeps]
# line: <number>
test
test
\stopbuffer
\ctxlua{document.add_number("oeps")}
\typebuffer[oeps]
\stoptext
when i have time (or reason) i'll think about a more integrated approach
with hooks
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
| www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 7+ messages in thread
* How to Determine the Current File Name and Line Number in the ConTeXt Source?
@ 2009-07-01 11:01 Tad Ashlock
2009-07-01 14:26 ` Hans Hagen
0 siblings, 1 reply; 7+ messages in thread
From: Tad Ashlock @ 2009-07-01 11:01 UTC (permalink / raw)
To: ntg-context
Is there a convenient way within a Lua block to determine the current
file name and line number of the source file being processed by ConTeXt?
For example: (test.tex)
---------------------------------
\def\ShowLineNumber{%
\ctxlua{print('current line number:', tex.current_line_number())
print('current file:', tex.current_file_name())}}
\starttext
a line
\ShowLineNumber
another line
\ShowLineNumber
\stoptext
---------------------------------
With the following displayed:
---------------------------------
current line number: 6
current file: test.tex
current line number: 9
current file: test.tex
---------------------------------
I've considered hooking into the open_read_file callback and tracking
the file name and line number (via reader) myself. But that seems a bit
heavy handed if the file name and line number information are available
more directly. And since that information is needed for error
reporting, I'm thinking there's a good chance it is accessible.
(Just in case you're interested, the purpose of this is to be able to
assemble code segments during the ConTeXt processing into external files
with #line directives ala the C preprocessor. That way if the
subsequent compilation of the external file results in an error, the
error message can refer back to the line of code in the ConTeXt source
file. This is part of the literate programming module that Kevin
Robbins has been describing in another thread.)
Thanks,
Tad
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-07-08 8:27 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-03 14:22 How to Determine the Current File Name and Line Number in the ConTeXt Source? Tad Ashlock
2009-07-03 15:23 ` Hans Hagen
2009-07-06 12:52 ` Taco Hoekwater
-- strict thread matches above, loose matches on Subject: below --
2009-07-07 18:09 Tad Ashlock
2009-07-08 8:27 ` Taco Hoekwater
2009-07-01 11:01 Tad Ashlock
2009-07-01 14:26 ` Hans Hagen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).