-
Notifications
You must be signed in to change notification settings - Fork 64
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
System.Filepath: Add to_slash() and from_slash() #586
Conversation
* Thanks AppVeyor! https://ci.appveyor.com/project/vim-jp/vital-vim/build/1650/job/spfc820d1dq2twc8 * This is why we need this function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return substitute(a:path, '/', '\', 'g') | ||
endif | ||
return a:path | ||
endfunction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go の path/filepath.ToSlash()
の実装を見てみました。
Go のソースコードは BSD なので、厳密にいうと ujihisa さんが見てしまうとライセンス違反な気もするので、自分が日本語で説明します。
Go の実装は、vital のコードでいうと s:separator() ==# '/'
ならそのまま return、そうでないなら s:separator()
を /
に置換する感じです (ちなみに置換は tr()
使うと \V
でエスケープ不要になるのと短くなるので良さそう)。
Go のはおそらくパスセパレータが /
と \
だけじゃない環境も考慮してるんだと思います (VMS とか古い Mac とか :
だった気がする。まぁ vital でそこまでやるかという話ではありますが…)。
path/filepath.FromSlash()
はセパレータが /
なら return するのは同じですが、 /
-> s:separator()
の逆パターンですね。
あと、スクリプトのトップレベルでセパレータ文字列をチェックして、 /
なら引数そのまま return な function を定義すると無駄なオーバーヘッドが無くなって良さそうです。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2コミット積んで対応しました。(VMSと古いMacの対応はとくになし)
* Switch function definition itself, assuming the OS doesn't change while Vim is up * Thanks @tyru!
@@ -6,6 +6,26 @@ | |||
let s:save_cpo = &cpo | |||
set cpo&vim | |||
|
|||
if has('win32') || has('win64') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
下で s:is_windows
定義してるのでそれ使うと良さそう?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(windowsに詳しくないのでwindowsに詳しい人の意見欲しい) それだとwin16とwin95も入っちゃうけど大丈夫かな?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
そもそも @h-east さんによると has('win32') || has('win64')
は has('win32')
だけでいいそうです (help にもそう書いてある)。
win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
64 bits)
win64 Win64 version of Vim (MS-Windows 64 bit).
win95 Win32 version for MS-Windows 95/98/ME.
つまり win32
は win95
と win64
を含む Windows の判定として使えます (今調べて気付いた)。
そして win16
に至ってはそもそも feature-list に残ってすらいない (help は 7.4.1382, 実装は 7.4.1375, 7.4.1368, 7.4.1364 で削除済み) ので、総括すると以下の判定でいいという事になります。
修正前: let s:is_windows = has('win16') || has('win32') || has('win64') || has('win95')
修正後: let s:is_windows = has('win32')
feature-list の判定の実装
そもそも has('win32')
がどういう場合に non-zero になるか気になったので調べたら、以下のようになっていました。
win32
:WIN32
マクロが定義されている場合に non-zerowin64
:WIN64
あるいは_WIN64
マクロが定義されている場合に non-zerowin95
: feature-list にはあるみたいですが、実装は見つけられませんでした。もしかして既にサポート切られてドキュメントが古い?
@k-takata さんが言ってたんですが、64bitであっても WIN32
, _WIN32
は定義されるため、help の言う通り 64bit でも win32
だけで non-zero を返します。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8.0.0029 で WinXP より前のサポートは打ち切られました。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
なるほど。win95 が無いのはそのせいでしたか。
win95 が help に残ってる件について Bram に尋ねてみたら、「過去あった物なので残してる (今は常に false を返す点については追記しておく)」との事だったので、「win16 も過去あったよ」とだけ伝えました (なので復元するべき、まで伝えるべきでした…)。
https://groups.google.com/d/msg/vim_dev/owxmPRf_Pog/plmWQZLSBQAJ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dos16, dos32, os2 も復活させるべき。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
おおーなるほど、こうなってたんですね!
とりあえず派生pullreq作ってみました。主目的は上記議論のdocument化です #589
ひとまずそこではwin16, dos{16,32}, os2はスルーしてます。
endfunction | ||
endif | ||
|
||
if has('win32') || has('win64') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
下で s:is_windows
定義してるのでそれ使うと良さそう?
7e54598 にて、既存の 現状まとめ:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
3年越しの新機能がついに入りました 👏 |
@mattn++ and @lambdalisue++
3年前から眠っていた #358 を古の眠りから覚まして改めて作ってみました。
mattnさんのコミットをベースに、document書いてtest追加したものがこちらとなっております。
#358 の方針のとおり。名前変えようという話もあったけど、3年そのままだったし、このままでまずマージするのがよさそうな気がしてます。