Skip to content

Conversation

tesujimath
Copy link

@tesujimath tesujimath commented Jan 13, 2025

Because of keybinding clash.

Fixes #1364


Before submitting the PR make sure the following things have been done (and denote this
by checking the relevant checkboxes):

Thanks!

Simon Guest added 2 commits January 13, 2025 17:50
(define-key newmap (kbd "C-a") 'org-beginning-of-line)
(make-local-variable 'minor-mode-overriding-map-alist)
;; windmove bindings clash badly with org mode, so disable them in org mode buffers
(windmove-mode -1)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a global minor mode, so you'll disable it everywhere, not just in org-mode with this approach.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I overlooked that, sorry.

So I think there's not a straightforward way to do this, but it will have to be done by manually overriding the keybindings that windmove has installed, by poking into its code and seeing what they are. That's a shame. 😢

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few alternative suggestions how to solve this here https://www.reddit.com/r/orgmode/comments/kyj1zi/using_windmove_with_meta_and_orgmode_conflicts/, but indeed there's no very simple solution.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also a solution suggested by org-mode's team here https://orgmode.org/manual/Conflicts.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should close this PR or adapt to consider this:

;; Make windmove work in Org mode:
(add-hook 'org-shiftup-final-hook 'windmove-up)
(add-hook 'org-shiftleft-final-hook 'windmove-left)
(add-hook 'org-shiftdown-final-hook 'windmove-down)
(add-hook 'org-shiftright-final-hook 'windmove-right)

@planetmcd
Copy link

@tesujimath I have been trying this solution to have org mode shift keybindings take precedence over windmove:

;; Advice to redirect windmove commands to org-mode functions in org buffers
(defun ap/windmove-left-advice (orig-fun &rest args)
  "Use org-mode shift-left in org buffers, windmove-left elsewhere."
  (if (derived-mode-p 'org-mode)
      (org-shiftleft)
    (apply orig-fun args)))

(defun ap/windmove-right-advice (orig-fun &rest args)
  "Use org-mode shift-right in org buffers, windmove-right elsewhere."
  (if (derived-mode-p 'org-mode)
      (org-shiftright)
    (apply orig-fun args)))

(defun ap/windmove-up-advice (orig-fun &rest args)
  "Use org-mode shift-up in org buffers, windmove-up elsewhere."
  (if (derived-mode-p 'org-mode)
      (org-shiftup)
    (apply orig-fun args)))

(defun ap/windmove-down-advice (orig-fun &rest args)
  "Use org-mode shift-down in org buffers, windmove-down elsewhere."
  (if (derived-mode-p 'org-mode)
      (org-shiftdown)
    (apply orig-fun args)))

;; Apply advice to all windmove functions
(advice-add 'windmove-left :around #'ap/windmove-left-advice)
(advice-add 'windmove-right :around #'ap/windmove-right-advice)
(advice-add 'windmove-up :around #'ap/windmove-up-advice)
(advice-add 'windmove-down :around #'ap/windmove-down-advice)

Does this achieve the results you are looking for?

If so I can try to make a PR.

@tesujimath
Copy link
Author

I will try that, but not imminently sorry, am away from my computer. Thanks for posting!

planetmcd added a commit to planetmcd/prelude that referenced this pull request Aug 10, 2025
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
planetmcd added a commit to planetmcd/prelude that referenced this pull request Aug 10, 2025
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
planetmcd added a commit to planetmcd/prelude that referenced this pull request Aug 10, 2025
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
planetmcd added a commit to planetmcd/prelude that referenced this pull request Aug 10, 2025
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
planetmcd added a commit to planetmcd/prelude that referenced this pull request Aug 10, 2025
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
planetmcd added a commit to planetmcd/prelude that referenced this pull request Aug 10, 2025
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
planetmcd added a commit to planetmcd/prelude that referenced this pull request Aug 10, 2025
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
planetmcd added a commit to planetmcd/prelude that referenced this pull request Aug 10, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emacs 28.1: org-mode shift key shortcuts shadowed

4 participants