From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] Add inspection command "source (, src)" which shows Scheme code of loaded module Date: Sun, 31 Mar 2013 23:54:07 -0400 Message-ID: <874nfq52jk.fsf@tines.lan> References: <1364651860.2730.71.camel@Renee-desktop.suse> <87zjxk7fjy.fsf@tines.lan> <1364734048.2730.97.camel@Renee-desktop.suse> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1364788476 10491 80.91.229.3 (1 Apr 2013 03:54:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 1 Apr 2013 03:54:36 +0000 (UTC) Cc: guile-devel@gnu.org To: Daniel Hartwig Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Apr 01 05:55:04 2013 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UMVpn-0006tl-VJ for guile-devel@m.gmane.org; Mon, 01 Apr 2013 05:55:04 +0200 Original-Received: from localhost ([::1]:32823 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMVpO-0003WS-RC for guile-devel@m.gmane.org; Sun, 31 Mar 2013 23:54:38 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:50690) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMVpL-0003WN-Pz for guile-devel@gnu.org; Sun, 31 Mar 2013 23:54:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UMVpG-000609-0D for guile-devel@gnu.org; Sun, 31 Mar 2013 23:54:35 -0400 Original-Received: from world.peace.net ([96.39.62.75]:56530) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMVpF-000602-Pn for guile-devel@gnu.org; Sun, 31 Mar 2013 23:54:29 -0400 Original-Received: from 209-6-91-212.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com ([209.6.91.212] helo=tines.lan) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1UMVp7-000250-H4; Sun, 31 Mar 2013 23:54:22 -0400 In-Reply-To: (Daniel Hartwig's message of "Mon, 1 Apr 2013 08:42:09 +0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 96.39.62.75 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:16078 Archived-At: Daniel Hartwig writes: > On 31 March 2013 20:47, Nala Ginrut 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 =E2=80=98read=E2=80=99 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)))) > =E2=80=A6 > > 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