From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andy Wingo Subject: Re: geiser-xref-callers does not seem to work Date: Tue, 30 Jan 2018 09:09:37 +0100 Message-ID: <87tvv34vjy.fsf@igalia.com> References: <87d13fjecw.fsf@gmail.com> <87shc8qt0p.fsf@igalia.com> <87372r2r0a.fsf@imladris> <87mv0x59n3.fsf@igalia.com> <87d11sblir.fsf@imladris> Mime-Version: 1.0 Content-Type: text/plain Return-path: In-Reply-To: <87d11sblir.fsf@imladris> (Jose A. Ortega Ruiz's message of "Mon, 29 Jan 2018 18:52:12 +0100") List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: geiser-users-bounces+glsg-geiser-users=m.gmane.org-qX2TKyscuCcdnm+yROfE0A@public.gmane.org Sender: "geiser-users" To: "Jose A. Ortega Ruiz" Cc: guix-devel-mXXj517/zsQ@public.gmane.org, geiser-users-qX2TKyscuCcdnm+yROfE0A@public.gmane.org List-Id: guix-devel.gnu.org 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)) Cheers, Andy