1

我想自动生成一个 HTML 文档,其中包含一个 Perl 文件的文档。要构建它,我需要一个列表函数,包含在文件中。每个函数都有格式“^sub name”。是否有任何函数可以获取所有函数名称?或者怎么写?

4

2 回答 2

2

Note that extracting all the function names (together with their location in the buffer) is already done by imenu. So you may prefer to use that. Just call imenu--make-index-alist and then look at the result in imenu--index-alist.

于 2012-10-21T15:11:22.270 回答
2

You can use elisp search functions:

(defun find-perl-sub ()
  (let ((subs))
    (with-current-buffer "my-perl-file.pl"
      (goto-char (point-min))
      (while (re-search-forward "^[[:blank:]]*sub[[:blank:]]+\\([a-zA-Z0-9_]+\\)" nil t)
        (push (match-string-no-properties 1) subs)))
    subs
    ))
于 2012-10-21T11:20:01.850 回答