shell-command-to-string
昨日作ったLispで困っていたのが、実行した外部コマンドの出力を変数に入れる部分です。
結局*perldoc*というバッファを経由したのですが、shell-command-to-stringというfunctionがあることが通りすがりさんの改良版を見ていて気づきました。
M-x describe-functionとM-x describe-key, M-x describe-bindings以外に、こんな関数ないかなぁとかって調べる方法を確立できていないのが問題だなぁ。
通りすがりさん提供版はモジュールが存在しないばあいのエラー処理や、モジュール文字列の範囲判定などが改善されているようです。
(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 cperl-mode-find-module ()
(interactive)
(let* ((module (thing-at-point ’perl-module-thing))
(perldoc-output (shell-command-to-string
(concat ”perldoc -lm ” module)))
(module-file (replace-regexp-in-string ”?n.*” ”” perldoc-output)))
(if (string= module-file (concat ”No module found for ?”” module ”?”.”))
(message ”%s” module-file)
(find-file module-file))))