[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Geiser-users] geiser-xref-callers does not seem to work

From: Andy Wingo
Subject: Re: [Geiser-users] geiser-xref-callers does not seem to work
Date: Tue, 30 Jan 2018 09:09:37 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux)

On Mon 29 Jan 2018 18:52, "Jose A. Ortega Ruiz" <address@hidden> 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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]