【Emacs】completion-preview の設定

ちなみに completion-previewEmacs 30 系に搭載予定.

最新のソースコードはこちらから。

github.com

(require 'completion-preview)

;; Enable Completion Preview mode in code buffers
(add-hook 'prog-mode-hook #'completion-preview-mode)
;; also in text buffers
(add-hook 'text-mode-hook #'completion-preview-mode)
;; also in eshell-buffers
(add-hook 'eshell-mode-hook #'completion-preview-mode)

;; and in \\[shell] and friends
(with-eval-after-load 'comint
  (add-hook 'comint-mode-hook #'completion-preview-mode))

(setq completion-preview-minimum-symbol-length 3)

;; Non-standard commands to that should show the preview:

;; Org mode has a custom `self-insert-command'
(push 'org-self-insert-command completion-preview-commands)
;; Paredit has a custom `delete-backward-char' command
(push 'paredit-backward-delete completion-preview-commands)

;; Bindings that take effect when the preview is shown:

;; Cycle the completion candidate that the preview shows
(keymap-set completion-preview-active-mode-map
            "M-n" #'completion-preview-next-candidate)
(keymap-set completion-preview-active-mode-map
            "M-p" #'completion-preview-prev-candidate)

;; Convenient alternative to C-i after typing one of the above
;; (keymap-set completion-preview-active-mode-map
;;             "M-i" #'completion-preview-insert)

(keymap-set completion-preview-active-mode-map
            "M-i" #'completion-preview-complete)

(keymap-set completion-preview-active-mode-map
            "<remap> <forward-word>" #'completion-preview-insert-word)
(keymap-set completion-preview-active-mode-map
            "<remap> <forward-sexp>" #'completion-preview-insert-sexp)

参考

eshelyaron.com