Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C-w C-w with Agenda List #13197

Closed
Matelasse opened this issue Jan 22, 2020 · 16 comments
Closed

C-w C-w with Agenda List #13197

Matelasse opened this issue Jan 22, 2020 · 16 comments

Comments

@Matelasse
Copy link

Description :octocat:

C-w C-w doesnt work when you have Agenda List open

Reproduction guide 🪲

Start spacemacs and open some orgfile, also open agenda-list in a split window (M-x org-agenda-list). Now you want to move between the windows using C-w C-w, but it doesnt work. Emacs C-x o does work though.
Observed behaviour: 👀 💔
C-w C-w doesnt move between windows. C-x o does.

Expected behaviour: ❤️ 😄
C-w C-w should move between windows, like C-x.

System Info 💻

  • OS: gnu/linux
  • Emacs: 26.3
  • Spacemacs: 0.200.13
  • Spacemacs branch: master (rev. 26b8fe0)
  • Graphic display: t
  • Distribution: spacemacs
  • Editing style: vim
  • Completion: helm
@duianto
Copy link
Collaborator

duianto commented Jan 22, 2020

Confirmed, the evil-state in the agenda buffer is evilified where C-w isn't bound, therefore it seems to use the default Emacs command from the global-map, kill-region, but it has no effect since the agenda buffer is in read-only state. It doesn't seem like an appropriate command for the agenda buffer anyway.

A fix is to bind:

      (kbd "C-w") 'evil-window-map

in the org/init-org-agenda functions:

    :config
    (evilified-state-evilify-map org-agenda-mode-map

section.

But this would only fix it in the agenda buffer, I suspect that the same issue is occurring in most/all evilified buffers. So it would probably better to have a more "global" solution.

However I'll open a PR that fixes it in this case. If someone comes up with a general solution then it can be used instead.

@nixmaniack
Copy link
Contributor

I suspect that the same issue is occurring in most/all evilified buffers.

I have experienced this.

If someone comes up with a general solution then it can be used instead.

@duianto Here 👇

;; default key bindings for all evilified buffers
(define-key evil-evilified-state-map "/" 'evil-search-forward)
(define-key evil-evilified-state-map ":" 'evil-ex)
(define-key evil-evilified-state-map "h" 'evil-backward-char)

Patch with this 👇?

(define-key evil-evilified-state-map (kbd "C-w") 'evil-window-map)

@duianto
Copy link
Collaborator

duianto commented Jan 22, 2020

That seems to be the right solution 👍
@nixmaniack if want to open a new PR then I can test and merge it.

@nixmaniack
Copy link
Contributor

@duianto Sure, I'll make a PR.

@duianto
Copy link
Collaborator

duianto commented Jan 22, 2020

Thanks nixmaniack.

@Matelasse This has now been fixed on the Spacemacs develop branch.

Your system info shows that your on the master branch.

develop is the recommended branch until the next version is released.

If you want to get this fix and a lot of other changes now:
https://github.com/syl20bnr/spacemacs/blob/develop/CHANGELOG.develop

Backup your current setup and make sure that there isn't a .emacs.d directory or a .spacemacs file in your home directory, then clone directly to the develop branch with:

git clone -b develop https://github.com/syl20bnr/spacemacs ~/.emacs.d

@Matelasse
Copy link
Author

Matelasse commented Jan 22, 2020

I went to sleep and woke up to a delivered fix. You guys are insane, thanks so much.

@Matelasse
Copy link
Author

I made sure to install the develop branch, which includes the commit that should've fixed this, but I'm still experiencing the same. Did anyone check if the fix worked for them?

@nixmaniack
Copy link
Contributor

Did anyone check if the fix worked for them?

Yes, I did verify. @duianto do you see any issue?

  • What's the behaviour after upgrading with develop?
  • Also, while in org-agenda, can you check what C-w C-w is bound to? You should be able to do that with SPC h d k then typing C-w C-w.
  • And, can you get the value of (lookup-key evil-evilified-state-map (kbd "C-w"))? You can execute previous snippet with M-: and paste the value it returns. It should be evil-window-map.

@duianto
Copy link
Collaborator

duianto commented Jan 23, 2020

Did anyone check if the fix worked for them?

Yes, I tested it before applying it to the develop branch.
I didn't and still don't see any issues.

C-w C-w switches to another window from the org agenda buffer.

SPC h d k C-w C-w shows:

C-w C-w runs the command evil-window-next, which is an interactive compiled Lisp
function in ‘evil-commands.el’.

It is bound to C-w C-w, C-w w, <evilified-state> C-w C-w, <evilified-state> C-w
w.

(evil-window-next COUNT)

Move the cursor to the next window in the cyclic order.
With COUNT go to the count-th window in the order starting from
top-left.

And evaluating (at the M-: prompt):
(lookup-key evil-evilified-state-map (kbd "C-w"))
shows: evil-window-map


I think I found the cause, C-w is bound to kill-region when the Spacemacs org layer isn't installed.

Because the evil-state is emacs in the org agenda buffer.

@nixmaniack
Copy link
Contributor

I think I found the cause, C-w is bound to kill-region when the Spacemacs org layer isn't installed.

Because the evil-state is emacs in the org agenda buffer.

Nice finding.

I'm not sure what is the right fix for this. In absence of full org layer, there's spacemacs-org which adds light integration with org mode to support doc viewing etc so not much evilification is done in that layer.

In case a person needs full-fledged org (with org-agenda etc.) with evil integration, then org layer provides that. I'm unsure if backporting org layer stuff to spacemacs-org layer makes sense to fix this (personally not in favour).

@Matelasse
Copy link
Author

Matelasse commented Jan 23, 2020

Did anyone check if the fix worked for them?

Yes, I did verify. @duianto do you see any issue?

  • What's the behaviour after upgrading with develop?
  • Also, while in org-agenda, can you check what C-w C-w is bound to? You should be able to do that with SPC h d k then typing C-w C-w.
  • And, can you get the value of (lookup-key evil-evilified-state-map (kbd "C-w"))? You can execute previous snippet with M-: and paste the value it returns. It should be evil-window-map.
  • Same behavior
  • C-w C-w runs the command evil-window-next (found in evil-motion-state-map),
    which is an interactive compiled Lisp function in ‘evil-commands.el’.
    It is bound to C-w C-w, C-w w.
    (evil-window-next COUNT)
    Move the cursor to the next window in the cyclic order.
    With COUNT go to the count-th window in the order starting from
    top-left.
  • evil-window-map

I notice that when I first click C-w before chording it to another C-w, the following message gets displayed in the status bar: Buffer is read-only: #<buffer *Org Agenda*>, so it seems to me like it is unable to chord these two clicks

@Matelasse
Copy link
Author

Did anyone check if the fix worked for them?

Yes, I tested it before applying it to the develop branch.
I didn't and still don't see any issues.

C-w C-w switches to another window from the org agenda buffer.

SPC h d k C-w C-w shows:

C-w C-w runs the command evil-window-next, which is an interactive compiled Lisp
function in ‘evil-commands.el’.
It is bound to C-w C-w, C-w w, C-w C-w, C-w
w.
(evil-window-next COUNT)
Move the cursor to the next window in the cyclic order.
With COUNT go to the count-th window in the order starting from
top-left.

And evaluating (at the M-: prompt):
(lookup-key evil-evilified-state-map (kbd "C-w"))
shows: evil-window-map

I think I found the cause, C-w is bound to kill-region when the Spacemacs org layer isn't installed.

Because the evil-state is emacs in the org agenda buffer.

I confirm that after installing adding org layer in my configuration this is no longer an issue. What do we want to do here?

@duianto
Copy link
Collaborator

duianto commented Jan 23, 2020

The reason you got the message:

Buffer is read-only: #<buffer Org Agenda>

when you press C-w, was because the org agenda buffer is in read-only mode.
In the cases you've tested, C-w was bound to kill-region which tries to kill the current region. But it isn't possible to edit a read-only buffer.


This seems to work to evilify the org agenda buffer, even when the org layer isn't installed:

      (defun spacemacs/evilify-org-agenda-buffer ()
        (when (memq dotspacemacs-editing-style '(hybrid vim))
          (evil-evilified-state)))
      (add-hook 'org-agenda-finalize-hook 'spacemacs/evilify-org-agenda-buffer)

It only evilifies the org agenda buffer when either the hybrid or vim editing styles are used.

But I'm not sure where it could be added.

While testing I tried these two org agenda hooks:
org-agenda-mode-hook
org-agenda-after-show-hook
with either of these two commands:
(evil-evilified-state)
(evil-force-evilified-state)
but I didn't find any combination of the hooks or commands that worked.

Then I found the org-agenda-finalize-hook and it works in the example above.

@nixmaniack
Copy link
Contributor

@duianto The question remains whether such org-agenda specific evil customization be brought into spacemacs-org layer (which provides lightweight customizations required to render spacemacs org docs and not customizations related to org ecosystem). If we can finalize on that, then the solution can go in spacemacs-org.

Also, I have a doubt if the solution would behave nicely with C-z (toggle between vim/hybrid and emacs styles at runtime).

@duianto
Copy link
Collaborator

duianto commented Jan 26, 2020

Another option might the spacemacs-evil layer, one of the listed features is:

Evilification of various modes if the editing style is vim or hybrid

https://github.com/syl20bnr/spacemacs/tree/develop/layers/+spacemacs/spacemacs-evil


Your might be right that there could be issues with this solution if the editing style is switched with C-z or with the keys under the prefix SPC t E after Spacemacs has been started.

It would be ideal to have as many of the evil bindings as possible work everywhere when the vim editing style is chosen.

But if someone is calling M-x org-agenda-list then they would probably want to use the org layer which also adds a key binding for it.

So maybe the advice should be to use the org layer.

@Matelasse
Copy link
Author

My issue was resolved by installing the org layer, so I will close this issue. Thanks for the discussion, everyone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants