From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Jose A. Ortega Ruiz" Subject: Re: [Geiser-users] geiser-xref-callers does not seem to work Date: Tue, 30 Jan 2018 23:55:15 +0100 Message-ID: <87lggf9cto.fsf@imladris> References: <87d13fjecw.fsf@gmail.com> <87shc8qt0p.fsf@igalia.com> <87372r2r0a.fsf@imladris> <87mv0x59n3.fsf@igalia.com> <87d11sblir.fsf@imladris> <87tvv34vjy.fsf@igalia.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:44345) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1egeor-0006vs-HF for guix-devel@gnu.org; Tue, 30 Jan 2018 17:57:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1egeoC-0006CQ-7D for guix-devel@gnu.org; Tue, 30 Jan 2018 17:56:01 -0500 Received: from mail-wr0-x235.google.com ([2a00:1450:400c:c0c::235]:38606) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1egeoB-00069N-Eb for guix-devel@gnu.org; Tue, 30 Jan 2018 17:55:19 -0500 Received: by mail-wr0-x235.google.com with SMTP id t94so1447742wrc.5 for ; Tue, 30 Jan 2018 14:55:18 -0800 (PST) In-Reply-To: <87tvv34vjy.fsf@igalia.com> (Andy Wingo's message of "Tue, 30 Jan 2018 09:09:37 +0100") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Andy Wingo Cc: guix-devel@gnu.org, geiser-users@nongnu.org On Tue, Jan 30 2018, Andy Wingo wrote: > On Mon 29 Jan 2018 18:52, "Jose A. Ortega Ruiz" writes: > >> i've figured out how to find the filename for a procedure, but i'm >> missing what is probably the easier part: give the latter, how do i get >> hold of the module object? > > On the one side there's no 100% reliable way. E.g. some files don't > declare what module they're in, and so if they are loaded (e.g. via > "include") from within some other module, then they inherit the current > module from the caller. > > However there is the very common case in which each file defines a > module -- there, I would actually go about this in the other way. Walk > the module tree and record source file names that map to modules. > However like source-procedures, probably Guile should bake this facility > into (system xref). Anyway here is a procedure that will do it: > > ;; Return hash table mapping filename to list of modules defined in that > ;; file. > (define (compute-source->module-mapping) > (let ((ret (make-hash-table))) > (define (record-module m) > (let ((f (module-filename m))) > (hash-set! ret f (cons m (hash-ref ret f '()))))) > (define (visit-module m) > (record-module m) > (hash-for-each (lambda (k v) (visit-module v)) > (module-submodules m))) > (visit-module (resolve-module '() #f)) > ret)) Thanks, this is working for me! And replacing program-arities was trivial given the new debug utilities. Chris, as a result, xref is working for me too in the latest geiser in git: please give it a try when you can, and thanks for your patience :) Cheers, jao -- Patriotism is a kind of religion; it is the egg from which wars are hatched. -Guy de Maupassant, short story writer and novelist (1850-1893)