# vim: filetype=neomuttrc
bind index \Cf noop
bind index,pager i noop
bind index,pager g noop

# General rebindings
bind index j next-entry
bind index k previous-entry
bind index G last-entry
bind index U undelete-message
bind index L limit
bind index h noop
bind index l display-message
bind index gg first-entry
bind index \031 previous-undeleted	# Mouse wheel
bind index \005 next-undeleted		# Mouse wheel

bind pager j next-line
bind pager k previous-line
bind pager l view-attachments
bind pager \031 previous-line		# Mouse wheel
bind pager \005 next-line		# Mouse wheel

bind attach <return> view-mailcap
bind attach l view-mailcap

bind editor <space> noop
bind editor <Tab> complete-query

bind browser l select-entry

bind index,pager D delete-message
bind index,pager H view-raw-message
bind index,query <space> tag-entry
bind index,pager S sync-mailbox
bind index,pager R group-reply

bind pager,browser gg top-page
bind pager,browser G bottom-page

bind pager,attach h exit

bind index,pager,browser d half-down
bind index,pager,browser u half-up

# View an attachment in the GUI browser
macro attach \cv "\
<enter-command> set my_pipe_decode=\$pipe_decode pipe_decode<Enter>\
<pipe-message> attachview<Enter>\
<enter-command> set pipe_decode=\$my_pipe_decode; unset my_pipe_decode<Enter>" \
"Open attachment in GUI browser"

macro pager \Cs "<shell-escape>rm -f /tmp/mutt-patch.diff<enter><copy-message>/tmp/mutt-patch.diff<enter><enter-command>echo 'Saved as /tmp/mutt-patch.diff'<enter><shell-escape> portpatch /tmp/mutt-patch.diff<enter>"

macro index \Cr "T~U<enter><tag-prefix><clear-flag>N<untag-pattern>.<enter>" "mark all messages as read"
macro index O "<shell-escape>mbsync -c ~/.config/isync/mbsyncrc -a<enter>" "run mbsync to sync all mail"
macro index \Cf "<enter-command>unset wait_key<enter><shell-escape>read -p 'Enter a search term to find with notmuch: ' x; echo \$x >~/.cache/mutt_terms<enter><limit>~i \"\`notmuch search --output=messages \$(cat ~/.cache/mutt_terms) | head -n 600 | perl -le '@a=<>;s/\^id:// for@a;$,=\"|\";print@a' | perl -le '@a=<>; chomp@a; s/\\+/\\\\+/ for@a;print@a' \`\"<enter>" "show only messages matching a notmuch pattern"
macro index A "<limit>all\n" "show all messages (undo limit)"

macro browser h '<change-dir><kill-line>..<enter>' "Go to parent folder"

macro index,pager <f1> '<sync-mailbox><enter-command>source ~/.config/neomutt/accounts/dgy@fuckup.club.muttrc<enter><change-folder>!<enter>;<check-stats>' "switch to dgy@fuckup"
macro index,pager <f2> '<sync-mailbox><enter-command>source ~/.config/neomutt/accounts/dgy@texto-plano.xyz.muttrc<enter><change-folder>!<enter>;<check-stats>' "switch to dgy@t-p"
