Skip to content

Commit dcfeae4

Browse files
committed
[feature] Add user configuration for org-mode specfic S-[arrow] bindings
This commit adds a function that a prelude user can add to their personal configs that, if called, will set org-mode specific S-[arrow key] functionality in org-mode buffers instead of the default windmove keybindings. Windmove keybindings should work in all other buffers. Fixes bbatsov#1364 Alternative to bbatsov#1427
1 parent 460bc16 commit dcfeae4

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

docs/configuration.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,18 @@ to disable this behaviour, set the following variable to nil before loading prel
210210
```emacs-lisp
211211
(setq prelude-override-package-user-dir nil)
212212
```
213+
214+
### Enable org-mode shift arrow Keybindings
215+
By default, windmove keybindings take precedence for binding to the S+[arrow] keys.
216+
Org-mode keybindings are overridden. This is a [know issue][1] described in org-mode's
217+
manual.
218+
219+
[1]: https://orgmode.org/manual/Conflicts.html
220+
221+
To have org-mode S+[arrow key] keybindings in org buffers, add this to your configs:
222+
223+
```lisp
224+
(prelude-enable-org-mode-shift-bindings)
225+
```
226+
227+
Other buffers should continue to be bound to windmove keybindings.

modules/prelude-org.el

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,42 @@
5858

5959
(add-hook 'org-mode-hook (lambda () (run-hooks 'prelude-org-mode-hook)))
6060

61+
(defun prelude-enable-org-mode-shift-bindings ()
62+
"Enable `windmove' advice to use `org-mode' shift functions in org buffers."
63+
(interactive)
64+
(message "Prelude: Installing org-mode shift key bindings to supersede windmove bindings")
65+
66+
;; Advice to redirect windmove commands to org-mode functions in org buffers
67+
(defun ap/windmove-left-advice (orig-fun &rest args)
68+
"Use `org-shiftleft' in org buffers, ORIG-FUN with ARGS elsewhere."
69+
(if (derived-mode-p 'org-mode)
70+
(org-shiftleft)
71+
(apply orig-fun args)))
72+
73+
(defun ap/windmove-right-advice (orig-fun &rest args)
74+
"Use `org-shiftright' in org buffers, ORIG-FUN with ARGS elsewhere."
75+
(if (derived-mode-p 'org-mode)
76+
(org-shiftright)
77+
(apply orig-fun args)))
78+
79+
(defun ap/windmove-up-advice (orig-fun &rest args)
80+
"Use `org-shiftup' in org buffers, ORIG-FUN with ARGS elsewhere."
81+
(if (derived-mode-p 'org-mode)
82+
(org-shiftup)
83+
(apply orig-fun args)))
84+
85+
(defun ap/windmove-down-advice (orig-fun &rest args)
86+
"Use `org-shiftdown' in org buffers, ORIG-FUN with ARGS elsewhere."
87+
(if (derived-mode-p 'org-mode)
88+
(org-shiftdown)
89+
(apply orig-fun args)))
90+
91+
;; Apply advice to all windmove functions
92+
(advice-add 'windmove-left :around #'ap/windmove-left-advice)
93+
(advice-add 'windmove-right :around #'ap/windmove-right-advice)
94+
(advice-add 'windmove-up :around #'ap/windmove-up-advice)
95+
(advice-add 'windmove-down :around #'ap/windmove-down-advice))
96+
6197
(provide 'prelude-org)
6298

6399
;;; prelude-org.el ends here

0 commit comments

Comments
 (0)