ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Tad Ashlock <taashlo@cyberdude.com>
To: ntg-context@ntg.nl
Subject: How to Determine the Current File Name and Line Number in the ConTeXt Source?
Date: Wed, 01 Jul 2009 05:01:10 -0600	[thread overview]
Message-ID: <4A4B41F6.2040005@cyberdude.com> (raw)

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
___________________________________________________________________________________


             reply	other threads:[~2009-07-01 11:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-01 11:01 Tad Ashlock [this message]
2009-07-01 14:26 ` Hans Hagen
2009-07-03 14:22 Tad Ashlock
2009-07-03 15:23 ` Hans Hagen
2009-07-06 12:52 ` Taco Hoekwater
2009-07-07 18:09 Tad Ashlock
2009-07-08  8:27 ` Taco Hoekwater

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A4B41F6.2040005@cyberdude.com \
    --to=taashlo@cyberdude.com \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).