Thanks Driven Life

日々是感謝

Emacs Lisp で 変数や関数が定義されているファイルパスを取得するには

  1. 諸事情によりロード済みのライブラリが置いてあるパス(/path/to/hoge.el)を知りたい
  2. せっかくだから、ライブラリだけじゃなくて変数や関数が定義されてる場所も!
  3. そういえば describe-function や describe-variables で表示される help-mode だと飛べる
  4. help-mode 読んでみよう

の結果、help-fns.el に find-lisp-object-file-name という便利関数があった

(find-library-name "url")
"/Users/gongo/.homebrew/Cellar/emacs/24.2/share/emacs/24.2/lisp/url/url.el.gz"

(find-library-name "simple-httpd")
"/Users/gongo/.emacs.d/elpa/simple-httpd-20121224.1121/simple-httpd.el"

(find-lisp-object-file-name 'httpd-status-codes 'defvar)
"/Users/gongo/.emacs.d/elpa/simple-httpd-20121224.1121/simple-httpd.el"

(find-lisp-object-file-name 'deferred:$ 'defun)
"/Users/gongo/.emacs.d/elpa/deferred-20120306.1807/deferred.el"

便利

追記

今起動している Emacs のある場所を知りたいとつぶやいたら

invocation-directory
"/Users/gongo/.homebrew/Cellar/emacs/24.2/Emacs.app/Contents/MacOS/"


invocation-name
"Emacs"

ありがとうございます!!