From 03b961a3cf1532b7e6751e94bafce3d0dc9b829b Mon Sep 17 00:00:00 2001 From: "Seth T. Aldini" Date: Mon, 8 Sep 2025 21:04:47 -0500 Subject: [PATCH] Create the default C-x keymap. Creates the lem-core:*global-prefix-keymap* and binds to it "C-x". This allows users to rebind the keymap to a different prefix. New "C-x" bindings in the lem-core:*global-keymap* should be bound in this new keymap instead. --- contrib/fbar/fbar.lisp | 2 +- extensions/legit/legit.lisp | 2 +- src/commands/buffer.lisp | 2 +- src/commands/edit.lisp | 2 +- src/commands/file.lisp | 15 +++++------ src/commands/help.lisp | 2 +- src/commands/mark.lisp | 4 +-- src/commands/move.lisp | 4 +-- src/commands/other.lisp | 2 +- src/commands/process.lisp | 4 +-- src/commands/project.lisp | 13 +++++----- src/commands/window.lisp | 37 +++++++++++++++------------- src/commands/word.lisp | 4 +-- src/ext/abbrev.lisp | 2 +- src/ext/directory-mode/keybinds.lisp | 2 +- src/ext/filer.lisp | 2 +- src/ext/grep.lisp | 2 +- src/ext/kbdmacro.lisp | 6 ++--- src/ext/list-buffers.lisp | 2 +- src/ext/rectangle.lisp | 2 +- src/fundamental-mode.lisp | 4 +++ src/internal-packages.lisp | 1 + 22 files changed, 63 insertions(+), 53 deletions(-) diff --git a/contrib/fbar/fbar.lisp b/contrib/fbar/fbar.lisp index 5be9d064d..29624eaf4 100644 --- a/contrib/fbar/fbar.lisp +++ b/contrib/fbar/fbar.lisp @@ -37,7 +37,7 @@ ;; open-close directories with ;; select files with -(define-key *global-keymap* "C-x f" 'fbar-on) +(define-key *global-prefix-keymap* "f" 'fbar-on) (define-key *fbar-mode-keymap* "j" 'next-line) (define-key *fbar-mode-keymap* "k" 'previous-line) (define-key *fbar-mode-keymap* "Down" 'next-line) diff --git a/extensions/legit/legit.lisp b/extensions/legit/legit.lisp index c37a44a2f..25fafdfc4 100644 --- a/extensions/legit/legit.lisp +++ b/extensions/legit/legit.lisp @@ -62,7 +62,7 @@ Currently Git-only. Concretely, this calls Git with the -w option.") ;; git commands. ;; Some are defined on peek-legit too. -(define-key *global-keymap* "C-x g" 'legit-status) +(define-key *global-prefix-keymap* "g" 'legit-status) (define-key *legit-diff-mode-keymap* "s" 'legit-stage-hunk) (define-key *legit-diff-mode-keymap* "u" 'legit-unstage-hunk) (define-key *legit-diff-mode-keymap* "n" 'legit-goto-next-hunk) diff --git a/src/commands/buffer.lisp b/src/commands/buffer.lisp index bc0f77df6..6680a9ba3 100644 --- a/src/commands/buffer.lisp +++ b/src/commands/buffer.lisp @@ -11,7 +11,7 @@ (defvar *read-only-function* nil) -(define-key *global-keymap* "C-x C-q" 'toggle-read-only) +(define-key *global-prefix-keymap* "C-q" 'toggle-read-only) (define-key *global-keymap* "M-~" 'unmark-buffer) (define-command indent-current-buffer () () diff --git a/src/commands/edit.lisp b/src/commands/edit.lisp index 69428ddea..1c5e74b7a 100644 --- a/src/commands/edit.lisp +++ b/src/commands/edit.lisp @@ -56,7 +56,7 @@ (define-key *global-keymap* "C-Shift-Backspace" 'kill-whole-line) (define-key *global-keymap* "C-y" 'yank) (define-key *global-keymap* "M-y" 'yank-pop) -(define-key *global-keymap* "C-x C-o" 'delete-blank-lines) +(define-key *global-prefix-keymap* "C-o" 'delete-blank-lines) (define-key *global-keymap* "M-Space" 'just-one-space) (define-key *global-keymap* "M-^" 'delete-indentation) (define-key *global-keymap* "C-t" 'transpose-characters) diff --git a/src/commands/file.lisp b/src/commands/file.lisp index e396e252b..8534856e7 100644 --- a/src/commands/file.lisp +++ b/src/commands/file.lisp @@ -33,13 +33,14 @@ (:lock t)) (in-package :lem-core/commands/file) -(define-key *global-keymap* "C-x C-f" 'find-file) -(define-key *global-keymap* "C-x C-r" 'read-file) -(define-key *global-keymap* "C-x C-s" 'save-current-buffer) -(define-key *global-keymap* "C-x C-w" 'write-file) -(define-key *global-keymap* "C-x C-h" 'find-recent-file) -(define-key *global-keymap* "C-x Tab" 'insert-file) -(define-key *global-keymap* "C-x s" 'save-some-buffers) +(let ((keymap *global-prefix-keymap*)) + (define-key keymap "C-f" 'find-file) + (define-key keymap "C-r" 'read-file) + (define-key keymap "C-s" 'save-current-buffer) + (define-key keymap "C-w" 'write-file) + (define-key keymap "C-h" 'find-recent-file) + (define-key keymap "Tab" 'insert-file) + (define-key keymap "s" 'save-some-buffers)) ;; Programs to find files recursively: ;; We want symbols and not strings, for CLOS dispatch. diff --git a/src/commands/help.lisp b/src/commands/help.lisp index 2906dd79a..299cf672c 100644 --- a/src/commands/help.lisp +++ b/src/commands/help.lisp @@ -10,7 +10,7 @@ (:lock t)) (in-package :lem-core/commands/help) -(define-key *global-keymap* "C-x ?" 'describe-key) +(define-key *global-prefix-keymap* "?" 'describe-key) (define-command describe-key () () "Tell what is the command associated to a keybinding." diff --git a/src/commands/mark.lisp b/src/commands/mark.lisp index 906574dc2..58368a264 100644 --- a/src/commands/mark.lisp +++ b/src/commands/mark.lisp @@ -9,8 +9,8 @@ (define-key *global-keymap* "C-@" 'mark-set) (define-key *global-keymap* "C-Space" 'mark-set) -(define-key *global-keymap* "C-x C-x" 'exchange-point-mark) -(define-key *global-keymap* "C-x h" 'mark-set-whole-buffer) +(define-key *global-prefix-keymap* "C-x" 'exchange-point-mark) +(define-key *global-prefix-keymap* "h" 'mark-set-whole-buffer) (define-command mark-set (p) (:universal-nil) "Sets a mark at the current cursor position." diff --git a/src/commands/move.lisp b/src/commands/move.lisp index 35011dadd..db1708fc2 100644 --- a/src/commands/move.lisp +++ b/src/commands/move.lisp @@ -41,8 +41,8 @@ (define-key *global-keymap* "PageDown" 'next-page) (define-key *global-keymap* "M-v" 'previous-page) (define-key *global-keymap* "PageUp" 'previous-page) -(define-key *global-keymap* "C-x ]" 'next-page-char) -(define-key *global-keymap* "C-x [" 'previous-page-char) +(define-key *global-prefix-keymap* "]" 'next-page-char) +(define-key *global-prefix-keymap* "[" 'previous-page-char) (define-key *global-keymap* "M-g" 'goto-line) (defun next-line-aux (n diff --git a/src/commands/other.lisp b/src/commands/other.lisp index 78e311ea8..b5b9b3de6 100644 --- a/src/commands/other.lisp +++ b/src/commands/other.lisp @@ -31,7 +31,7 @@ By default, persist M-x commands to disk. See *persist-M-x-commands*.") (define-key *global-keymap* "NopKey" 'nop-command) (define-key *global-keymap* "C-g" 'keyboard-quit) (define-key *global-keymap* "Escape" 'escape) -(define-key *global-keymap* "C-x C-c" 'exit-lem) +(define-key *global-prefix-keymap* "C-c" 'exit-lem) (define-key *global-keymap* "M-x" 'execute-command) (define-key *global-keymap* "Shift-F10" 'show-context-menu) (define-key *global-keymap* "M-h" 'show-context-menu) diff --git a/src/commands/process.lisp b/src/commands/process.lisp index b002b5da8..1b99354cb 100644 --- a/src/commands/process.lisp +++ b/src/commands/process.lisp @@ -6,8 +6,8 @@ (:lock t)) (in-package :lem-core/commands/process) -(define-key *global-keymap* "C-x #" 'filter-buffer) -(define-key *global-keymap* "C-x @" 'pipe-command) +(define-key *global-prefix-keymap* "#" 'filter-buffer) +(define-key *global-prefix-keymap* "@" 'pipe-command) (define-command filter-buffer (cmd) ((:string "Filter buffer: ")) "Replaces the contents of the buffer with the result of executing the command entered." diff --git a/src/commands/project.lisp b/src/commands/project.lisp index adf6bb96a..c895e41bb 100644 --- a/src/commands/project.lisp +++ b/src/commands/project.lisp @@ -21,12 +21,13 @@ (in-package :lem-core/commands/project) -(define-key *global-keymap* "C-x p f" 'project-find-file) -(define-key *global-keymap* "C-x p d" 'project-root-directory) -(define-key *global-keymap* "C-x p K" 'project-kill-buffers) -(define-key *global-keymap* "C-x p p" 'project-switch) -(define-key *global-keymap* "C-x p s" 'project-save) -(define-key *global-keymap* "C-x p u" 'project-unsave) +(let ((keymap *global-prefix-keymap*)) + (define-key keymap "p f" 'project-find-file) + (define-key keymap "p d" 'project-root-directory) + (define-key keymap "p K" 'project-kill-buffers) + (define-key keymap "p p" 'project-switch) + (define-key keymap "p s" 'project-save) + (define-key keymap "p u" 'project-unsave)) (defvar *root-directories* (list diff --git a/src/commands/window.lisp b/src/commands/window.lisp index f12b83d3c..9c7063947 100644 --- a/src/commands/window.lisp +++ b/src/commands/window.lisp @@ -33,31 +33,34 @@ (:lock t)) (in-package :lem-core/commands/window) -(define-key *global-keymap* "C-x b" 'select-buffer) -(define-key *global-keymap* "C-x k" 'kill-buffer) -(define-key *global-keymap* "C-x Left" 'previous-buffer) -(define-key *global-keymap* "C-x Right" 'next-buffer) (define-key *global-keymap* "C-l" 'recenter) -(define-key *global-keymap* "C-x 2" 'split-active-window-vertically) -(define-key *global-keymap* "C-x 3" 'split-active-window-horizontally) -(define-key *global-keymap* "C-x o" 'next-window) (define-key *global-keymap* "M-o" 'next-window) (define-key *global-keymap* "M-O" 'previous-window) -(define-key *global-keymap* "C-x 1" 'delete-other-windows) -(define-key *global-keymap* "C-x 0" 'delete-active-window) (define-key *global-keymap* "M-q" 'delete-active-window) -(define-key *global-keymap* "C-x ^" 'grow-window) -(define-key *global-keymap* "C-x C-z" 'shrink-window) -(define-key *global-keymap* "C-x }" 'grow-window-horizontally) -(define-key *global-keymap* "C-x {" 'shrink-window-horizontally) (define-key *global-keymap* "C-Down" 'scroll-down) (define-key *global-keymap* "M-Down" 'scroll-down) (define-key *global-keymap* "C-Up" 'scroll-up) (define-key *global-keymap* "M-Up" 'scroll-up) -(define-key *global-keymap* "C-x 4 f" 'find-file-next-window) -(define-key *global-keymap* "C-x 4 r" 'read-file-next-window) -(define-key *global-keymap* "C-x 4 b" 'select-buffer-next-window) -(define-key *global-keymap* "C-x 4 p f" 'project-find-file-next-window) + + +(let ((keymap *global-prefix-keymap*)) + (define-key keymap "b" 'select-buffer) + (define-key keymap "k" 'kill-buffer) + (define-key keymap "Left" 'previous-buffer) + (define-key keymap "Right" 'next-buffer) + (define-key keymap "2" 'split-active-window-vertically) + (define-key keymap "3" 'split-active-window-horizontally) + (define-key keymap "o" 'next-window) + (define-key keymap "1" 'delete-other-windows) + (define-key keymap "0" 'delete-active-window) + (define-key keymap "^" 'grow-window) + (define-key keymap "C-z" 'shrink-window) + (define-key keymap "}" 'grow-window-horizontally) + (define-key keymap "{" 'shrink-window-horizontally) + (define-key keymap "4 f" 'find-file-next-window) + (define-key keymap "4 r" 'read-file-next-window) + (define-key keymap "4 b" 'select-buffer-next-window) + (define-key keymap "4 p f" 'project-find-file-next-window)) (defvar *balance-after-split-window* t) diff --git a/src/commands/word.lisp b/src/commands/word.lisp index f959a0131..50c42d098 100644 --- a/src/commands/word.lisp +++ b/src/commands/word.lisp @@ -28,8 +28,8 @@ (define-key *global-keymap* "C-M-h" 'backward-delete-word) (define-key *global-keymap* "M-Backspace" 'backward-delete-word) (define-key *global-keymap* "C-Backspace" 'backward-delete-word) -(define-key *global-keymap* "C-x C-l" 'downcase-region) -(define-key *global-keymap* "C-x C-u" 'uppercase-region) +(define-key *global-prefix-keymap* "C-l" 'downcase-region) +(define-key *global-prefix-keymap* "C-u" 'uppercase-region) (define-key *global-keymap* "M-c" 'capitalize-word) (define-key *global-keymap* "M-l" 'lowercase-word) (define-key *global-keymap* "M-u" 'uppercase-word) diff --git a/src/ext/abbrev.lisp b/src/ext/abbrev.lisp index d76967431..471cc7535 100644 --- a/src/ext/abbrev.lisp +++ b/src/ext/abbrev.lisp @@ -65,7 +65,7 @@ (buffer-list)) :test #'equal))))) -(define-key *global-keymap* "C-x /" 'abbrev-with-pop-up-window) +(define-key *global-prefix-keymap* "/" 'abbrev-with-pop-up-window) (define-command abbrev-with-pop-up-window () () (run-completion (lambda (point) (let* ((src-word (preceding-word point)) diff --git a/src/ext/directory-mode/keybinds.lisp b/src/ext/directory-mode/keybinds.lisp index dba3e9cf0..82b504fd5 100644 --- a/src/ext/directory-mode/keybinds.lisp +++ b/src/ext/directory-mode/keybinds.lisp @@ -10,7 +10,7 @@ (eval-when (:compile-toplevel :load-toplevel :execute) (sb-ext:lock-package :lem/directory-mode/keybinds)) -(define-key *global-keymap* "C-x C-j" 'find-file-directory) +(define-key *global-prefix-keymap* "C-j" 'find-file-directory) (define-key *directory-mode-keymap* "q" 'quit-active-window) (define-key *directory-mode-keymap* "M-q" 'quit-active-window) diff --git a/src/ext/filer.lisp b/src/ext/filer.lisp index a0253a45e..ff626e60c 100644 --- a/src/ext/filer.lisp +++ b/src/ext/filer.lisp @@ -11,7 +11,7 @@ (setf (variable-value 'line-wrap :buffer (current-buffer)) nil) (setf (buffer-read-only-p (current-buffer)) t)) -(define-key *global-keymap* "C-x d" 'filer) +(define-key *global-prefix-keymap* "d" 'filer) (define-key *filer-mode-keymap* "Return" 'filer-select) (define-key *filer-mode-keymap* "D" 'filer-delete-file) diff --git a/src/ext/grep.lisp b/src/ext/grep.lisp index 4a0d7a522..52a79d9d6 100644 --- a/src/ext/grep.lisp +++ b/src/ext/grep.lisp @@ -188,7 +188,7 @@ (:name "Peek" :keymap *peek-grep-mode-keymap*)) -(define-key *global-keymap* "C-x p g" 'project-grep) +(define-key *global-prefix-keymap* "p g" 'project-grep) (define-key *peek-grep-mode-keymap* "C-x ?" 'grep-help) ;; originally bound to describe-key. ;; Comment out because it conflicts with isearch. diff --git a/src/ext/kbdmacro.lisp b/src/ext/kbdmacro.lisp index 71d54e3a6..a0824c3b0 100644 --- a/src/ext/kbdmacro.lisp +++ b/src/ext/kbdmacro.lisp @@ -12,7 +12,7 @@ (defvar *last-macro-chars* nil) (defvar *macro-running-p* nil) -(define-key *global-keymap* "C-x (" 'kbdmacro-start) +(define-key *global-prefix-keymap* "(" 'kbdmacro-start) (define-command kbdmacro-start () () (cond ((key-recording-p) (stop-record-key) @@ -20,7 +20,7 @@ (t (start-record-key)))) -(define-key *global-keymap* "C-x )" 'kbdmacro-end) +(define-key *global-prefix-keymap* ")" 'kbdmacro-end) (define-command kbdmacro-end () () (cond (*macro-running-p* t) ((not (key-recording-p)) @@ -28,7 +28,7 @@ (t (setq *last-macro-chars* (stop-record-key))))) -(define-key *global-keymap* "C-x e" 'kbdmacro-execute) +(define-key *global-prefix-keymap* "e" 'kbdmacro-execute) (define-command kbdmacro-execute (n) (:universal) (cond ((key-recording-p) (editor-error "Macro already active")) diff --git a/src/ext/list-buffers.lisp b/src/ext/list-buffers.lisp index c7478723c..8bffd0e39 100644 --- a/src/ext/list-buffers.lisp +++ b/src/ext/list-buffers.lisp @@ -12,7 +12,7 @@ (:export :list-buffers)) (in-package :lem/list-buffers) -(define-key *global-keymap* "C-x C-b" 'list-buffers) +(define-key *global-prefix-keymap* "C-b" 'list-buffers) (defun kill-buffers (window) (let ((multi-column-list (multi-column-list-of-window window))) diff --git a/src/ext/rectangle.lisp b/src/ext/rectangle.lisp index 9e779fb76..9cf9a9f80 100644 --- a/src/ext/rectangle.lisp +++ b/src/ext/rectangle.lisp @@ -17,7 +17,7 @@ :name "Rectangle") (setf *mark-point* (copy-point (current-point) :temporary))) -(define-key *global-keymap* "C-x Space" 'start-rectangle-mark-mode) +(define-key *global-prefix-keymap* "Space" 'start-rectangle-mark-mode) (define-key *rectangle-mark-mode-keymap* 'copy-region 'rectangle-copy) (define-key *rectangle-mark-mode-keymap* 'kill-region 'rectangle-kill) (define-key *rectangle-mark-mode-keymap* "C-o" 'rectangle-open) diff --git a/src/fundamental-mode.lisp b/src/fundamental-mode.lisp index d4d33d38f..6a8e97aec 100644 --- a/src/fundamental-mode.lisp +++ b/src/fundamental-mode.lisp @@ -4,6 +4,10 @@ (:name "Fundamental")) (defvar *global-keymap* (make-keymap :name '*global-keymap*)) +(defvar *global-prefix-keymap* (make-keymap :name '*global-prefix-keymap*) + "The global prefix keymap. It defaults to \"C-x\". ") + +(define-key *global-keymap* "C-x" *global-prefix-keymap*) (define-global-mode emacs-mode () (:name "emacs" diff --git a/src/internal-packages.lisp b/src/internal-packages.lisp index 341f4cd53..c14f098ee 100644 --- a/src/internal-packages.lisp +++ b/src/internal-packages.lisp @@ -468,6 +468,7 @@ :keymap-undef-hook :make-keymap :*global-keymap* + :*global-prefix-keymap* :define-key :define-keys :undefine-key