diff options
Diffstat (limited to 'lisp/bindings.el')
-rw-r--r-- | lisp/bindings.el | 78 |
1 files changed, 66 insertions, 12 deletions
diff --git a/lisp/bindings.el b/lisp/bindings.el index 2f4bab11cf5..03459448943 100644 --- a/lisp/bindings.el +++ b/lisp/bindings.el @@ -330,22 +330,53 @@ of the menu's data." (defvar mode-line-mode-menu (make-sparse-keymap "Minor Modes") "\ Menu of mode operations in the mode line.") +(defun bindings--menu-item-string (item) + "Return the menu-item string for ITEM, or nil if not a menu-item." + (pcase item + (`(menu-item ,name . ,_) (eval name t)) + (`(,(and (pred stringp) name) . ,_) name))) + +(defun bindings--sort-menu-keymap (map) + "Sort the bindings in MAP in alphabetical order by menu-item string. +The order of bindings in a keymap matters only when it is used as +a menu, so this function is not useful for non-menu keymaps." + (let ((bindings nil) + (prompt (keymap-prompt map))) + (while (keymapp map) + (setq map (map-keymap + (lambda (key item) + ;; FIXME: Handle char-ranges here? + (push (cons key item) bindings)) + map))) + ;; Sort the bindings and make a new keymap from them. + (setq bindings + (sort bindings + (lambda (a b) + (string< (bindings--menu-item-string (cdr-safe a)) + (bindings--menu-item-string (cdr-safe b)))))) + (nconc (make-sparse-keymap prompt) bindings))) + (defvar mode-line-major-mode-keymap (let ((map (make-sparse-keymap))) (bindings--define-key map [mode-line down-mouse-1] `(menu-item "Menu Bar" ignore :filter ,(lambda (_) (mouse-menu-major-mode-map)))) (define-key map [mode-line mouse-2] 'describe-mode) - (define-key map [mode-line down-mouse-3] mode-line-mode-menu) + (bindings--define-key map [mode-line down-mouse-3] + `(menu-item "Minor Modes" ,mode-line-mode-menu + :filter bindings--sort-menu-keymap)) map) "\ Keymap to display on major mode.") (defvar mode-line-minor-mode-keymap - (let ((map (make-sparse-keymap))) + (let ((map (make-sparse-keymap)) + (mode-menu-binding + `(menu-item "Menu Bar" ,mode-line-mode-menu + :filter bindings--sort-menu-keymap))) (define-key map [mode-line down-mouse-1] 'mouse-minor-mode-menu) (define-key map [mode-line mouse-2] 'mode-line-minor-mode-help) - (define-key map [mode-line down-mouse-3] mode-line-mode-menu) - (define-key map [header-line down-mouse-3] mode-line-mode-menu) + (define-key map [mode-line down-mouse-3] mode-menu-binding) + (define-key map [header-line down-mouse-3] mode-menu-binding) map) "\ Keymap to display on minor modes.") @@ -432,7 +463,9 @@ displayed in `mode-line-position', a component of the default (defcustom mode-line-position-line-format '(" L%l") "Format used to display line numbers in the mode line. This is used when `line-number-mode' is switched on. The \"%l\" -format spec will be replaced by the line number." +format spec will be replaced by the line number. + +Also see `mode-line-position-column-line-format'." :type '(list string) :version "28.1" :group 'mode-line) @@ -440,9 +473,10 @@ format spec will be replaced by the line number." (defcustom mode-line-position-column-format '(" C%c") "Format used to display column numbers in the mode line. This is used when `column-number-mode' is switched on. The -\"%c\" format spec will be replaced by the column number, which -is zero-based if `column-number-indicator-zero-based' is non-nil, -and one-based if `column-number-indicator-zero-based' is nil." +\"%c\" format spec is replaced by the zero-based column number, +and \"%C\" is replaced by the one-based column number. + +Also see `mode-line-position-column-line-format'." :type '(list string) :version "28.1" :group 'mode-line) @@ -549,7 +583,7 @@ Major modes that edit things other than ordinary files may change this (put 'mode-line-buffer-identification 'risky-local-variable t) (defvar mode-line-misc-info - '((global-mode-string ("" global-mode-string " "))) + '((global-mode-string ("" global-mode-string))) "Mode line construct for miscellaneous information. By default, this shows the information specified by `global-mode-string'.") (put 'mode-line-misc-info 'risky-local-variable t) @@ -610,7 +644,9 @@ Switch to the most recently selected buffer other than the current one." (previous-buffer))) (defmacro bound-and-true-p (var) - "Return the value of symbol VAR if it is bound, else nil." + "Return the value of symbol VAR if it is bound, else nil. +Note that if `lexical-binding' is in effect, this function isn't +meaningful if it refers to a lexically bound variable." `(and (boundp (quote ,var)) ,var)) ;; Use mode-line-mode-menu for local minor-modes only. @@ -950,6 +986,12 @@ if `inhibit-field-text-motion' is non-nil." ;; Richard said that we should not use C-x <uppercase letter> and I have ;; no idea whereas to bind it. Any suggestion welcome. -stef ;; (define-key ctl-x-map "U" 'undo-only) +(defvar undo-repeat-map + (let ((map (make-sparse-keymap))) + (define-key map "u" 'undo) + map) + "Keymap to repeat undo key sequences `C-x u u'. Used in `repeat-mode'.") +(put 'undo 'repeat-map 'undo-repeat-map) (define-key esc-map "!" 'shell-command) (define-key esc-map "|" 'shell-command-on-region) @@ -1036,6 +1078,17 @@ if `inhibit-field-text-motion' is non-nil." (define-key ctl-x-map "`" 'next-error) +(defvar next-error-repeat-map + (let ((map (make-sparse-keymap))) + (define-key map "n" 'next-error) + (define-key map "\M-n" 'next-error) + (define-key map "p" 'previous-error) + (define-key map "\M-p" 'previous-error) + map) + "Keymap to repeat next-error key sequences. Used in `repeat-mode'.") +(put 'next-error 'repeat-map 'next-error-repeat-map) +(put 'previous-error 'repeat-map 'next-error-repeat-map) + (defvar goto-map (make-sparse-keymap) "Keymap for navigation commands.") (define-key esc-map "g" goto-map) @@ -1194,7 +1247,7 @@ if `inhibit-field-text-motion' is non-nil." ;; (define-key global-map [kp-9] 'function-key-error) ;; (define-key global-map [kp-equal] 'function-key-error) -;; X11R6 distinguishes these keys from the non-kp keys. +;; X11 distinguishes these keys from the non-kp keys. ;; Make them behave like the non-kp keys unless otherwise bound. ;; FIXME: rather than list such mappings for every modifier-combination, ;; we should come up with a way to do it generically, something like @@ -1415,7 +1468,8 @@ if `inhibit-field-text-motion' is non-nil." (defvar ctl-x-x-map (let ((map (make-sparse-keymap))) - (define-key map "g" #'revert-buffer) + (define-key map "f" #'font-lock-update) + (define-key map "g" #'revert-buffer-quick) (define-key map "r" #'rename-buffer) (define-key map "u" #'rename-uniquely) (define-key map "n" #'clone-buffer) |