gioele / vim-autoswap

Please Vim, stop with these swap file messages. Just switch to the correct window!
Creative Commons Zero v1.0 Universal
115 stars 25 forks source link

Using other terminals on macOS, Terminal still opens #11

Closed eriknomitch closed 5 years ago

eriknomitch commented 7 years ago

I'm on macOS and using Hyper terminal and when autoswap is activated, Terminal.app opens and the autoswap never happens.

Looking at this issue, it looks like Terminal is hardcoded in.

Although I'm unsure as to why the Apple script is necessary, as a proposed fix, you could use the environment variable TERM_PROGRAM instead of the hardcoded Terminal line.

gioele commented 6 years ago

Hi @eriknomitch, thank you for the suggestion. I implemented support for arbitrary terminal applications on MacOS in commit daa59dd48de3d370304b854166183228ed69d095, part of the branch any-terminal-macos.

Could you please test the branch and tell me if everything is fine? I do not currently have access to a MacOS workstation.

Hi @CharlesPatterson, I see that you have a fork for vim-autoswap modified to support iTerm2. The code in this branch should work for iTerm2 as well. Does it?

rlue commented 6 years ago

Hi @gioele, I've tried this in iTerm but unfortunately it's not working for me.

I'm also experiencing a lot of latency (#15), but I don't know if those issues are related.

gioele commented 6 years ago

Hi @rlue, could you check out the branch any-terminal-macos-verbose-debug and paste here the content of /tmp/vim-autoswap.log?

I do not have access to a MacOS box, so the changes I made in this branch are just speculations for the moment. :)

rlue commented 6 years ago

In a bare terminal (iTerm 2)

When running

$ vim Projects/bodega/app/models/order.rb

in two separate tabs, the second tab opens a new instance of vim and loads the file with the warning message, "Swapfile detected... opening read-only".

# /tmp/vim-autoswap.log
1502418805

Starting session 1502418805
1502418805 testing already loaded?...
1502418805  ...no, set variable
1502418805 testing tmux support set?...
1502418805  ...yes, tmux detection may be attempted later
1502418811

Starting session 1502418811
1502418811 testing already loaded?...
1502418811  ...no, set variable
1502418811 testing tmux support set?...
1502418811  ...yes, tmux detection may be attempted later
1502418811 swapfile callback called
1502418811 a:filename = >/Users/rlue/Projects/bodega/app/models/order.rb<
1502418811 a:swapname = >/Users/rlue/.config/.vim/swap/order.rb.swp<
1502418811 g:autoswap_detect_tmux = 1
1502418811 testing is $TMUX set?...
1502418811  ...no, tmux is not running
1502418811 AS_RunningTmux() = 0
1502418811 has('macunix') = 1
1502418811 has('unix') = 1
1502418811 detecting active window...
1502418811 testing is $TMUX set?...
1502418811  ...no, tmux is not running
1502418811  ...on mac...
1502418811 mac: shortname = >order.rb<
1502418811 codename = iTerm.app
1502418811 mac: terminal_app_name = >iTerm2<
1502418812 mac: active_name = >
<
1502418812 mac: active_name = >
<
1502418812  ...active_window = ><
1502418812 detected active window = <>
1502418812 Swapfile detected... opening read-only

in tmux

when attempting the same command as above in two separate tmux panes, vim-autoswap works as expected BUT I'm seeing about a 4-second lag (not as severe as when reported in issue #15, but still noticeable).

# /tmp/vim-autoswap.log

1502418948

Starting session 1502418948
1502418948 testing already loaded?...
1502418948  ...no, set variable
1502418948 testing tmux support set?...
1502418948  ...yes, tmux detection may be attempted later
1502418955

Starting session 1502418955
1502418955 testing already loaded?...
1502418955  ...no, set variable
1502418955 testing tmux support set?...
1502418955  ...yes, tmux detection may be attempted later
1502418955 swapfile callback called
1502418955 a:filename = >/Users/rlue/Projects/bodega/app/models/order.rb<
1502418955 a:swapname = >/Users/rlue/.config/.vim/swap/order.rb.swp<
1502418955 g:autoswap_detect_tmux = 1
1502418955 testing is $TMUX set?...
1502418955  ...yes, to >/private/tmp/tmux-501/default,13269,0<, tmux is running
1502418955 AS_RunningTmux() = 1
1502418955 has('macunix') = 1
1502418955 has('unix') = 1
1502418955 detecting active window...
1502418955 testing is $TMUX set?...
1502418955  ...yes, to >/private/tmp/tmux-501/default,13269,0<, tmux is running
1502418955  ...on tmux...
1502418958 tmux: pid = >16566<
1502418958 tmux: tty = >s006 <
1502418958 tmux: window = >/dev/ttys006 2 0<
1502418958  ...active_window = >/dev/ttys006 2 0<
1502418958 detected active window = </dev/ttys006 2 0>
1502418958 Switched to existing session in another window
1502418958 g:autoswap_detect_tmux = 1
1502418958 testing is $TMUX set?...
1502418958  ...yes, to >/private/tmp/tmux-501/default,13269,0<, tmux is running
1502418958 AS_RunningTmux() = 1
1502418958 has('macunix') = 1
1502418958 has('unix') = 1
1502418958 testing is $TMUX set?...
1502418958  ...yes, to >/private/tmp/tmux-501/default,13269,0<, tmux is running
1502418958 tmux command >tmux select-window -t 2; tmux select-pane -t 0< exited with code 0