public inbox for guile-emacs@sourceware.org
 help / color / mirror / Atom feed
* scheme-find-definition
@ 2000-05-09  3:23 Kalle Olavi Niemitalo
  2000-05-09  4:03 ` scheme-find-definition Keisuke Nishida
  0 siblings, 1 reply; 4+ messages in thread
From: Kalle Olavi Niemitalo @ 2000-05-09  3:23 UTC (permalink / raw)
  To: guile-emacs

Here's a command which finds the source location of a Scheme
procedure, if the reader saved it.  (read-enable 'positions)
I didn't commit this to CVS because Keisuke is rewriting the
Scheme files.  Will that take long?

(import-lisp-function find-file)
(import-lisp-function goto-line)
(import-lisp-function move-to-column)

(define (find-filename-property tree)
  "Return a part of TREE which has a `filename' source-property.
Return #f if not found."
  (and (pair? tree)
       (or (and (source-property tree 'filename) tree)
	   (find-filename-property (car tree))
	   (find-filename-property (cdr tree)))))

(define-command (scheme-find-procedure proc)
  "Go to the definition of Scheme procedure PROC."
  (interactive "SFind procedure: ")
  ;; Hack for converting interactively entered symbols to procedures.
  ;; This might go away, don't use this from programs.
  (if (symbol? proc) (set! proc (eval proc)))
  (let ((part (cond ((procedure-with-setter? proc)
		     (or (find-filename-property (procedure-source (procedure proc)))
			   (find-filename-property (procedure-source (setter proc)))))
		    ((procedure? proc)
		     (find-filename-property (procedure-source proc))))))
    (or part (error "Can't find definition of " proc))
    (find-file (source-property part 'filename))
    (and=> (source-property part 'line)
	   (lambda (line) (goto-line (+ line 1))))
    (and=> (source-property part 'column) move-to-column)))

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: scheme-find-definition
  2000-05-09  3:23 scheme-find-definition Kalle Olavi Niemitalo
@ 2000-05-09  4:03 ` Keisuke Nishida
  2000-05-09 22:16   ` scheme-find-definition Kalle Olavi Niemitalo
  0 siblings, 1 reply; 4+ messages in thread
From: Keisuke Nishida @ 2000-05-09  4:03 UTC (permalink / raw)
  To: guile-emacs

Kalle Olavi Niemitalo <tosi@ees2.oulu.fi> writes:

> Here's a command which finds the source location of a Scheme
> procedure, if the reader saved it.  (read-enable 'positions)
> I didn't commit this to CVS because Keisuke is rewriting the
> Scheme files.  Will that take long?

Great!  I'll be working on some more low level stuff for a while,
so feel free to commit it.  I'm writing new modules (emacs base),
(emacs class), and (emacs generic), and after this is done, I'll
rewrite (emacs guile).

-- Kei

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: scheme-find-definition
  2000-05-09  4:03 ` scheme-find-definition Keisuke Nishida
@ 2000-05-09 22:16   ` Kalle Olavi Niemitalo
  2000-05-09 23:46     ` scheme-find-definition Keisuke Nishida
  0 siblings, 1 reply; 4+ messages in thread
From: Kalle Olavi Niemitalo @ 2000-05-09 22:16 UTC (permalink / raw)
  To: guile-emacs

Keisuke Nishida <kxn30@po.cwru.edu> writes:

> Great!  I'll be working on some more low level stuff for a while,
> so feel free to commit it.

Actually, I'm not satisfied with this implementation and won't
commit it.  It requires the reader to save source positions,
which might be expensive.  It doesn't work well with macros which
define procedures.  It can't find non-procedure variables.  It
goes out of sync if the source file is changed.  And it can't
find anything evaluated with M-C-x.

I think it would be better to make `define' save the source
location in the symbol.  Or if all variables are defined in
modules, scheme-find-definition could just 1. find from which
module the variable was imported, 2. locate the module's source
in %load-path, 3. load it in a buffer and 4. find the variable's
definition with a textual search.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: scheme-find-definition
  2000-05-09 22:16   ` scheme-find-definition Kalle Olavi Niemitalo
@ 2000-05-09 23:46     ` Keisuke Nishida
  0 siblings, 0 replies; 4+ messages in thread
From: Keisuke Nishida @ 2000-05-09 23:46 UTC (permalink / raw)
  To: guile-emacs

Kalle Olavi Niemitalo <tosi@ees2.oulu.fi> writes:

> I think it would be better to make `define' save the source
> location in the symbol.  Or if all variables are defined in
> modules, scheme-find-definition could just 1. find from which
> module the variable was imported, 2. locate the module's source
> in %load-path, 3. load it in a buffer and 4. find the variable's
> definition with a textual search.

I think combining the source property and the textual search you
write may be enough.  Only when no source property exists or it is
not correct, we can search the module.  If a module stores its file
location as a property, we can use it.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2000-05-09 23:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-09  3:23 scheme-find-definition Kalle Olavi Niemitalo
2000-05-09  4:03 ` scheme-find-definition Keisuke Nishida
2000-05-09 22:16   ` scheme-find-definition Kalle Olavi Niemitalo
2000-05-09 23:46     ` scheme-find-definition Keisuke Nishida

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).