Skip to content

Commit

Permalink
Add an easy way to modify common window keybindings
Browse files Browse the repository at this point in the history
  • Loading branch information
davidshepherd7 committed Dec 1, 2024
1 parent 887667d commit 9c82e77
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ There's a fairly rough screencast showing the kind of things you can do with thi

## Typical Setup

By default `frames-only-mode` doesn't modify any keybindings. To replace common
window-using keybindings with their frame equivalents add
`(frames-only-mode-remap-common-window-)` to your config.

In combination with `frames-only-mode` I recommend:

* Running emacs as [server-client](http://wikemacs.org/wiki/Emacs_server).
* Binding a window manager hotkey to open new emacs frames (see below).
* Rebinding any window splitting keys that you use to call `make-frame` instead.


Bind this shell command to a hotkey to automatically open a useful buffer in
Expand Down Expand Up @@ -87,11 +90,12 @@ Alternatively the `*Completions*` buffer can be disabled entirely by setting
* Fix some customize group weirdness
* Fix sometimes leaving additional frames open after quitting magit
* Regexp support in kill-frame-when-buffer-killed-buffer-list
* Add frames-only-mode-remap-common-window-split-keybindings



## Other links

This mode originated in
[a blog post](http://techtrickery.com/tearing-out-the-emacs-window-manager.html)
[a blog post](http://techtrickery.net/tearing-out-the-emacs-window-manager.html)
which has some additional details.
19 changes: 19 additions & 0 deletions frames-only-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,28 @@ magit status buffer."
(defvar frames-only-mode-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-]") #'frames-only-mode-abort-recursive-edit)
;; Additional keys rebinding common window commands are added/removed by TODO
map)
"Keymap for ‘frames-only-mode’.")

;;;###autoload
(defun frames-only-mode-remap-common-window-split-keybindings ()
"Make frames-only-mode remap common window splitting keybinds.
Only modifies `frames-only-mode-mode-map', no effect when the mode is
disabled.
If you have much customisation of your keybinds then you should
probably do this manually instead.
"
(interactive)
(define-key frames-only-mode-mode-map [remap split-window-below] #'make-frame-command)
(define-key frames-only-mode-mode-map [remap split-window-right] #'make-frame-command)
;; C-x 4 is other-window functions, C-x 5 is other frame. remap doesn't work
;; for this case.
(define-key frames-only-mode-mode-map (kbd "C-x 4") #'ctl-x-5-prefix)
)

;;;###autoload
(define-minor-mode frames-only-mode
"Use frames instead of emacs windows."
Expand Down
15 changes: 15 additions & 0 deletions test/frames-only-mode-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,18 @@ Expr should be false, true, false respectively."
(should (frames-only-should-kill-frame-for-buffer "foo"))
(should (frames-only-should-kill-frame-for-buffer "foolish"))
(should-not (frames-only-should-kill-frame-for-buffer "bar"))))


(ert-deftest test-window-keybinding-overrides ()
;; By default we don't do any rebinding
(with-frames-only-mode
(should (equal (key-binding (kbd "C-x 2")) #'split-window-below))
(should (equal (key-binding (kbd "C-x 4 b")) #'switch-to-buffer-other-window))
)

(frames-only-mode-remap-common-window-split-keybindings)
(with-frames-only-mode
(should (equal (key-binding (kbd "C-x 2")) #'make-frame-command))
(should (equal (key-binding (kbd "C-x 4 b")) #'switch-to-buffer-other-frame))
)
)

0 comments on commit 9c82e77

Please sign in to comment.