M-x describe-mode在.el文件中执行a 时,我注意到Emacs-Lisp模式实际上完成了代码.但是,lisp-complete-symbol必然会M-TAB.在Windows中,Windows使用此键绑定来切换活动窗口.大多数IDE都在使用C-SPC,但这也是在Emacs中使用的.代码完成的一个好的,相当常见的键绑定是什么?
如果您喜欢各种类型的完成,我建议M-/并将其绑定到hippie-expand.
(global-set-key (kbd "M-/") 'hippie-expand)
Run Code Online (Sandbox Code Playgroud)
它执行各种完成,由变量控制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))))
Run Code Online (Sandbox Code Playgroud)
正如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)
Run Code Online (Sandbox Code Playgroud)
你可以让嬉皮士扩展设置如下:
;;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))
Run Code Online (Sandbox Code Playgroud)