Emacs中的代码完成键绑定

时间:2010-01-27 20:07:22

标签: emacs elisp

在.el文件中执行 M-x describe-mode 时,我注意到Emacs-Lisp模式实际上完成了代码。但是,lisp-complete-symbol绑定到 M-TAB 。在Windows中,Windows使用此键绑定来切换活动窗口。大多数IDE都使用 C-SPC ,但这也是在Emacs中使用的。代码完成的一个好的,相当常见的密钥绑定是什么?

6 个答案:

答案 0 :(得分:8)

如果您喜欢各种类型的完成,我建议 M - / 并将其绑定到hippie-expand

(global-set-key (kbd "M-/") 'hippie-expand)

它执行各种完成,由变量hippie-expand-try-functions-list控制。在.el文件中,您可以将其设置为首先执行'try-complete-lisp-symbol以获取您上面要求的行为,以及hippie-expand提供的所有其他扩展。

这会为你做到这一点:

(add-hook 'emacs-lisp-mode-hook 'move-lisp-completion-to-front)
(defun move-lisp-completion-to-front ()
  "Adjust hippie-expand-try-functions-list to have lisp completion at the front."
  (make-local-variable 'hippie-expand-try-functions-list)
  (setq hippie-expand-try-functions-list 
        (cons 'try-complete-lisp-symbol
              (delq 'try-complete-lisp-symbol hippie-expand-try-functions-list)))
  (setq hippie-expand-try-functions-list 
        (cons 'try-complete-lisp-symbol-partially
              (delq 'try-complete-lisp-symbol-partially hippie-expand-try-functions-list))))

答案 1 :(得分:7)

正如Trey Jackson所说,hippie-expand是要走的路,但除了将它绑定到 M - / 之外,我还喜欢 TAB 键为我完成所有的完成工作。所以我从我的.emacs文件中的Emacs-Wiki获得了这个:

;;function to implement a smarter TAB (EmacsWiki)
(defun smart-tab ()
  "This smart tab is minibuffer compliant: it acts as usual in
    the minibuffer. Else, if mark is active, indents region. Else if
    point is at the end of a symbol, expands it. Else indents the
    current line."
  (interactive)
  (if (minibufferp)
      (unless (minibuffer-complete)
        (hippie-expand nil))
    (if mark-active
        (indent-region (region-beginning)
                       (region-end))
      (if (looking-at "\\_>")
         (hippie-expand nil)
        (indent-for-tab-command)))))
(global-set-key (kbd "TAB") 'smart-tab)

你可以让嬉皮士扩展设置如下:

;;settings for hippie-expand
(setq hippie-expand-try-functions-list
       '(try-complete-lisp-symbol
         try-complete-lisp-symbol-partially
         try-expand-dabbrev
         try-expand-dabbrev-from-kill
         try-expand-dabbrev-all-buffers
         try-expand-line
         try-complete-file-name-partially
         try-complete-file-name))

答案 2 :(得分:4)

C-M-我;无需定制。

答案 3 :(得分:2)

我用:

(define-key function-key-map [(control tab)] [?\M-\t])

答案 4 :(得分:1)

我使用M-.M-/作为2种完成模式 - hippie-expand和标准emacs。

答案 5 :(得分:0)

将此内容放入.emacs以使Windows让Emacs使用M-TAB

(when (fboundp 'w32-register-hot-key) (w32-register-hot-key [M-tab]))