我已经成为vim用户好几年了。现在我想出于某些原因尝试Emacs。我在Vim中经常使用路径自动完成功能(C-c,C-f)。所以我想知道Emacs中是否有类似的击键?我用谷歌搜索了这个问题,但只找到了这个答案https://superuser.com/questions/67170/how-do-i-complete-file-paths-in-emacs。但是,与提供给我列表候选人的vim不同,Emacs自动完成了第一个候选人。所以,我的问题是如何配置HippieExpand使它为我提供候选人列表而不是自动完成第一个候选人?
答案 0 :(得分:2)
我不确定如何自定义HippieExpand来执行此操作,但您可能需要查看auto-complete package。设置相当容易,并提供完成作为下拉列表。它也是非常可定制的,所以你可以调整它以完全像你喜欢的行为。希望你觉得它有用!
编辑:我刚刚意识到你正在寻找路径完成而不是一般的自动完成。在这种情况下,auto-complete.el可能有点矫枉过正。我仍然建议你看看它,因为它提供了很多额外的实用程序。我第二次看看ido的路径完成。
答案 1 :(得分:2)
这是一个使用hippie-expand的实现,并将ido用于选择菜单。
这使我们my-ido-hippie-expand
(我绑定到C-c e
)的ido
等同于hippie-expand
,并且还可以轻松生成其他目标扩展实用程序使用特定的扩展函数(通常是hippie-expand-try-functions-list
的一些子集),这有助于仅文件名版本。
(defun my-hippie-expand-completions (&optional hippie-expand-function)
"Return the full list of possible completions generated by `hippie-expand'.
The optional argument can be generated with `make-hippie-expand-function'."
(require 'cl)
(let ((this-command 'my-hippie-expand-completions)
(last-command last-command)
(buffer-modified (buffer-modified-p))
(hippie-expand-function (or hippie-expand-function 'hippie-expand)))
(flet ((ding)) ; avoid the (ding) when hippie-expand exhausts its options.
(while (progn
(funcall hippie-expand-function nil)
(setq last-command 'my-hippie-expand-completions)
(not (equal he-num -1)))))
;; Evaluating the completions modifies the buffer, however we will finish
;; up in the same state that we began.
(set-buffer-modified-p buffer-modified)
;; Provide the options in the order in which they are normally generated.
(delete he-search-string (reverse he-tried-table))))
(defmacro my-ido-hippie-expand-with (hippie-expand-function)
"Generate an interactively-callable function that offers ido-based completion
using the specified hippie-expand function."
`(call-interactively
(lambda (&optional selection)
(interactive
(let ((options (my-hippie-expand-completions ,hippie-expand-function)))
(if options
(list (ido-completing-read "Completions: " options)))))
(if selection
(he-substitute-string selection t)
(message "No expansion found")))))
(defun my-ido-hippie-expand ()
"Offer ido-based completion for the word at point."
(interactive)
(my-ido-hippie-expand-with 'hippie-expand))
(global-set-key (kbd "C-c e") 'my-ido-hippie-expand)
这个扩展只是为了完成文件名:
(defun my-ido-hippie-expand-filename ()
"Offer ido-based completion for the filename at point."
(interactive)
(my-ido-hippie-expand-with
(make-hippie-expand-function '(try-complete-file-name))))
(global-set-key (kbd "C-c f") 'my-ido-hippie-expand-filename)
答案 2 :(得分:0)
感兴趣的注意事项:
;; For the real hippie-expand enthusiast: A macro that makes it
;; possible to use many functions like hippie-expand, but with
;; different try-functions-lists.
;; Usage is for example:
;; (fset 'my-complete-file (make-hippie-expand-function
;; '(try-complete-file-name-partially
;; try-complete-file-name)))
;; (fset 'my-complete-line (make-hippie-expand-function
;; '(try-expand-line
;; try-expand-line-all-buffers)))
;;
;;;###autoload
(defmacro make-hippie-expand-function (try-list &optional verbose)
"Construct a function similar to `hippie-expand'.
Make it use the expansion functions in TRY-LIST. An optional second
argument VERBOSE non-nil makes the function verbose."
你可以利用它来生成可能的文件名完成列表。
编辑:实际上,这不会让你比其他问题更进一步。我会把它放在这里,因为这似乎是一个更好的方法。