clj-commons / potemkin

some ideas which are almost good
572 stars 53 forks source link

preserve file and line metadata? #1

Closed tomjack closed 11 years ago

tomjack commented 13 years ago

It would be nice for Emacs users for import-fn to preserve file and line metadata, so that M-. jumps straight to the actual definition and avoids cluttering the edit-definition stack. I'm not sure that the metadata really should point to the actual definition over the import-fn call site, but I'm using the following patch for this convenience:

diff --git a/src/potemkin.clj b/src/potemkin.clj
index eb4e307..4ec5a72 100644
--- a/src/potemkin.clj
+++ b/src/potemkin.clj
@@ -18,4 +18,10 @@
         n (:name m)
         arglists (:arglists m)
         doc (:doc m)]
-    (list `def (with-meta n {:doc doc :arglists (list 'quote arglists)}) (eval sym))))
\ No newline at end of file
+    `(do
+       (def ~(with-meta n {:doc doc :arglists (list 'quote arglists)})
+            ~(eval sym))
+       (alter-meta! ~(list 'var n) assoc
+                    :file ~(:file m)
+                    :line ~(:line m))
+       ~(list 'var n))))
ztellman commented 13 years ago

I need to think about this a little more, but I suspect that there's not really a "correct" way to do this, and yours is more useful. If I can't come up with a good reason not to in a day or so, I'll integrate your change.

ztellman commented 13 years ago

Oh, wow. Totally forgot about this. I need to also fix Potemkin to work with 1.3.0, I'll add this in the process.

ztellman commented 11 years ago

This has been fixed since forever.