看看图, 就知道是啥了, 跟 C-h m 有点像, 不同的更精炼的方式.
which-key is a minor mode for Emacs that displays the key bindings following your currently entered incomplete command (a prefix) in a popup. For example, after enabling the minor mode if you enter
C-x and wait for the default of 1 second the minibuffer will expand with all of the available key bindings that follow
C-x (or as many as space allows given your settings). This includes prefixes like
C-x 8 which are shown in a different face. Screenshots of what the popup will look like are included below.
which-key started as a rewrite of guide-key-mode, but the feature sets have diverged to a certain extent.
After setting up MELPA as a repository, use
M-x package-install which-key or your preferred method. You will need to call
which-key-mode to enable the minor mode of course.
Add which-key.el to your
load-path and require. Something like
(add-to-list 'load-path "path/to/which-key.el") (require 'which-key) (which-key-mode)
No further setup is required if you are happy with the default setup. To try other options, there are 3 choices of default configs that are preconfigured (then customize to your liking). The main choice is where you want the which-key buffer to display. Screenshots of the default options are shown in the next sections.
In each case, we show as many key bindings as we can fit in the buffer within the constraints. The constraints are determined by several factors, including your Emacs settings, the size of the current Emacs frame, and the which-key settings, most of which are described below.
By default which-key makes substitutions for text all with the aim of saving space. The most noticeable are the “special keys” like SPC, TAB, RET, etc. This can be turned off (see Other Options), but the default is to truncate these keys to one character and display them using
:inverse-video (flips foreground and background colors). You can see the effect in the screenshots.
There are other substitution abilities included, which are quite flexible (ability to use regexp for example). This makes which-key very customizable. This functionality is targeting spacemacs.
Popup side window on bottom. This is the current default. To restore this setup use
Popup side window on right. For defaults use
Note the defaults are fairly conservative and will tend to not display on narrower frames. If you get a message saying which-key can’t display the keys, try making your frame wider or adjusting the defaults related to the maximum width (see
M-x customize-group which-key).
This is a combination of the previous two choices. It will try to use the right side, but if there is no room it will switch to using the bottom, which is usually easier to fit keys into. This setting can be helpful if the size of the Emacs frame changes frequently, which might be the case if you are using a dynamic/tiling window manager.
Take over the minibuffer. For the recommended configuration use
Note the maximum height of the minibuffer is controlled through the built-in variable
which-key-show-top-levelwill show most key bindings without a prefix. It is most and not all, because many are probably not interesting to most users.
which-key-show-next-pageis the command used for paging.
which-key-undocan be used to undo the last keypress when in the middle of a key sequence.
There are more options than the ones described here. All of the configurable variables are available through
M-x customize-group which-key.
There are three different popup types that which-key can use by default to display the available keys. The variable
which-key-popup-type decides which one is used.
(setq which-key-popup-type 'minibuffer)
Show keys in the minibuffer.
(setq which-key-popup-type 'side-window)
Show keys in a side window. This popup type has further options:
;; location of which-key window. valid values: top, bottom, left, right, ;; or a list of any of the two. If it's a list, which-key will always try ;; the first location first. It will go to the second location if there is ;; not enough room to display any keys in the first location (setq which-key-side-window-location 'bottom) ;; max width of which-key window, when displayed at left or right. ;; valid values: number of columns (integer), or percentage out of current ;; frame's width (float larger than 0 and smaller than 1) (setq which-key-side-window-max-width 0.33) ;; max height of which-key window, when displayed at top or bottom. ;; valid values: number of lines (integer), or percentage out of current ;; frame's height (float larger than 0 and smaller than 1) (setq which-key-side-window-max-height 0.25)
(setq which-key-popup-type 'frame)
Show keys in a popup frame. This popup won’t work very well in a terminal, where only one frame can be shown at any given moment. This popup type has further options:
;; max width of which-key frame: number of columns (an integer) (setq which-key-frame-max-width 60) ;; max height of which-key frame: number of lines (an integer) (setq which-key-frame-max-height 20)
Write your own display functions! This requires you to write three functions,
which-key-custom-hide-popup-function. Refer to the documentation for those variables for more information, but here is a working example (this is the current implementation of side-window bottom).
(setq which-key-popup-type 'custom) (defun which-key-custom-popup-max-dimensions-function (ignore) (cons (which-key-height-or-percentage-to-height which-key-side-window-max-height) (frame-width))) (defun fit-horizonatally () (let ((fit-window-to-buffer-horizontally t)) (fit-window-to-buffer))) (defun which-key-custom-show-popup-function (act-popup-dim) (let* ((alist '((window-width . fit-horizontally) (window-height . fit-window-to-buffer)))) (if (get-buffer-window which-key--buffer) (display-buffer-reuse-window which-key--buffer alist) (display-buffer-in-major-side-window which-key--buffer 'bottom 0 alist)))) (defun which-key-custom-hide-popup-function () (when (buffer-live-p which-key--buffer) (quit-windows-on which-key--buffer)))
原文时间: 2016-04-12 03:18
整理时间: 2016-04-22 04:03
本文由 Hick 整理，转载请保留以上信息;
The articles on this site come from Internet, thanks to all the original authors.
If anything about COPYRIGHT, or LEFT, please contact Emacsist at gmail dot com .