~soywod/pimalaya#204: 
Error when listing E-Mails on vim

After installing himalaya-vim under

~/.vim/pack/plugins/start/himalaya-vim

and running :Himalaya I get the following errors:

Fetching INBOX envelopes… ^[[31mError:^[[0m cannot parse search emails query INBOX ^[[38;5;246m╭^[[0m^[[38;5;246m─^[[0m^[[38;5;246m[^[[0mquery:1:1^[[38;5;246m]^[[0m ^[[38;5;246m│^[[0m ^[[38;5;246m1 │^[[0m ^[[31mI^[[0m^[[38;5;249mN^[[0m^[[38;5;249mB^[[0m^[[38;5;249mO^[[0m^[[38 ;5;249mX^[[0m ^[[38;5;240m │^[[0m ^[[31m┬^[[0m
^[[38;5;240m │^[[0m ^[[31m╰^[[0m^[[31m─^[[0m^[[31m─^[[0m found I expected not, date, b efore, after, from, to, subject, body, flag, or (nested filter) ^[[38;5;246m───╯^[[0m Error detected while processing function 6[1]..41_on_close[6]..function 6[1]..41_on_close: line 6: E605: Exception not caught: CLI error, see :messages for more information

This is only after fixing the typo for which I already sent a patch here[0]. Before that it didn't start either, but it showed a message related to the typo fixed with the patch.

I'm using vim version 9.1. Please let me know if you need the output of vim --version (not included here as it is quite long).

[0] https://lists.sr.ht/~soywod/pimalaya/patches/51673

Status
REPORTED
Submitter
Johannes Thyssen Tishman
Assigned to
No-one
Submitted
2 months ago
Updated
a month ago
Labels
No labels applied.

Johannes Thyssen Tishman 2 months ago · edit

The errors seems to come from the on_close function under:

~/.vim/pack/plugins/start/himalaya-vim/autoload/himalaya/job/vim8.vim

~m15a referenced this from #206 2 months ago

~m15a 2 months ago

This fixes the problem for me:

diff --git a/autoload/himalaya/domain/email.vim b/autoload/himalaya/domain/email.vim
index 25a2fa6..9fcc70f 100644
--- a/autoload/himalaya/domain/email.vim
+++ b/autoload/himalaya/domain/email.vim
@@ -16,7 +16,7 @@ endfunction

 function! himalaya#domain#email#list_with(account, folder, page) abort
   call himalaya#request#plain({
-  \ 'cmd': 'envelope list --account %s --max-width %d --page-size %d --page %d %s',
+  \ 'cmd': 'envelope list --account %s --max-width %d --page-size %d --page %d --folder %s',
   \ 'args': [shellescape(a:account), s:bufwidth(), winheight(0) - 1, a:page, shellescape(a:folder)],
   \ 'msg': printf('Fetching %s envelopes', a:folder),
   \ 'on_data': {data -> s:list_with(a:folder, a:page, data)}

Johannes Thyssen Tishman 2 months ago · edit

2024-05-12T07:37:24Z "~m15a" outgoing@sr.ht:

This fixes the problem for me:

diff --git a/autoload/himalaya/domain/email.vim b/autoload/himalaya/domain/email.vim
index 25a2fa6..9fcc70f 100644
--- a/autoload/himalaya/domain/email.vim
+++ b/autoload/himalaya/domain/email.vim
@@ -16,7 +16,7 @@ endfunction

 function! himalaya#domain#email#list_with(account, folder, page) abort
   call himalaya#request#plain({
-  \ 'cmd': 'envelope list --account %s --max-width %d --page-size %d --page %d %s',
+  \ 'cmd': 'envelope list --account %s --max-width %d --page-size %d --page %d --folder %s',
   \ 'args': [shellescape(a:account), s:bufwidth(), winheight(0) - 1, a:page, shellescape(a:folder)],
   \ 'msg': printf('Fetching %s envelopes', a:folder),
   \ 'on_data': {data -> s:list_with(a:folder, a:page, data)}

Indeed this seems to fix the listing of E-Mails. However, I still get some other errors on some actions. E.g.:

When changing folders with 'gm' or trying to move or copy a message with 'gM' and 'gC':

Listing folders…
error: unrecognized subcommand 'list'
Usage: himalaya [OPTIONS] [COMMAND]
For more information, try '--help'.
Error detected while processing function <lambda>26[1]..<SNR>37_on_close[6].
.function <lambda>26[1]..<SNR>37_on_close:
line    6:
E605: Exception not caught: CLI error, see :messages for more information

Also when replying to an E-Mail with 'gr', the message window is opened as expected (not as a tile as I would expect, but full screen), but when I save and close the file, I don't get prompted to send cancel or anything as when I'm writing a new mail (which works properly and opens as a tile too).

Is this only on Vim? Seems very buggy.

~soywod 2 months ago

After installing himalaya-vim and running :Himalaya I get the following errors: […]

I forgot to merge the v1.0.0-beta.4 branch into master, hence the errors. I just did it, could you try again?

https://git.sr.ht/~soywod/himalaya-vim/commit/ba760afa1eb3af5354a709f30ebdac8269f2a1ba

-- Regards Clément DOUIN https://soywod.me

Johannes Thyssen Tishman 2 months ago · edit

2024-05-15T09:08:27Z "~soywod" outgoing@sr.ht:

After installing himalaya-vim and running :Himalaya I get the following errors: […]

I forgot to merge the v1.0.0-beta.4 branch into master, hence the errors. I just did it, could you try again?

https://git.sr.ht/~soywod/himalaya-vim/commit/ba760afa1eb3af5354a709f30ebdac8269f2a1ba

Yes, the listing is now working. However when replying to a message I'm getting a weird behaviour. First, the buffer is not opened as a split like it is done when writing a new message, but it takes over the current buffer. Is this intentional? And second, when I exit the buffer, I don't get a prompt for sending, saving as draft quiting or canceling. Vim exits and I have no clue what happens.

~soywod 2 months ago

However when replying to a message I'm getting a weird behaviour. First, the buffer is not opened as a split like it is done when writing a new message, but it takes over the current buffer. Is this intentional?

Mmmh this is strange, and I cannot reproduce this behaviour. Can you describe your replying flow?

And second, when I exit the buffer, I don't get a prompt for sending, saving as draft quiting or canceling. Vim exits and I have no clue what happens.

Same, I do not reproduce this behaviour. When I :bd (even ZZ) it prompts me the action. It may be related to the first issue, somehow it could prevent the prompting.

I precise that I performed tests on Vim 9.0.1811, with the master branch of the plugin and v1.0.0-beta.4 CLI.

-- Regards Clément DOUIN https://soywod.me

Johannes Thyssen Tishman a month ago · edit

2024-05-18T09:08:40Z "~soywod" outgoing@sr.ht:

However when replying to a message I'm getting a weird behaviour. First, the buffer is not opened as a split like it is done when writing a new message, but it takes over the current buffer. Is this intentional?

Mmmh this is strange, and I cannot reproduce this behaviour. Can you describe your replying flow?

Sure. For testing I've removed my .vimrc and only cloned the himalaya-vim plugin:

$ tree -L 4 ~/.vim
/home/johannes/.vim
`-- pack
    `-- plugins
        |-- opt
        `-- start
            `-- himalaya-vim

5 directories, 0 file

Now I do the following:

$ vim
:Himalaya<Enter>
jgr

The reply buffer opens but it takes over the window completely. After that I press ZZ to save and exit and vim exits completely.

And second, when I exit the buffer, I don't get a prompt for sending, saving as draft quiting or canceling. Vim exits and I have no clue what happens.

Same, I do not reproduce this behaviour. When I :bd (even ZZ) it prompts me the action. It may be related to the first issue, somehow it could prevent the prompting.

Yeah ZZ and :wq do not work. However :bd is working, but then I have to 'set hidden' because otherwise the email listing is gone after exiting.

I precise that I performed tests on Vim 9.0.1811, with the master branch of the plugin and v1.0.0-beta.4 CLI.

$ himalaya --version
himalaya 1.0.0-beta.4

$ git -C /home/johannes/.vim/pack/plugins/start/himalaya-vim log | head -n1
commit afe37d38509f347e93757910875984b48baa34f0

$ vim --version | head -n1
VIM - Vi IMproved 9.1 (2024 Jan 02, compiled May 19 2024 10:38:04)

~soywod a month ago

Yeah ZZ and :wq do not work. However :bd is working, but then I have to 'set hidden' because otherwise the email listing is gone after exiting.

Wait, I remember sth about set hidden. It was highly recommended to set it up:

https://git.sr.ht/~soywod/himalaya-vim#configuration

The plugin listens to the BufLeave event, which is not triggered when set hidden is not defined.

https://git.sr.ht/~soywod/himalaya-vim/tree/master/item/ftplugin/himalaya-email-writing.vim#L17

It may be the cause of your issue.

-- Regards Clément DOUIN https://soywod.me

Johannes Thyssen Tishman a month ago · edit

2024-05-22T14:07:09Z ~soywod outgoing@sr.ht:

Wait, I remember sth about set hidden. It was highly recommended to set it up:

https://git.sr.ht/~soywod/himalaya-vim#configuration

The plugin listens to the BufLeave event, which is not triggered when set hidden is not defined.

https://git.sr.ht/~soywod/himalaya-vim/tree/master/item/ftplugin/himalaya-email-writing.vim#L17

It may be the cause of your issue.

Yes, I've tested with that setting already, and the window is still not being tiled when replying to an e-mail.

Johannes Thyssen Tishman a month ago · edit

Yeah ZZ and :wq do not work. However :bd is working, but then I have to 'set hidden' because otherwise the email listing is gone after exiting.

Okay I know what is going on now. When only the email listing is open, pressing gr on any email will take over the whole window as I've explained before, because it is opened with the command :silent! edit <bufname> as it can be seen here[1]. This will cause any Z{Z,Q} or :{,w}q to exit vim as the current window is the only window.

Reproduction steps:

$ vim
:Himalaya<CR>
jgr
ZQ

The only alternative is to use set hidden and :bd instead. Using :silent! edit <bufname> only makes sense when we want to reply to an email that we are already reading in its separate split. In this case, instead of opening another split, we do want to take over the window where we are reading the email.

What we could do is try to check if we have a single window or more. In case of a single window (email listing) we split and in case of more than one (reading email) we replace the window. E.g.:

diff --git a/autoload/himalaya/domain/email.vim b/autoload/himalaya/domain/email.vim
index dc6661a..291a86c 100644
--- a/autoload/himalaya/domain/email.vim
+++ b/autoload/himalaya/domain/email.vim
@@ -138,7 +138,11 @@ function! s:write(msg, email) abort
   if a:msg == 'write'
     execute printf('silent! botright new %s', bufname)
   endif
-  execute printf('silent! edit %s', bufname)
+  if winnr('$') == 1
+	  execute printf('silent! botright split %s', bufname)
+  else
+	  execute printf('silent! edit %s', bufname)
+  endif
   setlocal modifiable
   silent execute '%d'
   call append(0, split(substitute(a:email, "\r", '', 'g'), "\n"))

However I'm not sure this is the best way to handle this.

[1] https://git.sr.ht/~soywod/himalaya-vim/tree/master/item/autoload/himalaya/domain/email.vim#L138-141

~soywod a month ago

Reproduction steps:

:Himalaya jgr ZQ

Indeed I am able to reproduce the same behaviour, both on Vim and Neovim.

What we could do is try to check if we have a single window or more. In case of a single window (email listing) we split and in case of more than one (reading email) we replace the window.

I applied your patch, I think it is a good enough solution. Thank you for digging the issue and find a solution!

-- Regards Clément DOUIN https://soywod.me

Register here or Log in to comment, or comment via email.