2014-03-26 63 views
3

我在哪里可以找到所有Emacs的elisp脚本?我不是说脚本用户自己开发或安装的,但常用的elisp脚本已经存在。emacs中的Lisp位置

例如,

如果我有像describe-charinsert-file一个功能,我怎么能找到该文件包含这些功能呢?

+2

'Mx find-function-other-window'和'Mx find-variable-other-window'。我用'(global-set-key(kbd“Ch F”)'find-function-other-window)'和'(global-set-key(kbd“Ch V”)'find-variable-other -window)'我的模式行设置为显示打开缓冲区中显示的文件的路径。一旦文件被打开,你也可以使用'M-x describe-variable RET buffer-file-name',这会给你完整的路径。 – lawlist

+0

当然'C-h F'有一个相当有用的默认绑定,所以我建议选择一个未使用的绑定。 'C-h C-f'是我的选择;仍然不是保留绑定,但它目前默认不使用。 – phils

+5

请注意,.el可以被卸载。例如在debian中,您需要安装emacs23-el或emacs24-el软件包。如果你不这样做,那么只有elc(编译后的lisp文件)可用。 –

回答

3

Ctrl-h f会告诉函数的解释以及它包含在哪里。

如果你想有一个函数来完成这个程序自动,这里有一个草案:

(defun my-find-lisp-object-file-name (function) 
    "Display the lisp file name of FUNCTION (a symbol)." 
    (interactive 
    (let ((fn (function-called-at-point)) 
    (enable-recursive-minibuffers t) 
    val) 
    (setq val (completing-read (if fn 
        (format "Describe function (default %s): " fn) 
        "Describe function: ") 
       obarray 'fboundp t nil nil 
       (and fn (symbol-name fn)))) 
    (list (if (equal val "") 
      fn (intern val))))) 
    (if (null function) 
     (message "You didn't specify a function") 
    (setq object-file-name (find-lisp-object-file-name function (symbol-function function))) 
    (if (eq object-file-name 'C-source) 
     (message "%s is in %s" function "C source code") 
     (setq buff (find-function-search-for-symbol function nil object-file-name)) 
     (setq buf-name (buffer-name(car buff))) 
     (setq buf-pos (cdr buff)) 
     (switch-to-buffer (car buff)) 
     (message "%s is in %s(%s, %d)" function object-file-name buf-name buf-pos)))) 
+0

是的,它描述了该功能的功能,但不是它在哪里。我想知道包含* .el文件的位置。 –

+1

@PierreB我不确定你想知道什么,但是当你得到一个函数的文档,比如'describe-char'时,你可以在'* Help *'缓冲区中获得'.el'文件的链接,并获取'.el'文件的位置。例如'/ usr/local/share/emacs/24.3/lisp/descr-text.el.gz'中的'descr-text.el'。不是吗? – songyuanyao

+1

也就是说'* Help *'缓冲区中显示的库名称与定义所描述功能的源文件链接;所以你可以按照链接(作为调用'find-function'的替代方法)。 – phils

2

我想M-x locate-library RET <libname> RET可能是一个答案寿它需要的库名,而不是函数名。否则,M-x find-function-other-window不会告诉你文件在哪里,而是打开文件,之后你可以使用M-x pwd来知道你在哪里。

还有一件事:您可以通过C-h v load-path RET来查看Emacs用来查找其库的目录,以便您了解所有捆绑的Elisp文件所在的位置。

1

初始草稿(2014年3月25日):初稿。

编辑(2014年3月26日):增加了global-set-key。为了从按钮文本属性列表中完全提取文件名的路径,在最终消息中添加了一个car。为初始和最终消息添加了一些彩色化。在函数结尾添加返回光标到缓冲区的开始位置。增加了find-variable-other-windowfind-function-other-window的选项。添加了条件,以便在没有文件名时不会生成消息。


这里是我掀起了一个有趣的小功能 - 它会显示一个文件路径的消息如果*.el文件显示在*Help*缓冲。


(global-set-key (kbd "C-h z") 'lawlist-describe-find-function-variable) 

(defun lawlist-describe-find-function-variable() 
"Describe or find a function/variable. Displays the path of filename." 
(interactive) 
    (message (concat 
    (propertize "Describe" 'face 'font-lock-keyword-face) 
    " [" 
    (propertize "f" 'face 'font-lock-warning-face) 
    "]unction/[" 
    (propertize "v" 'face 'font-lock-warning-face) 
    "]ariable | " 
    (propertize "Find" 'face 'font-lock-keyword-face) 
    " [" 
    (propertize "F" 'face 'font-lock-warning-face) 
    "]unction/[" 
    (propertize "V" 'face 'font-lock-warning-face) 
    "]ariable")) 
    (let* (
     (select-f-or-v (read-char-exclusive)) 
     function 
     variable) 
    (cond 
     ((eq select-f-or-v ?f) 
     (setq function (read (read-string "Please enter a function name: "))) 
     (describe-function function) 
     (select-window (get-buffer-window "*Help*"))) 
     ((eq select-f-or-v ?v) 
     (setq variable (read (read-string "Please enter a variable name: "))) 
     (describe-variable variable) 
     (select-window (get-buffer-window "*Help*"))) 
     ((eq select-f-or-v ?F) 
     (setq function (read (read-string "Please enter a function name: "))) 
     (find-function-other-window function) 
     (when buffer-file-name 
      (message (propertize buffer-file-name 'face 'font-lock-warning-face)))) 
     ((eq select-f-or-v ?V) 
     (setq variable (read (read-string "Please enter a variable name: "))) 
     (find-variable-other-window variable) 
     (when buffer-file-name 
      (message (propertize buffer-file-name 'face 'font-lock-warning-face)))) 
     (t 
     (message "Thanks and come again!"))) 
    (when (and 
     (equal (buffer-name) "*Help*") 
     (save-excursion 
      (goto-char (point-max)) 
      (re-search-backward "\\(`*[.]el'\\)" nil t))) 
     (goto-char (point-max)) 
     (re-search-backward "\\(`*[.]el'\\)" nil t) 
     (message 
     (propertize 
      (car (cdr (car (nthcdr 1 (text-properties-at (point)))))) 
      'face 'font-lock-warning-face)) 
     (goto-char (point-min))))) 
0

如果使用lispy辅助模式:

  1. 您可以通过定位点 该函数的开括号打开当前函数的定义和按F
  2. 您可以通过标记它来打开当前变量的定义,并按F
  3. 你可以在当前目录中找到与g的所有定义。 您将获得所有Elisp文件中所有标签的完成接口helm。 每行将在第一列中有标记,在第二列中有文件。 我安装的基础Elisp目录有19838个标签,并且完成速度足够快。

  4. 您可以在当前目录及其子目录 与lispy-goto-recursive中找到所有的定义。需要几分钟时间才能完成界面上的 。但它允许交互式搜索 全部 Emacs源文件 - 这是89675标签。 示例搜索:有55个顶级标签包含insert-file传播 约20个文件。 其中大部分都是功能,但顶级标签(define-key ctl-x-map "i" 'insert-file) 也是匹配的,无需打开文件即可查看。

0

你可以抓住the source of Emacs(如果你安装了Emacs,你可能有.elc文件 - 这是编译的elisp文件)和搜索功能,如果你在Unix类的系统,您可以使用ackfind/grep所有lisp文件都在lisp目录中

cd Emacs-24.4/lisp 
ack 'defun some-function' 
find . -name '*.el' | xargs grep 'defun some-function'