* tool to display library dependencies?
@ 2004-12-30 15:58 Drew Adams
0 siblings, 0 replies; 4+ messages in thread
From: Drew Adams @ 2004-12-30 15:58 UTC (permalink / raw)
This has probably been asked before, but I couldn't find it.
Is there a tool somewhere that will look at one or more Emacs Lisp libraries
and output a tree or list of its library dependencies? An Emacs command that
does this would be great.
For example: Library A requires B, which requires C and D. I'd like to be
able to determine all of the libraries that A ultimately requires - in this
case B, C, and D. A dependency tree would be even better:
A-B-+-C
|
+-D
I realize that it would be problematic to take autoloads into account, but
just dealing with the explicit `require's would still be useful. And it
would be good if such a tool/command distinguished somehow between hard and
soft (`(require nil t)') `require's.
- Drew
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: tool to display library dependencies?
[not found] <mailman.10066.1104423032.27204.help-gnu-emacs@gnu.org>
@ 2004-12-30 18:59 ` Kevin Rodgers
2004-12-30 19:49 ` Drew Adams
0 siblings, 1 reply; 4+ messages in thread
From: Kevin Rodgers @ 2004-12-30 18:59 UTC (permalink / raw)
Drew Adams wrote:
> This has probably been asked before, but I couldn't find it.
>
> Is there a tool somewhere that will look at one or more Emacs Lisp
libraries
> and output a tree or list of its library dependencies? An Emacs
command that
> does this would be great.
>
> For example: Library A requires B, which requires C and D. I'd like to be
> able to determine all of the libraries that A ultimately requires -
in this
> case B, C, and D. A dependency tree would be even better:
>
> A-B-+-C
> |
> +-D
>
> I realize that it would be problematic to take autoloads into
account, but
> just dealing with the explicit `require's would still be useful. And it
> would be good if such a tool/command distinguished somehow between
hard and
> soft (`(require nil t)') `require's.
,----[ C-h f file-requires RET ]
| file-requires is a compiled Lisp function in `loadhist'.
| (file-requires FILE)
|
| Return the list of features required by FILE.
`----
,----[ C-h f feature-file RET ]
| feature-file is a compiled Lisp function in `loadhist'.
| (feature-file FEATURE)
|
| Return the file name from which a given FEATURE was loaded.
| Actually, return the load argument, if any; this is sometimes the name
of a
| Lisp file without an extension. If the feature came from an
`eval-buffer' on
| a buffer with no associated file, or an `eval-region', return nil.
`----
So:
(require 'loadhist)
(defun file-dependencies (file)
"Return a list of the files `require'd by FILE.
If any of those files themselves `require' another, return it as a list
of it
and its dependencies, and so on (recursively)."
(mapcar (lambda (feature)
(let* ((required-file (feature-file feature))
(required-file-dependencies
(file-dependencies required-file)))
(if required-file-dependencies
(cons required-file required-file-dependencies)
required-file)))
(file-requires file)))
Now (progn (require 'w3m) (file-dependencies "w3m")) returns
("browse-url"
"timezone"
"w3m-hist"
("w3m-e21"
"wid-edit"
("w3m-ccl"
"ccl")
"w3m-fsf"
"w3m-favicon"
"w3m-image")
"w3m-proc"
"w3m-util")
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: tool to display library dependencies?
2004-12-30 18:59 ` tool to display library dependencies? Kevin Rodgers
@ 2004-12-30 19:49 ` Drew Adams
0 siblings, 0 replies; 4+ messages in thread
From: Drew Adams @ 2004-12-30 19:49 UTC (permalink / raw)
Cc: help-gnu-emacs
> Is there a tool somewhere that will look at one or more Emacs Lisp
> libraries and output a tree or list of its library dependencies?
> And it would be good if such a tool/command distinguished somehow
> between hard and soft (`(require nil t)') `require's.
C-h f file-requires
C-h f feature-file
This is great news. I wasn't aware of these functions (or of loadhist.el).
(require 'loadhist)
(defun file-dependencies (file)
"Return a list of the files `require'd by FILE.
If any of those files themselves `require' another, return it as a list
of it and its dependencies, and so on (recursively)."
(mapcar (lambda (feature)
(let* ((required-file (feature-file feature))
(required-file-dependencies
(file-dependencies required-file)))
(if required-file-dependencies
(cons required-file required-file-dependencies)
required-file)))
(file-requires file)))
(progn (require 'w3m) (file-dependencies "w3m"))
returns ("browse-url" "timezone" "w3m-hist" ("w3m-e21" "wid-edit"
("w3m-ccl" "ccl") "w3m-fsf" "w3m-favicon" "w3m-image")
"w3m-proc" "w3m-util")
Thanks, Kevin.
However, there is one hiccup still: there is no distinction between hard and
soft `require's. This in effect relies on all of the `require'd libraries
actually being loaded.
For example, I have a library foo.el that does this: (require 'mwheel nil
t). My library works in Emacs 21 (which has feature mwheel), but also in
Emacs 20 (which does not have feature mwheel) - the soft require succeeds in
Emacs 21 and fails (gracefully) in Emacs 20.
When I try (progn (require 'foo) (file-dependencies "foo")) in Emacs 20 I
get an error from the call to (feature-file mwheel): "mwheel is not a
currently loaded feature".
This is such a _useful_ feature, and it's so close to being generally
usable. I can try myself to hack it up to get around this, but perhaps you
have a suggestion or two (or a fix)?
Thanks,
Drew
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: tool to display library dependencies?
[not found] <mailman.10104.1104437134.27204.help-gnu-emacs@gnu.org>
@ 2004-12-30 20:54 ` Kevin Rodgers
0 siblings, 0 replies; 4+ messages in thread
From: Kevin Rodgers @ 2004-12-30 20:54 UTC (permalink / raw)
Drew Adams wrote:
> When I try (progn (require 'foo) (file-dependencies "foo")) in Emacs 20 I
> get an error from the call to (feature-file mwheel): "mwheel is not a
> currently loaded feature".
>
> This is such a _useful_ feature, and it's so close to being generally
> usable. I can try myself to hack it up to get around this, but
perhaps you
> have a suggestion or two (or a fix)?
Sure, just conditionalize the lambda body:
(if (featurep feature)
(let*
...)
feature)
That will yield a feature symbol instead of a file name string for all
features that were not actually loaded.
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-12-30 20:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.10066.1104423032.27204.help-gnu-emacs@gnu.org>
2004-12-30 18:59 ` tool to display library dependencies? Kevin Rodgers
2004-12-30 19:49 ` Drew Adams
[not found] <mailman.10104.1104437134.27204.help-gnu-emacs@gnu.org>
2004-12-30 20:54 ` Kevin Rodgers
2004-12-30 15:58 Drew Adams
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).