五月 04, 2008

Read CPAN module source code

有了cperl-perldoc,在Emacs里面看perl文档很方便,但有时候想看看代码,只好切换到命令行下面执行:

$ emacsclient --no-wait `perldoc -l A::Module`

如果使用下面的Emacs Lisp代码,可以省掉切换的麻烦,像使用cperl-perldoc看文档一样,直接在Emacs里面代开源代码文件。

(defun wl-cperl-find-module (module)
  "View source code of CPAN module."
  (interactive
   (list (let* ((default-module (cperl-word-at-point))
                (input (read-string
                        (format "CPAN module%s: "
                                (if (string= default-module "")
                                    ""
                                  (format " (default %s)" default-module))))))
           (if (string= input "")
               (if (string= default-module "")
                   (error "No module given")
                 default-module)
             input))))
  (let ((perldoc-output
         (with-temp-buffer
           (call-process "perldoc" nil t nil "-l" module)
           (buffer-substring-no-properties (point-min) (1- (point-max))))))
    (if (string-match "no documentation found" perldoc-output)
        (message "%s" perldoc-output)
      (find-file-other-window perldoc-output))))

(cperl-define-key (kbd "C-c m") 'wl-cperl-find-module)

0 条评论:

发表评论

指向此文章的链接:

创建链接

<< 主页