unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: Daniel Hartwig <mandyke@gmail.com>
Cc: guile-devel@gnu.org
Subject: Re: [PATCH] Add inspection command "source (, src)" which shows Scheme code of loaded module
Date: Sun, 31 Mar 2013 23:54:07 -0400	[thread overview]
Message-ID: <874nfq52jk.fsf@tines.lan> (raw)
In-Reply-To: <CAN3veRedE2xd1DV_aAEMFyZMWzDgHMOw1iOen42QJfs6rxnAfQ@mail.gmail.com> (Daniel Hartwig's message of "Mon, 1 Apr 2013 08:42:09 +0800")

Daniel Hartwig <mandyke@gmail.com> writes:

> On 31 March 2013 20:47, Nala Ginrut <nalaginrut@gmail.com> wrote:
>> On Sat, 2013-03-30 at 17:17 -0400, Mark H Weaver wrote:
>>> Also, as we discussed on IRC, it would be better to show the original
>>> characters in the file instead of the sexp representation.  I want to
>>> see the comments.  I want to see the programmer-chosen indentation.  If
>>> they chose to use curly-infix for some expressions, I want to see that.
>>> More generally, I want to see the presentation that the programmer
>>> thought was most readable, i.e. the *source* code.
>>>
>>
>> For these purposes above, I think there should be a modified 'read' to
>> read the code from source file with comments.
>>
>
> There are other transformations that occur as Mark points out.  It is
> far better to just return the unmodified source from the file.  As
> discussed, the source file, column, line information gives you the
> start, and ‘read’ can be used to locate the end:
>
>  (let ((start (begin
>                 (skip-lines fp (source:line src))
>                 (seek fp (source:column src) SEEK_CUR)
>                 (ftell fp)))
>        (end (begin
>               (read fp)
>               (ftell fp))))
>    …
>
> these two points are enough information to obtain the unmodified
> source from the file.

This is enough to get the original characters, but then there's the
other problem I mentioned: reader directives such as #!curly-infix
earlier in the file.

For this reason, I think we need to use 'read' from the beginning of the
file, and look at the source properties of the returned datums to find
the right top-level datum.  In most cases, a top-level datum is what is
desired, but in some cases not.  In general, you will need to traverse
the sublists of a top-level datum to find the right one.

     Good luck!
        Mark



  reply	other threads:[~2013-04-01  3:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-30 13:57 [PATCH] Add inspection command "source (,src)" which shows Scheme code of loaded module Nala Ginrut
2013-03-30 21:17 ` [PATCH] Add inspection command "source (, src)" " Mark H Weaver
2013-03-31  0:33   ` Daniel Hartwig
2013-03-31 12:47   ` [PATCH] Add inspection command "source (,src)" " Nala Ginrut
2013-04-01  0:42     ` [PATCH] Add inspection command "source (, src)" " Daniel Hartwig
2013-04-01  3:54       ` Mark H Weaver [this message]
2013-04-01  4:22         ` Daniel Hartwig
2013-04-01 19:12   ` Andy Wingo
2013-04-23  7:26     ` Show source code from .debug_info section (Was Re: [PATCH] Add inspection command "source (, src)" which shows Scheme code of loaded module) Nala Ginrut

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

  List information: https://www.gnu.org/software/guile/

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

  git send-email \
    --in-reply-to=874nfq52jk.fsf@tines.lan \
    --to=mhw@netris.org \
    --cc=guile-devel@gnu.org \
    --cc=mandyke@gmail.com \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).