From 296c585f7731ee6a7c624ddd2507c4e8d98e97ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Kryger?= Date: Wed, 27 Nov 2024 10:56:40 +0000 Subject: [PATCH] Use bind-key for keybindings --- README.md | 38 +++++++++++++++++---------------- modules/init-autocomplete.el | 4 ++-- modules/init-bde-style.el | 14 ++++++------ modules/init-company.el | 2 +- modules/init-cpp.el | 2 +- modules/init-gdb.el | 8 +++---- modules/init-git.el | 39 +++++++++++++++++++--------------- modules/init-highlight.el | 4 ++-- modules/init-ido.el | 2 +- modules/init-look-and-feel.el | 19 ++++++++--------- modules/init-prog-mode.el | 12 +++++------ modules/init-rtags-helm.el | 2 +- modules/init-rtags.el | 38 ++++++++++++++++----------------- modules/init-util.el | 29 +++++++++++++------------ modules/init-window-manager.el | 2 +- 15 files changed, 111 insertions(+), 104 deletions(-) diff --git a/README.md b/README.md index 1eea6b1e..ba66ff9d 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,8 @@ See the [Customization](#customization) section below for more details. ## Keymap +Exordium uses `bind-key` to set up key bindings, which keeps track of all bindings made. You can display a comprehensive list using M-x describe-personal-keybindings. + General: Keybinding | Description @@ -139,20 +141,20 @@ Keybinding | Description Editing: -Keybinding | Description ---------------------|---------------------------------------------------------- -RETURN | Return and indent by default; use S-RETURN for just return. -M-BCKSP | `backward-kill-word` (e.g. the opposite of M-d `kill-word`). -C-\\ | Delete spaces after cursor (`delete-horizontal-space-forward`). -C-BCKSP | Delete spaces before cursor (`delete-horizontal-space-backward`). -M-\\ | Delete all spaces around cursor. -M-LEFT and M-RIGHT | Move cursor by semantic units (use C-LEFT and C-RIGHT to move by words). -C-c d | Duplicate line. -C-= | Expand region by semantic units. -M-C-= | Contract region by semantic units. -M- | Move region one line up -M- | Move region one line down -C-| | Toggle the 80-column ruler (fill column indicator). +Keybinding | Description +--------------------------|---------------------------------------------------------- +RET | Return and indent by default; use S-RET for just return. +M- | `backward-kill-word` (e.g. the opposite of M-d `kill-word`). +C-\\ | Delete spaces after cursor (`delete-horizontal-space-forward`). +C- | Delete spaces before cursor (`delete-horizontal-space-backward`). +M-\\ | Delete all spaces around cursor. +M- and M- | Move cursor by semantic units (use C- and C- to move by words). +C-c d | Duplicate line. +C-= | Expand region by semantic units. +M-C-= | Contract region by semantic units. +M- | Move region one line up +M- | Move region one line down +C-| | Toggle the 80-column ruler (fill column indicator). Navigation: @@ -343,7 +345,7 @@ Treemacs displays the git status of files (added, modified, ignored etc.) using different faces. With the cursor in the Treemacs window, you can use TAB to -open/close directories, RETURN to open a file, and q to +open/close directories, RET to open a file, and q to quit. Use ? to view all the available keys. See the documentation of Treemacs for details. @@ -465,7 +467,7 @@ and auto-complete/company-complete. You can easily use a function key if you pre by adding this in your `after-init.el`: ```lisp -(define-key yas-minor-mode-map (kbd "") 'yas-expand) +(bind-key "" #'yas-expand yas-minor-mode-map) ``` Snippets are stored in `~/.emacs.d/snippets/c++-mode`. Here are @@ -714,8 +716,8 @@ Any navigation is recorded onto a stack, so it is easy to go back and forth: Keybinding | Description ---------------------------------------------|--------------------------------- -C-c r LEFT or C-c r [ | Go back to previous location. -C-c r RIGHT or C-c r ] | Go forward to next location. +C-c r or C-c r [ | Go back to previous location. +C-c r or C-c r ] | Go forward to next location. Refactoring: diff --git a/modules/init-autocomplete.el b/modules/init-autocomplete.el index 9bc6ad3f..0f3ba921 100644 --- a/modules/init-autocomplete.el +++ b/modules/init-autocomplete.el @@ -29,8 +29,8 @@ (;; Key to force trigger auto-complete (useful if ac-auto-start is set to nil) ("C-." . #'auto-complete) :map ac-completing-map - ("" . #'ac-stop) - ([return] . #'ac-complete))) + ("ESC" . #'ac-stop) + ("RET" . #'ac-complete))) (provide 'init-autocomplete) diff --git a/modules/init-bde-style.el b/modules/init-bde-style.el index 5d9e5ffc..10384ecf 100644 --- a/modules/init-bde-style.el +++ b/modules/init-bde-style.el @@ -388,8 +388,8 @@ backspace, delete, left or right." (bde-insert-class-header ?-)) ;;; Ctrl-C = and Ctrl-C - for class header -(keymap-set c-mode-base-map "C-c =" #'bde-insert-define-class-header) -(keymap-set c-mode-base-map "C-c -" #'bde-insert-declare-class-header) +(bind-key "C-c =" #'bde-insert-define-class-header c-mode-base-map) +(bind-key "C-c -" #'bde-insert-declare-class-header c-mode-base-map) ;;; BDE's right style comments such as // RETURN or // LOCK @@ -418,7 +418,7 @@ works even if point is in a C++ comment." (message "Sorry, not enough space..."))) (move-end-of-line nil)) ;;; Ctrl-> to right-aligh the text after point -(keymap-set c-mode-base-map "C->" #'bde-align-right) +(bind-key "C->" #'bde-align-right c-mode-base-map) ;;; Insert redundant include guards @@ -478,7 +478,7 @@ guard around it." ;; No region: just insert one guard for the current line (bde-insert-redundant-include-guard)))) -(keymap-set c-mode-base-map "C-c i" #'bde-insert-redundant-include-guard-region) +(bind-key "C-c i" #'bde-insert-redundant-include-guard-region c-mode-base-map) ;;; Align stuff @@ -809,7 +809,7 @@ declaration or definition." (when (looking-at "\\s\(") (end-of-thing 'arglist))))) -(keymap-set c-mode-base-map "C-c a" #'bde-align-fundecl) +(bind-key "C-c a" #'bde-align-fundecl c-mode-base-map) ;;; Align arguments in a function call @@ -882,7 +882,7 @@ call. It puts one argument per line and aligns to the right." (when (looking-at "\\s\(") (forward-list 1)))) -(keymap-set c-mode-base-map "C-c f" #'bde-align-funcall) +(bind-key "C-c f" #'bde-align-funcall c-mode-base-map) ;;; Align members in a class @@ -1032,7 +1032,7 @@ all comments start at column 40." (t (message "No region")))) -(keymap-set c-mode-base-map "C-c m" #'bde-align-class-members) +(bind-key "C-c m" #'bde-align-class-members c-mode-base-map) ;;; Repunctuate: the BDE comment style requires 2 spaces at the end of each diff --git a/modules/init-company.el b/modules/init-company.el index 95a1fe2f..edb9ff77 100644 --- a/modules/init-company.el +++ b/modules/init-company.el @@ -77,7 +77,7 @@ :bind (("C-." . #'company-complete) :map company-active-map - ("" . #'company-abort))) + ("ESC" . #'company-abort))) (use-package company-statistics diff --git a/modules/init-cpp.el b/modules/init-cpp.el index 4d0f6594..4c860a9b 100644 --- a/modules/init-cpp.el +++ b/modules/init-cpp.el @@ -167,7 +167,7 @@ With argument, switch to the second choice. For example, from a (t (message "This is not a C/C++ file")))))) ;;; Ctrl-Tab to switch between .h and .cpp -(define-key c-mode-base-map [(control tab)] 'cpp-switch-h-cpp) +(bind-key "C-TAB" #'cpp-switch-h-cpp c-mode-base-map) ;;; C++11 keywords diff --git a/modules/init-gdb.el b/modules/init-gdb.el index d08389c4..166c772f 100644 --- a/modules/init-gdb.el +++ b/modules/init-gdb.el @@ -111,10 +111,10 @@ Windows created are gdb command line, source code, and program IO." (declare-function gud-cont "gud" (arg)) (declare-function gud-next "gud" (arg)) (declare-function gud-step "gud" (arg))) -(keymap-set gud-minor-mode-map "" #'gud-step) -(keymap-set gud-minor-mode-map "" #'gud-next) -(keymap-set gud-minor-mode-map "" #'gud-finish) -(keymap-set gud-minor-mode-map "" #'gud-cont) +(bind-key "" #'gud-step gud-minor-mode-map) +(bind-key "" #'gud-next gud-minor-mode-map) +(bind-key "" #'gud-finish gud-minor-mode-map) +(bind-key "" #'gud-cont gud-minor-mode-map) (provide 'init-gdb) diff --git a/modules/init-git.el b/modules/init-git.el index f5003812..c650aca0 100644 --- a/modules/init-git.el +++ b/modules/init-git.el @@ -32,8 +32,8 @@ (require 'vc-git) (defvar exordium-git-map nil) -(define-prefix-command 'exordium-git-map) -(global-set-key (kbd "C-c g") 'exordium-git-map) + +(bind-key "C-c g" (define-prefix-command 'exordium-git-map)) (defvar-local exordium--magit-fullscreen-configuration nil "A screen configuration and a point marker. @@ -296,14 +296,17 @@ with `exordium-magit-quit-session'." ;;; Git Grep +(defun exordium-helm-do-git-grep () + "Call `helm-grep-do-git-grep' with prefix ARG to git-grep whole repository." + (interactive) + (let ((current-prefix-arg '(4))) + (call-interactively #'helm-grep-do-git-grep))) -(define-key exordium-git-map (kbd "g") - (if exordium-helm-everywhere - (lambda() - (interactive) - (setq current-prefix-arg '(4)) - (call-interactively 'helm-grep-do-git-grep)) - (function vc-git-grep))) +(bind-key "g" + (if exordium-helm-everywhere + #'exordium-helm-do-git-grep + #'vc-git-grep) + exordium-git-map) ;;; Make backtick an electric pair @@ -337,14 +340,16 @@ http://stackoverflow.com/questions/9656311/conflict-resolution-with-emacs-ediff- (defun exordium--add-copy-both-to-ediff-mode-map () (when ediff-merge-job - (define-key ediff-mode-map "A" - (lambda () - (interactive) - (exordium-ediff-copy-both-to-C "A" "B"))) - (define-key ediff-mode-map "B" - (lambda () - (interactive) - (exordium-ediff-copy-both-to-C "B" "A"))))) + (bind-key "A" + (lambda () + (interactive) + (exordium-ediff-copy-both-to-C "A" "B")) + ediff-mode-map) + (bind-key "B" + (lambda () + (interactive) + (exordium-ediff-copy-both-to-C "B" "A")) + ediff-mode-map))) (defconst exordium--ediff-long-help-message-merge " diff --git a/modules/init-highlight.el b/modules/init-highlight.el index 0a8343b1..4d80f07c 100644 --- a/modules/init-highlight.el +++ b/modules/init-highlight.el @@ -15,8 +15,8 @@ ;; may be highlighted at one time, using different colors. Feel free to rebind ;; function `exordium-highlight-symbol-at-point' to a better key, like for example: ;; -;; (global-set-key [(control return)] #'exordium-highlight-symbol-at-point) -;; (global-set-key [(f6)] #'exordium-highlight-symbol-at-point) +;; (bind-key "C-RET" #'exordium-highlight-symbol-at-point) +;; (bind-key "" #'exordium-highlight-symbol-at-point) ;; ;; Notes: Exordium uses 2 packages for highlighting the symbol under ;; point. One is "highlight-symbol" used for automatic highlighting after a diff --git a/modules/init-ido.el b/modules/init-ido.el index d086b70e..95d23611 100644 --- a/modules/init-ido.el +++ b/modules/init-ido.el @@ -54,7 +54,7 @@ (mapcar 'abbreviate-file-name recentf-list) nil t))) -(define-key global-map [(control x)(control r)] 'ido-find-recentf) +(bind-key "C-x C-r" #'ido-find-recentf) diff --git a/modules/init-look-and-feel.el b/modules/init-look-and-feel.el index f446b713..717e4073 100644 --- a/modules/init-look-and-feel.el +++ b/modules/init-look-and-feel.el @@ -163,7 +163,7 @@ Set FONT and SIZE if they are passed as arguments." ;; Use ESC as Control-G (when exordium-keyboard-escape - (global-set-key (kbd "") 'keyboard-quit)) + (bind-key "ESC" #'keyboard-quit)) ;;; Use "y or n" answers instead of full words "yes or no" (when exordium-enable-y-or-n @@ -197,16 +197,15 @@ Set FONT and SIZE if they are passed as arguments." (insert-for-yank text))))) (when exordium-enable-insert-gui-primary-selection - (global-set-key [(meta insert)] #'insert-gui-primary-selection)) + (bind-key "M-" #'insert-gui-primary-selection)) ;;; Shortcut keys -(global-set-key [(meta g)] (function goto-line)) +(bind-key "M-g" #'goto-line) (when exordium-keyboard-ctrl-z-undo - (define-key global-map [(control z)] (function undo))) -(global-set-key [(control ?`)] (function kill-this-buffer)) - + (bind-key "C-z" #'undo)) +(bind-key "C-`" #'kill-this-buffer) ;;; Meta-Control-L = switch to last buffer (defun switch-to-other-buffer () @@ -214,10 +213,10 @@ Set FONT and SIZE if they are passed as arguments." (interactive) (switch-to-buffer (other-buffer))) -(define-key global-map [(meta control l)] (function switch-to-other-buffer)) +(bind-key "M-C-l" #'switch-to-other-buffer) ;;; C-x C-b = ibuffer (better than list-buffers) -(define-key global-map [(control x)(control b)] (function ibuffer)) +(bind-key "C-x C-b" #'ibuffer) ;;; Zoom (use-package default-text-scale @@ -267,8 +266,8 @@ Set FONT and SIZE if they are passed as arguments." (interactive "r\np") (move-region start end (if (null n) 1 n))) -(global-set-key (kbd "M-") 'move-region-up) -(global-set-key (kbd "M-") 'move-region-down) +(bind-key "M-" #'move-region-up) +(bind-key "M-" #'move-region-down) ;;; File saving and opening diff --git a/modules/init-prog-mode.el b/modules/init-prog-mode.el index 8651aba2..7b0741a9 100644 --- a/modules/init-prog-mode.el +++ b/modules/init-prog-mode.el @@ -48,19 +48,19 @@ ;;; The return key (cond (exordium-enable-newline-and-indent - (define-key prog-mode-map (kbd "") (function newline-and-indent)) - (define-key prog-mode-map (kbd "") (function newline))) + (bind-key "RET" #'newline-and-indent prog-mode-map) + (bind-key "S-RET" #'newline prog-mode-map)) (t - (define-key prog-mode-map (kbd "") (function newline-and-indent)))) + (bind-key "S-RET" #'newline-and-indent prog-mode-map))) ;;; Fill comments, comment regions (setq comment-auto-fill-only-comments 1) -(define-key prog-mode-map (kbd "\C-c\C-c") (function comment-region)) +(bind-key "C-c C-c" #'comment-dwim prog-mode-map) ;;; Step through compile errors -(global-set-key (quote [f10]) (quote next-error)) -(global-set-key (quote [(control f10)]) (quote previous-error)) +(bind-key "" #'next-error) +(bind-key "C-" #'previous-error) ;;; Font lock changes diff --git a/modules/init-rtags-helm.el b/modules/init-rtags-helm.el index 7858573f..31b322e3 100644 --- a/modules/init-rtags-helm.el +++ b/modules/init-rtags-helm.el @@ -188,7 +188,7 @@ For example: classes, functions, variables, enums and other." (candidates . ,(rtags-helm-sort-list macros)) (action . rtags-helm-jump-to-line)))))) -(define-key c-mode-base-map [(meta control g)] 'rtags-helm-select-taglist) +(bind-key "M-C-g" #'rtags-helm-select-taglist c-mode-base-map) (provide 'init-rtags-helm) diff --git a/modules/init-rtags.el b/modules/init-rtags.el index b742aa5d..7b05e9a4 100644 --- a/modules/init-rtags.el +++ b/modules/init-rtags.el @@ -172,29 +172,30 @@ ;; "Ctrl-c r" is not defined by default, so we get the whole keyboard. (rtags-enable-standard-keybindings c-mode-base-map "\C-cr") +;; Disable "M-." and "M-," as they conflict with standard `xref' ;; Alias for C-c r . This key recenters the buffer if needed. -(define-key c-mode-base-map "\M-." - (lambda (other-window) - (interactive "P") - (let ((rtags-after-find-file-hook rtags-after-find-file-hook)) - (add-hook 'rtags-after-find-file-hook (lambda () (recenter))) - (rtags-find-symbol-at-point other-window)))) - +;; (bind-key "M-." +;; (lambda (other-window) +;; (interactive "P") +;; (let ((rtags-after-find-file-hook rtags-after-find-file-hook)) +;; (add-hook 'rtags-after-find-file-hook (lambda () (recenter))) +;; (rtags-find-symbol-at-point other-window))) +;; c-mode-base-map) ;; Alias for C-c r , -(define-key c-mode-base-map "\M-," (function rtags-find-references-at-point)) +;; (bind-key "M-," #'rtags-find-references-at-point c-mode-base-map) ;; Alias for C-c r [ -(define-key c-mode-base-map [(control c) (r) (left)] (function rtags-location-stack-back)) +(bind-key "C-c r " #'rtags-location-stack-back c-mode-base-map) ;; Alias for C-c r [ -(define-key c-mode-base-map [(control c) (r) (right)] (function rtags-location-stack-forward)) +(bind-key "C-c r " #'rtags-location-stack-forward c-mode-base-map) -(define-key c-mode-base-map [(meta control g)] (function rtags-imenu)) +(bind-key "M-C-g" #'rtags-imenu c-mode-base-map) -(define-key c-mode-base-map [(control c) (r) (down)] (function rtags-next-diag)) -(define-key c-mode-base-map [(control c) (r) (up)] (function rtags-previous-diag)) -(define-key c-mode-base-map [(control c) (r) (c)] (function rtags-clear-diagnostics)) +(bind-key "C-c r " #'rtags-next-diag c-mode-base-map) +(bind-key "C-c r " #'rtags-previous-diag c-mode-base-map) +(bind-key "C-c r c" #'rtags-clear-diagnostics c-mode-base-map) -(define-key c-mode-base-map "\C-crQ" (function rtags-stop-diagnostics)) +(bind-key "C-c r S-q" #'rtags-stop-diagnostics c-mode-base-map) ;;; Start rdm as a subprocess, with output in a buffer @@ -283,7 +284,7 @@ Redirect output to *RTags Diagnostics*. Also start the RTag diagostics mode." (t (message "Rtags rdm is not running (use M-x rtags-start)"))))) -(define-key c-mode-base-map [(control c)(r)(l)] 'rtags-show-rdm-buffer) +(bind-key "C-c r l" #'rtags-show-rdm-buffer c-mode-base-map) ;;; Mode for rdm log output @@ -369,7 +370,7 @@ Similar to `rtags-diagnostics' but without reparsing." (other-window -1)))) (message "Rtags diagnostics is not running (use C-c r D)"))) -(define-key c-mode-base-map [(control c)(r)(d)] 'rtags-show-diagnostics-buffer) +(bind-key "C-c r d" #'rtags-show-diagnostics-buffer c-mode-base-map) ;; Used in powerline: (defun rtags-diagnostics-has-errors () @@ -473,8 +474,7 @@ Similar to `rtags-diagnostics' but without reparsing." ;; ;; ))))) -;; (define-key c-mode-base-map [(control c)(r)(A)] -;; 'rtags-diagnostics-auto-complete)) +;; (bind-key "C-c r S-A" #'rtags-diagnostics-auto-complete c-mode-base-map) diff --git a/modules/init-util.el b/modules/init-util.el index 8c273adc..58a80b56 100644 --- a/modules/init-util.el +++ b/modules/init-util.el @@ -89,7 +89,7 @@ insert the char that many times." ((looking-at "\\s\)") (forward-char 1) (backward-list 1)) (t (self-insert-command (or arg 1))))) -(global-set-key [(control %)] #'goto-match-paren-or-up) +(bind-key "C-%" #'goto-match-paren-or-up) ;;; Bookmark position stack @@ -126,8 +126,8 @@ insert the char that many times." (t (message "Invalid position in stack"))))) -(global-set-key [(control c)(s)] #'postack-push) -(global-set-key [(control c)(b)] #'postack-pop) +(bind-key "C-c s" #'postack-push) +(bind-key "C-c b" #'postack-pop) ;;; Goto last change @@ -208,7 +208,7 @@ When called with ARG, do this that many times." ;; Leave the cursor an the same column if we duplicated 1 line (move-to-column col)))) -(global-set-key [(control c)(d)] #'duplicate-line-or-region) +(bind-key "C-c d" #'duplicate-line-or-region) ;;; Deleting Spaces @@ -218,14 +218,14 @@ When called with ARG, do this that many times." (interactive "*") (delete-region (point) (progn (skip-chars-forward " \t") (point)))) -(global-set-key [(control \\)] 'delete-horizontal-space-forward) +(bind-key "C-\\" #'delete-horizontal-space-forward) (defun delete-horizontal-space-backward () "Delete all spaces and tabs before point." (interactive "*") (delete-region (point) (progn (skip-chars-backward " \t") (point)))) -(global-set-key [(control backspace)] #'delete-horizontal-space-backward) +(bind-key "C-" #'delete-horizontal-space-backward) ;;; Deleting Words @@ -242,7 +242,7 @@ When called with ARG, do this that many times." (interactive "p") (delete-region (point) (progn (forward-word arg) (point)))) -(define-key global-map [(meta d)] 'delete-word) +(bind-key "M-d" #'delete-word) (defun backward-delete-word (arg) "Delete characters backward until encountering the end of a word. @@ -250,7 +250,7 @@ When called with ARG, do this that many times." (interactive "p") (delete-word (- arg))) -(define-key global-map [(meta backspace)] #'backward-delete-word) +(bind-key "M-" #'backward-delete-word) ;;; Moving between words @@ -263,12 +263,12 @@ When called with ARG, do this that many times." ;;; and M-right to move following the syntax: the motion is slower but ;;; symetrical. C-Left and C-Right are left unchanged (move by words). -(define-key global-map [(meta right)] +(bind-key "M-" (lambda (arg) (interactive "p") (forward-same-syntax arg))) -(define-key global-map [(meta left)] +(bind-key "M-" (lambda (arg) (interactive "p") (forward-same-syntax (- arg)))) @@ -333,9 +333,10 @@ When called with ARG, do this that many times." ;;; Avy - go to any word on the screen in just 2 or 3 keystrokes. ;;; C-c j => asks for a character, then one or 2 keys to jump. ;;; Note: Avy has other commands, this is the most useful. - -(global-set-key [(control c)(j)] #'avy-goto-word-or-subword-1) -(global-set-key [(control ?\')] #'avy-goto-word-or-subword-1) +(use-package avy + :bind + (("C-c j" . #'avy-goto-word-or-subword-1) + ("C-'" . #'avy-goto-word-or-subword-1))) ;;; Finding lines that are too long (according to some code styles). @@ -404,7 +405,7 @@ REGION is t when called interactively and is passed to (emacs-lisp-docstring-fill-column t)) (fill-paragraph nil region))) -(define-key global-map "\M-Q" #'unfill-paragraph) +(bind-key "M-S-q" #'unfill-paragraph) ;;; Config management diff --git a/modules/init-window-manager.el b/modules/init-window-manager.el index 3847db0e..7a240dc4 100644 --- a/modules/init-window-manager.el +++ b/modules/init-window-manager.el @@ -109,7 +109,7 @@ (current-buffer)))) ;;; Note: apparently there is no Pause key on an Apple keyboard... -(define-key global-map [pause] 'exordium-toggle-window-dedicated) +(bind-key "" #'exordium-toggle-window-dedicated) ;;; Ace-window