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

1.8.0 breaks escape sequence of keys #246

Closed
teoljungberg opened this issue Sep 18, 2017 · 4 comments
Closed

1.8.0 breaks escape sequence of keys #246

teoljungberg opened this issue Sep 18, 2017 · 4 comments

Comments

@teoljungberg
Copy link
Contributor

I'm unsure the title is correct or not, but pick 1.8.0 broke the arrow keys inside of my vim. And my feeling is that an escape sequence got trickled.

Version: v1.8.0 (not reproducible in v1.7.0)

After a git bisect, I found the error to be in 2d57016.

Reproduction steps:

git bisect:

% git bisect start
% git bisect good v1.7.0
% git bisect bad v1.8.0
Bisecting: 24 revisions left to test after this (roughly 5 steps)
[1cdf59294ed6626aae7ff25852c43eab2d5786d5] Prefix UP since it's already defined on NetBSD
% ./configure && make && vim -u test.vimrc +"call PickFile()"
# ...
pick % git bisect bad
Bisecting: 11 revisions left to test after this (roughly 4 steps)
[369eb665d59cc0374c690068a4c1f609e99c3280] Accept env vars in tests
pick % ./configure && make && vim -u test.vimrc +"call PickFile()"
pick % git bisect bad
Bisecting: 5 revisions left to test after this (roughly 3 steps)
[0c3369b1bca63928ddd73fad69ba114f97462301] Use the new CAP macro for movement keys and delete
pick % ./configure && make && vim -u test.vimrc +"call PickFile()"
pick % git bisect good
Bisecting: 2 revisions left to test after this (roughly 2 steps)
[58b17e05d58e6f8f94893433d7607591f828e995] Use reallocarray in pick-test
pick % ./configure && make && vim -u test.vimrc +"call PickFile()"
pick % git bisect skip # could not compile on macOS
Bisecting: 2 revisions left to test after this (roughly 2 steps)
[be071ece5b1fc74d9e1aa3559df988e7dbbdbc5a] Rename compat.c -> compat-reallocarray.c
pick % ./configure && make && vim -u test.vimrc +"call PickFile()"
pick % git bisect bad
Bisecting: 0 revisions left to test after this (roughly 0 steps)
[2d57016edb52ad80dc676e4466cace2e65edf373] Enable keyboard_transmit-mode for arrow keys to work with xterm
pick % ./configure && make && vim -u test.vimrc +"call PickFile()"
pick % git bisect bad
2d57016edb52ad80dc676e4466cace2e65edf373 is the first bad commit
commit 2d57016edb52ad80dc676e4466cace2e65edf373
Author: Jenz <[email protected]>
Date:   Wed Jul 5 23:40:01 2017 +0200

    Enable keyboard_transmit-mode for arrow keys to work with xterm

:100644 100644 8f538c09cfba41942b9400876364a7cfb243181d 111b15b7659f9dca588759082f62c07de3e4e378 M	pick.c

test.vimrc:

The pick.vim code is copied inside this test vimrc, and set to use the compiled version of pick inside this repository.

set nocompatible

if !exists("g:pick_executable")
  let g:pick_executable = "./pick -X"
endif

if exists("g:pick_height")
  let g:pick_executable = "env LINES=" . g:pick_height . " " . g:pick_executable
endif

function! PickCommand(choice_command, pick_args, vim_command, escapable_output)
  try
    let pick_command = a:choice_command . " | " . g:pick_executable . " " . a:pick_args
    if exists("*systemlist")
      let selection = systemlist(pick_command)[0]
    else
      let selection = substitute(system(pick_command), '\n$', '', '')
    endif
    redraw!

    if a:escapable_output > 0
      let escaped_selection = fnameescape(selection)
    else
      let escaped_selection = selection
    endif

    if v:shell_error == 0
      try
        exec a:vim_command . " " . escaped_selection
      catch /E325/
      endtry
    endif
  catch /Vim:Interrupt/
    " Swallow the ^C so that the redraw below happens; otherwise there will be
    " leftovers from pick on the screen
    redraw!
  endtry
endfunction

function! PickFile()
  call PickCommand(s:FileListCommand(), "", ":edit", 1)
endfunction

function! PickFileVerticalSplit()
  call PickCommand(s:FileListCommand(), "", ":vsplit", 1)
endfunction

function! PickFileSplit()
  call PickCommand(s:FileListCommand(), "", ":split", 1)
endfunction

function! PickFileTab()
  call PickCommand(s:FileListCommand(), "", ":tabedit", 1)
endfunction

function! PickBuffer()
  call PickBufferCommand(":buffer")
endfunction

function! PickTag()
  call PickCommand(s:TagCommand(), "", ":tag", 0)
endfunction

function! PickBufferCommand(vim_command)
  call PickCommand(s:BufferListCommand(), "", a:vim_command, 1)
endfunction

function! s:FileListCommand()
  let command = ""

  if s:IsGitRepo()
    let command = s:GitListCommand(".")
  else
    let command = "find * -type f"
  endif

  return command
endfunction

function! s:GitListCommand(file)
  return "git ls-files " . a:file . " --cached --exclude-standard --others"
endfunction

function! s:IsGitRepo()
  return system("git ls-files " . expand("%") . " --cached --exclude-standard --others --error-unmatch 2> /dev/null ; echo $?") == 0
endfunction

function! s:BufferListCommand()
  let bufnrs = filter(range(1, bufnr("$")), 'buflisted(v:val)')
  let buffers = map(bufnrs, 'bufname(v:val)')
  return 'echo "' . join(buffers, "\n") . '"'
endfunction

function! s:TagCommand()
  let tag_files = join(tagfiles(), " ")

  return "cat " . tag_files . " 2> /dev/null | awk -F$'\t' '{print $1}' | sort -u | grep -v '^!'"
endfunction

Command:

% vim -u test.vimrc

Move around, and your arrow keys should work as expected.

Then execute:

:call PickFile()

Select a file, and the arrow keys no longer work as they used to.

@teoljungberg
Copy link
Contributor Author

Worth filing in, this is on macOS 10.12.5.

mptre added a commit that referenced this issue Sep 18, 2017
Useful when running pick from within another interactive program (like
vim(1)) which does not re-enable keyboard transmit mode after executing
an external program.

Fixes #246.
@mptre
Copy link
Owner

mptre commented Sep 18, 2017

Thanks for the report and especially the bisect(!). Can reproduce with
this minimal command executed from within vim:

:echo systemlist('git ls-files | ./pick -X')

After doing some research, it seems impossible to get the current
keyboard transmit mode. Let me know if I'm wrong here.

Therefore, see #247 which adds a new option K which disables toggling
of the keyboard transmit mode. Similiar to how less does it. Let me
know if it's working for you by now.

:echo systemlist('git ls-files | ./pick -KX')

@teoljungberg
Copy link
Contributor Author

:echo systemlist('git ls-files | ./pick -X')

Why didn't I think of that... yes - that is way simpler. Thank you.

Your PR resolves the issue for me, thank you!

@mptre
Copy link
Owner

mptre commented Sep 18, 2017

Great! Planing on doing a release tomorrow.

mptre added a commit that referenced this issue Sep 19, 2017
Useful when running pick from within another interactive program (like
Vim) which does not re-enable keyboard transmit mode after executing an
external program.

Fixes #246.
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

No branches or pull requests

2 participants