Skip to content

Commit fd12571

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 fd12571

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
### New features
88

9+
- [PR 1443] (https://github.com/bbatsov/prelude/pull/1443): Add user configuration for `org-mode` specfic `S-[arrow]` bindings.
910
- [PR 1432](https://github.com/bbatsov/prelude/pull/1432): Allow directories of custom Emacs Lisp files in `personal/preload`.
1011
- Enable `org-habits`.
1112
- Neatly track `TODO` state changes in a drawer (LOGBOOK), thereby improving readability.

docs/configuration.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,19 @@ 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+
216+
By default, windmove keybindings take precedence for binding to the S+[arrow] keys.
217+
Org-mode keybindings are overridden. This is a [know issue][1] described in org-mode's
218+
manual.
219+
220+
[1]: https://orgmode.org/manual/Conflicts.html
221+
222+
To have org-mode S+[arrow key] keybindings in org buffers, add this to your configs:
223+
224+
```lisp
225+
(prelude-enable-org-mode-shift-bindings)
226+
```
227+
228+
Other buffers should continue to be bound to windmove keybindings.

docs/modules/orgmode.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ It establishes a few extra keybidings:
1313
- `C-c a` (`org-agenda`)
1414
- `C-c b` (`org-switchb`)
1515

16+
### Shift-arrow keybinding conflicts
17+
18+
Windmove arrow keybindings are the defualt for Prelude, but org-mode has some
19+
specific bindings for ath S-[arrow keys].
20+
21+
If a user adds the following code, org-mode buffers will have standard org-mode
22+
bindings, but other buffers will use windmove bindings.
23+
24+
```lisp
25+
(prelude-enable-org-mode-shift-bindings)
26+
```
27+
1628
## org-habits
1729

1830
It enables [org-habits](https://orgmode.org/manual/Tracking-your-habits.html "org-habits") and [tracks TODO state changes](https://orgmode.org/manual/Tracking-TODO-state-changes.html "todo-state-changes") into a

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)