Skip to content

Commit

Permalink
Use bind-key for keybindings
Browse files Browse the repository at this point in the history
  • Loading branch information
pkryger committed Nov 27, 2024
1 parent 272a585 commit 296c585
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 104 deletions.
38 changes: 20 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <kbd>M-x describe-personal-keybindings</kbd>.

General:

Keybinding | Description
Expand All @@ -139,20 +141,20 @@ Keybinding | Description

Editing:

Keybinding | Description
--------------------|----------------------------------------------------------
<kbd>RETURN</kbd> | Return and indent by default; use <kbd>S-RETURN</kbd> for just return.
<kbd>M-BCKSP</kbd> | `backward-kill-word` (e.g. the opposite of <kbd>M-d</kbd> `kill-word`).
<kbd>C-\\</kbd> | Delete spaces after cursor (`delete-horizontal-space-forward`).
<kbd>C-BCKSP</kbd> | Delete spaces before cursor (`delete-horizontal-space-backward`).
<kbd>M-\\</kbd> | Delete all spaces around cursor.
<kbd>M-LEFT</kbd> and <kbd>M-RIGHT</kbd> | Move cursor by semantic units (use <kbd>C-LEFT</kbd> and <kbd>C-RIGHT</kbd> to move by words).
<kbd>C-c d</kbd> | Duplicate line.
<kbd>C-=</kbd> | Expand region by semantic units.
<kbd>M-C-=</kbd> | Contract region by semantic units.
<kbd>M-<up></kbd> | Move region one line up
<kbd>M-<down></kbd> | Move region one line down
<kbd>C-&#124;</kbd> | Toggle the 80-column ruler (fill column indicator).
Keybinding | Description
--------------------------|----------------------------------------------------------
<kbd>RET</kbd> | Return and indent by default; use <kbd>S-RET</kbd> for just return.
<kbd>M-<backspace></kbd> | `backward-kill-word` (e.g. the opposite of <kbd>M-d</kbd> `kill-word`).
<kbd>C-\\</kbd> | Delete spaces after cursor (`delete-horizontal-space-forward`).
<kbd>C-<backspace></kbd> | Delete spaces before cursor (`delete-horizontal-space-backward`).
<kbd>M-\\</kbd> | Delete all spaces around cursor.
<kbd>M-<left></kbd> and <kbd>M-<right></kbd> | Move cursor by semantic units (use <kbd>C-<left></kbd> and <kbd>C-<right></kbd> to move by words).
<kbd>C-c d</kbd> | Duplicate line.
<kbd>C-=</kbd> | Expand region by semantic units.
<kbd>M-C-=</kbd> | Contract region by semantic units.
<kbd>M-<up></kbd> | Move region one line up
<kbd>M-<down></kbd> | Move region one line down
<kbd>C-&#124;</kbd> | Toggle the 80-column ruler (fill column indicator).

Navigation:

Expand Down Expand Up @@ -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 <kbd>TAB</kbd> to
open/close directories, <kbd>RETURN</kbd> to open a file, and <kbd>q</kbd> to
open/close directories, <kbd>RET</kbd> to open a file, and <kbd>q</kbd> to
quit. Use <kbd>?</kbd> to view all the available keys. See the documentation of
Treemacs for details.

Expand Down Expand Up @@ -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 "<f2>") 'yas-expand)
(bind-key "<f2>" #'yas-expand yas-minor-mode-map)
```

Snippets are stored in `~/.emacs.d/snippets/c++-mode`. Here are
Expand Down Expand Up @@ -714,8 +716,8 @@ Any navigation is recorded onto a stack, so it is easy to go back and forth:

Keybinding | Description
---------------------------------------------|---------------------------------
<kbd>C-c r LEFT</kbd> or <kbd>C-c r [</kbd> | Go back to previous location.
<kbd>C-c r RIGHT</kbd> or <kbd>C-c r ]</kbd> | Go forward to next location.
<kbd>C-c r <left></kbd> or <kbd>C-c r [</kbd> | Go back to previous location.
<kbd>C-c r <right></kbd> or <kbd>C-c r ]</kbd> | Go forward to next location.

Refactoring:

Expand Down
4 changes: 2 additions & 2 deletions modules/init-autocomplete.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
("<escape>" . #'ac-stop)
([return] . #'ac-complete)))
("ESC" . #'ac-stop)
("RET" . #'ac-complete)))

(provide 'init-autocomplete)

Expand Down
14 changes: 7 additions & 7 deletions modules/init-bde-style.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/init-company.el
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
:bind
(("C-." . #'company-complete)
:map company-active-map
("<escape>" . #'company-abort)))
("ESC" . #'company-abort)))


(use-package company-statistics
Expand Down
2 changes: 1 addition & 1 deletion modules/init-cpp.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions modules/init-gdb.el
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<f5>" #'gud-step)
(keymap-set gud-minor-mode-map "<f6>" #'gud-next)
(keymap-set gud-minor-mode-map "<f7>" #'gud-finish)
(keymap-set gud-minor-mode-map "<f8>" #'gud-cont)
(bind-key "<f5>" #'gud-step gud-minor-mode-map)
(bind-key "<f6>" #'gud-next gud-minor-mode-map)
(bind-key "<f7>" #'gud-finish gud-minor-mode-map)
(bind-key "<f8>" #'gud-cont gud-minor-mode-map)


(provide 'init-gdb)
Expand Down
39 changes: 22 additions & 17 deletions modules/init-git.el
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
"
Expand Down
4 changes: 2 additions & 2 deletions modules/init-highlight.el
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<f6>" #'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
Expand Down
2 changes: 1 addition & 1 deletion modules/init-ido.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)



Expand Down
19 changes: 9 additions & 10 deletions modules/init-look-and-feel.el
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<escape>") '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
Expand Down Expand Up @@ -197,27 +197,26 @@ 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>" #'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 ()
"Alternates between the two most recent buffers."
(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
Expand Down Expand Up @@ -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-<up>") 'move-region-up)
(global-set-key (kbd "M-<down>") 'move-region-down)
(bind-key "M-<up>" #'move-region-up)
(bind-key "M-<down>" #'move-region-down)


;;; File saving and opening
Expand Down
12 changes: 6 additions & 6 deletions modules/init-prog-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@

;;; The return key
(cond (exordium-enable-newline-and-indent
(define-key prog-mode-map (kbd "<return>") (function newline-and-indent))
(define-key prog-mode-map (kbd "<S-return>") (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 "<S-return>") (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 "<f10>" #'next-error)
(bind-key "C-<f10>" #'previous-error)


;;; Font lock changes
Expand Down
2 changes: 1 addition & 1 deletion modules/init-rtags-helm.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 296c585

Please sign in to comment.