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

位置表現に offset を指定できるようにしたい #1115

Open
ichizok opened this Issue Nov 10, 2017 · 1 comment

Comments

Projects
None yet
1 participant
@ichizok
Member

ichizok commented Nov 10, 2017

内容

line({expr})    The result is a Number, which is the line number of the file
                position given with {expr}.  The accepted positions are:
                    .       the cursor position
                    $       the last line in the current buffer
                    'x      position of mark x (if the mark is not set, 0 is
                            returned)
                    w0      first line visible in current window (one if the
                            display isn't updated, e.g. in silent Ex mode)
                    w$      last line visible in current window (this is one
                            less than "w0" if no lines are visible)
                    v       In Visual mode: the start of the Visual area (the
                            cursor is the end).  When not in Visual mode
                            returns the cursor position.  Differs from '< in
                            that it's updated right away.

上記の . $ 等で、.-1 $+1 というように offset を指定できたら便利ではないかという提案です。

  • line() 等の行指定では行の offset、col() では桁の offset とする。
  • . w0 w$ といった window 依存の位置表現は、関連する window を持たない buffer には使えない。
  • v は current window に対してのみ。

検討:

  • col('$+10') のように有効な範囲を超えた場合の戻り値はどうするか(そのまま返す or 範囲内に直す)
    • line('$+1') のように範囲外だが有用なケースもある(後述)

使用例

setbufline() で buffer の末尾に追記する処理が setbufline('#', '$+1', [...]) と書ける。

http://lingr.com/room/vim/archives/2017/10/31#message-24333515
現状では別 buffer の末尾行を求めるのに len(getbufline('#', 1, '$')) とする必要がある。

Patch

https://github.com/vim/vim/compare/master...ichizok:feature/offset-expr.diff

@ichizok

This comment has been minimized.

Show comment
Hide comment
@ichizok

ichizok Dec 13, 2017

Member

投げました。
vim/vim#2441

Member

ichizok commented Dec 13, 2017

投げました。
vim/vim#2441

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment