日記はScrapboxに移動しました。

EmacsでPerlライブラリのソースファイルを開く

デバッグしてる時などに、CPANからインストールしたモジュールを直接いじりたくなったりすることがあるので、以下のコマンドで開けるようにした。

(put 'perl-module-thing 'end-op
(lambda ()
(re-search-forward "\\=[a-zA-Z][a-zA-Z0-9_:]*" nil t)))
(put 'perl-module-thing 'beginning-op
(lambda ()
(if (re-search-backward "[^a-zA-Z0-9_:]" nil t)
(forward-char)
(goto-char (point-min)))))
(defun find-perl-module-file ()
(interactive)
(let ((module (thing-at-point 'perl-module-thing))
(file ""))
(when (string= module "")
(setq module (read-string "Module Name: ")))
(setq file (replace-regexp-in-string "\n+$" ""
(shell-command-to-string (format "perldoc -l %s" module))))
(if (string-match "^No documentation" file)
(error (format "module not found: %s" module))
(find-file file))))

追記

id:dankogaiさんのご指摘を受けて、ちょっと書き直しました。

4 comments

  1. perldoc -l Foo:Bar
    を使うようにすれば Foo/Bar.pm を作らなくても直にパスがわかりまっせ
    Dan the Perl Monger

  2. おー、そうですね!!1 ていうかいつもは普通にそうやってるのに、すっかり忘れてました……。

  3. ありそうだとは思っていました><。重くていろいろ外してたんだけど、マシン新しくなったし、再挑戦してみるか……。

Leave a Reply

Your email address will not be published. Required fields are marked *