2014-03-26 60 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'