diff options
Diffstat (limited to 'lisp/bindings.el')
-rw-r--r-- | lisp/bindings.el | 275 |
1 files changed, 144 insertions, 131 deletions
diff --git a/lisp/bindings.el b/lisp/bindings.el index 5eb8e629124..2e321282742 100644 --- a/lisp/bindings.el +++ b/lisp/bindings.el @@ -1,7 +1,6 @@ ;;; bindings.el --- define standard key bindings and some variables -*- lexical-binding: t; -*- -;; Copyright (C) 1985-1987, 1992-1996, 1999-2022 Free Software -;; Foundation, Inc. +;; Copyright (C) 1985-2022 Free Software Foundation, Inc. ;; Maintainer: emacs-devel@gnu.org ;; Keywords: internal @@ -231,6 +230,7 @@ mnemonics of the following coding systems: (:propertize ("" (:eval (if (frame-parameter nil 'client) "@" ""))) help-echo ,(purecopy "emacsclient frame"))) "Mode line construct for identifying emacsclient frames.") +;; Autoload if this file no longer dumped. ;;;###autoload (put 'mode-line-client 'risky-local-variable t) @@ -288,7 +288,7 @@ mnemonics of the following coding systems: Value is used for `mode-line-frame-identification', which see." (if (or (null window-system) (eq window-system 'pc)) - "-%F " + " %F " " ")) ;; We need to defer the call to mode-line-frame-control to the time @@ -458,8 +458,8 @@ displayed in `mode-line-position', a component of the default (const :tag "\"%q\": Offsets of both top and bottom of window" (6 "%q"))) :version "26.1" + :risky t :group 'mode-line) -(put 'mode-line-percent-position 'risky-local-variable t) (defcustom mode-line-position-line-format '(" L%l") "Format used to display line numbers in the mode line. @@ -501,8 +501,9 @@ mouse-1: Display Line and Column Mode Menu")) (defvar mode-line-position `((:propertize - mode-line-percent-position + ("" mode-line-percent-position) local-map ,mode-line-column-line-number-mode-map + display (min-width (5.0)) mouse-face mode-line-highlight ;; XXX needs better description help-echo "Window Scroll Percentage @@ -517,30 +518,35 @@ mouse-1: Display Line and Column Mode Menu") mouse-1: Display Line and Column Mode Menu"))) (line-number-mode (column-number-mode - (column-number-indicator-zero-based - (10 - (:propertize - mode-line-position-column-line-format - ,@mode-line-position--column-line-properties)) - (10 - (:propertize - (:eval (string-replace - "%c" "%C" (car mode-line-position-column-line-format))) - ,@mode-line-position--column-line-properties))) - (6 + (column-number-indicator-zero-based + (10 + (:propertize + mode-line-position-column-line-format + display (min-width (10.0)) + ,@mode-line-position--column-line-properties)) + (10 (:propertize - mode-line-position-line-format + (:eval (string-replace + "%c" "%C" (car mode-line-position-column-line-format))) + display (min-width (10.0)) ,@mode-line-position--column-line-properties))) + (6 + (:propertize + mode-line-position-line-format + display (min-width (6.0)) + ,@mode-line-position--column-line-properties))) (column-number-mode (column-number-indicator-zero-based (6 (:propertize mode-line-position-column-format + display (min-width (6.0)) ,@mode-line-position--column-line-properties)) (6 (:propertize (:eval (string-replace "%c" "%C" (car mode-line-position-column-format))) + display (min-width (6.0)) ,@mode-line-position--column-line-properties)))))) "Mode line construct for displaying the position in the buffer. Normally displays the buffer percentage and, optionally, the @@ -597,10 +603,14 @@ By default, this shows the information specified by `global-mode-string'.") (let ((standard-mode-line-format (list "%e" 'mode-line-front-space - 'mode-line-mule-info - 'mode-line-client - 'mode-line-modified - 'mode-line-remote + (list + :propertize + (list "" + 'mode-line-mule-info + 'mode-line-client + 'mode-line-modified + 'mode-line-remote) + 'display '(min-width (5.0))) 'mode-line-frame-identification 'mode-line-buffer-identification " " @@ -644,6 +654,18 @@ By default, this shows the information specified by `global-mode-string'.") (with-selected-window (posn-window (event-start event)) (previous-buffer))) +(defun mode-line-window-selected-p () + "Return non-nil if we're updating the mode line for the selected window. +This function is meant to be called in `:eval' mode line +constructs to allow altering the look of the mode line depending +on whether the mode line belongs to the currently selected window +or not." + (let ((window (selected-window))) + (or (eq window (old-selected-window)) + (and (minibuffer-window-active-p (minibuffer-window)) + (with-selected-window (minibuffer-window) + (eq window (minibuffer-selected-window))))))) + (defmacro bound-and-true-p (var) "Return the value of symbol VAR if it is bound, else nil. Note that if `lexical-binding' is in effect, this function isn't @@ -944,14 +966,13 @@ if `inhibit-field-text-motion' is non-nil." (backward-word n) (forward-word n))) -(defvar narrow-map (make-sparse-keymap) - "Keymap for narrowing commands.") +(defvar-keymap narrow-map + :doc "Keymap for narrowing commands." + "n" #'narrow-to-region + "w" #'widen + "g" #'goto-line-relative) (define-key ctl-x-map "n" narrow-map) -(define-key narrow-map "n" 'narrow-to-region) -(define-key narrow-map "w" 'widen) -(define-key narrow-map "g" 'goto-line-relative) - ;; Quitting (define-key global-map "\e\e\e" 'keyboard-escape-quit) (define-key global-map "\C-g" 'keyboard-quit) @@ -968,7 +989,7 @@ if `inhibit-field-text-motion' is non-nil." (define-key esc-map "\\" 'delete-horizontal-space) (define-key esc-map "m" 'back-to-indentation) (define-key ctl-x-map "\C-o" 'delete-blank-lines) -(define-key esc-map " " 'just-one-space) +(define-key esc-map " " 'cycle-spacing) (define-key esc-map "z" 'zap-to-char) (define-key esc-map "=" 'count-words-region) (define-key ctl-x-map "=" 'what-cursor-position) @@ -987,11 +1008,9 @@ 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'.") +(defvar-keymap undo-repeat-map + :doc "Keymap to repeat undo key sequences \\`C-x u u'. Used in `repeat-mode'." + "u" #'undo) (put 'undo 'repeat-map 'undo-repeat-map) (define-key global-map '[(control ??)] 'undo-redo) @@ -1062,8 +1081,6 @@ if `inhibit-field-text-motion' is non-nil." (define-key global-map "\C-y" 'yank) (define-key esc-map "y" 'yank-pop) -;; (define-key ctl-x-map "a" 'append-to-buffer) - (define-key global-map "\C-@" 'set-mark-command) ;; Many people are used to typing C-SPC and getting C-@. (define-key global-map [?\C- ] 'set-mark-command) @@ -1082,43 +1099,41 @@ 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'.") +(defvar-keymap next-error-repeat-map + :doc "Keymap to repeat `next-error' key sequences. Used in `repeat-mode'." + "n" #'next-error + "M-n" #'next-error + "p" #'previous-error + "M-p" #'previous-error) (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.") +(defvar-keymap goto-map + :doc "Keymap for navigation commands." + "c" #'goto-char + "g" #'goto-line + "M-g" #'goto-line + "n" #'next-error + "M-n" #'next-error + "p" #'previous-error + "M-p" #'previous-error + "TAB" #'move-to-column + "i" #'imenu) (define-key esc-map "g" goto-map) -(define-key goto-map "c" 'goto-char) -(define-key goto-map "g" 'goto-line) -(define-key goto-map "\M-g" 'goto-line) -(define-key goto-map "n" 'next-error) -(define-key goto-map "\M-n" 'next-error) -(define-key goto-map "p" 'previous-error) -(define-key goto-map "\M-p" 'previous-error) -(define-key goto-map "\t" 'move-to-column) - -(defvar search-map (make-sparse-keymap) - "Keymap for search related commands.") +(defvar-keymap search-map + :doc "Keymap for search related commands." + "o" #'occur + "M-w" #'eww-search-words + "h r" #'highlight-regexp + "h p" #'highlight-phrase + "h l" #'highlight-lines-matching-regexp + "h ." #'highlight-symbol-at-point + "h u" #'unhighlight-regexp + "h f" #'hi-lock-find-patterns + "h w" #'hi-lock-write-interactive-patterns) (define-key esc-map "s" search-map) -(define-key search-map "o" 'occur) -(define-key search-map "\M-w" 'eww-search-words) -(define-key search-map "hr" 'highlight-regexp) -(define-key search-map "hp" 'highlight-phrase) -(define-key search-map "hl" 'highlight-lines-matching-regexp) -(define-key search-map "h." 'highlight-symbol-at-point) -(define-key search-map "hu" 'unhighlight-regexp) -(define-key search-map "hf" 'hi-lock-find-patterns) -(define-key search-map "hw" 'hi-lock-write-interactive-patterns) (put 'highlight-regexp :advertised-binding [?\M-s ?h ?r]) (put 'highlight-phrase :advertised-binding [?\M-s ?h ?p]) (put 'highlight-lines-matching-regexp :advertised-binding [?\M-s ?h ?l]) @@ -1138,7 +1153,9 @@ if `inhibit-field-text-motion' is non-nil." ;(define-key global-map [delete] 'backward-delete-char) ;; natural bindings for terminal keycaps --- defined in X keysym order -(define-key global-map [Scroll_Lock] 'scroll-lock-mode) +(define-key global-map + (if (eq system-type 'windows-nt) [scroll] [Scroll_Lock]) + #'scroll-lock-mode) (define-key global-map [C-S-backspace] 'kill-whole-line) (define-key global-map [home] 'move-beginning-of-line) (define-key global-map [C-home] 'beginning-of-buffer) @@ -1251,6 +1268,8 @@ 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) +(define-key global-map [touch-end] 'ignore) + ;; 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, @@ -1312,7 +1331,15 @@ if `inhibit-field-text-motion' is non-nil." ;; can use S-tab instead to access that binding. (define-key function-key-map [S-tab] [backtab]) -(define-key global-map [mouse-movement] 'ignore) +(defun ignore-preserving-kill-region (&rest _) + "Like `ignore', but don't overwrite `last-event' if it's `kill-region'." + (declare (completion ignore)) + (interactive) + (when (eq last-command 'kill-region) + (setq this-command 'kill-region)) + nil) + +(define-key global-map [mouse-movement] #'ignore-preserving-kill-region) (define-key global-map "\C-t" 'transpose-chars) (define-key esc-map "t" 'transpose-words) @@ -1340,7 +1367,7 @@ if `inhibit-field-text-motion' is non-nil." (defalias 'mode-specific-command-prefix (make-sparse-keymap)) (defvar mode-specific-map (symbol-function 'mode-specific-command-prefix) - "Keymap for characters following C-c.") + "Keymap for characters following \\`C-c'.") (define-key global-map "\C-c" 'mode-specific-command-prefix) (global-set-key [M-right] 'right-word) @@ -1376,10 +1403,8 @@ if `inhibit-field-text-motion' is non-nil." (define-key esc-map [?\C-\ ] 'mark-sexp) (define-key esc-map "\C-d" 'down-list) (define-key esc-map "\C-k" 'kill-sexp) -;;; These are dangerous in various situations, -;;; so let's not encourage anyone to use them. -;;;(define-key global-map [C-M-delete] 'backward-kill-sexp) -;;;(define-key global-map [C-M-backspace] 'backward-kill-sexp) +(define-key global-map [C-M-delete] 'backward-kill-sexp) +(define-key global-map [C-M-backspace] 'backward-kill-sexp) (define-key esc-map [C-delete] 'backward-kill-sexp) (define-key esc-map [C-backspace] 'backward-kill-sexp) (define-key esc-map "\C-n" 'forward-list) @@ -1398,31 +1423,29 @@ if `inhibit-field-text-motion' is non-nil." (define-key ctl-x-5-map "m" 'compose-mail-other-frame) -(defvar ctl-x-r-map - (let ((map (make-sparse-keymap))) - (define-key map "c" 'clear-rectangle) - (define-key map "k" 'kill-rectangle) - (define-key map "d" 'delete-rectangle) - (define-key map "y" 'yank-rectangle) - (define-key map "o" 'open-rectangle) - (define-key map "t" 'string-rectangle) - (define-key map "N" 'rectangle-number-lines) - (define-key map "\M-w" 'copy-rectangle-as-kill) - (define-key map "\C-@" 'point-to-register) - (define-key map [?\C-\ ] 'point-to-register) - (define-key map " " 'point-to-register) - (define-key map "j" 'jump-to-register) - (define-key map "s" 'copy-to-register) - (define-key map "x" 'copy-to-register) - (define-key map "i" 'insert-register) - (define-key map "g" 'insert-register) - (define-key map "r" 'copy-rectangle-to-register) - (define-key map "n" 'number-to-register) - (define-key map "+" 'increment-register) - (define-key map "w" 'window-configuration-to-register) - (define-key map "f" 'frameset-to-register) - map) - "Keymap for subcommands of C-x r.") +(defvar-keymap ctl-x-r-map + :doc "Keymap for subcommands of \\`C-x r'." + "c" #'clear-rectangle + "k" #'kill-rectangle + "d" #'delete-rectangle + "y" #'yank-rectangle + "o" #'open-rectangle + "t" #'string-rectangle + "N" #'rectangle-number-lines + "M-w" #'copy-rectangle-as-kill + "C-@" #'point-to-register + "C-SPC" #'point-to-register + "SPC" #'point-to-register + "j" #'jump-to-register + "s" #'copy-to-register + "x" #'copy-to-register + "i" #'insert-register + "g" #'insert-register + "r" #'copy-rectangle-to-register + "n" #'number-to-register + "+" #'increment-register + "w" #'window-configuration-to-register + "f" #'frameset-to-register) (define-key ctl-x-map "r" ctl-x-r-map) (define-key esc-map "q" 'fill-paragraph) @@ -1439,12 +1462,10 @@ if `inhibit-field-text-motion' is non-nil." (define-key ctl-x-map "[" 'backward-page) (define-key ctl-x-map "]" 'forward-page) -(defvar page-navigation-repeat-map - (let ((map (make-sparse-keymap))) - (define-key map "]" #'forward-page) - (define-key map "[" #'backward-page) - map) - "Keymap to repeat page navigation key sequences. Used in `repeat-mode'.") +(defvar-keymap page-navigation-repeat-map + :doc "Keymap to repeat page navigation key sequences. Used in `repeat-mode'." + "]" #'forward-page + "[" #'backward-page) (put 'forward-page 'repeat-map 'page-navigation-repeat-map) (put 'backward-page 'repeat-map 'page-navigation-repeat-map) @@ -1452,26 +1473,20 @@ if `inhibit-field-text-motion' is non-nil." (define-key ctl-x-map "\C-p" 'mark-page) (define-key ctl-x-map "l" 'count-lines-page) (define-key ctl-x-map "np" 'narrow-to-page) -;; (define-key ctl-x-map "p" 'narrow-to-page) -(defvar abbrev-map (make-sparse-keymap) - "Keymap for abbrev commands.") +(defvar-keymap abbrev-map + :doc "Keymap for abbrev commands." + "l" #'add-mode-abbrev + "C-a" #'add-mode-abbrev + "g" #'add-global-abbrev + "+" #'add-mode-abbrev + "i g" #'inverse-add-global-abbrev + "i l" #'inverse-add-mode-abbrev + "-" #'inverse-add-global-abbrev + "e" #'expand-abbrev + "'" #'expand-abbrev) (define-key ctl-x-map "a" abbrev-map) -(define-key abbrev-map "l" 'add-mode-abbrev) -(define-key abbrev-map "\C-a" 'add-mode-abbrev) -(define-key abbrev-map "g" 'add-global-abbrev) -(define-key abbrev-map "+" 'add-mode-abbrev) -(define-key abbrev-map "ig" 'inverse-add-global-abbrev) -(define-key abbrev-map "il" 'inverse-add-mode-abbrev) -;; (define-key abbrev-map "\C-h" 'inverse-add-global-abbrev) -(define-key abbrev-map "-" 'inverse-add-global-abbrev) -(define-key abbrev-map "e" 'expand-abbrev) -(define-key abbrev-map "'" 'expand-abbrev) -;; (define-key ctl-x-map "\C-a" 'add-mode-abbrev) -;; (define-key ctl-x-map "+" 'add-global-abbrev) -;; (define-key ctl-x-map "\C-h" 'inverse-add-mode-abbrev) -;; (define-key ctl-x-map "-" 'inverse-add-global-abbrev) (define-key esc-map "'" 'abbrev-prefix-mark) (define-key ctl-x-map "'" 'expand-abbrev) (define-key ctl-x-map "\C-b" 'list-buffers) @@ -1481,17 +1496,15 @@ if `inhibit-field-text-motion' is non-nil." (define-key ctl-x-map "z" 'repeat) -(defvar ctl-x-x-map - (let ((map (make-sparse-keymap))) - (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) - (define-key map "i" #'insert-buffer) - (define-key map "t" #'toggle-truncate-lines) - map) - "Keymap for subcommands of C-x x.") +(defvar-keymap ctl-x-x-map + :doc "Keymap for subcommands of \\`C-x x'." + "f" #'font-lock-update + "g" #'revert-buffer-quick + "r" #'rename-buffer + "u" #'rename-uniquely + "n" #'clone-buffer + "i" #'insert-buffer + "t" #'toggle-truncate-lines) (define-key ctl-x-map "x" ctl-x-x-map) (define-key esc-map "\C-l" 'reposition-window) |