-
Notifications
You must be signed in to change notification settings - Fork 10
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
Vim script 実行時にファイル先頭からの行番号を取得したい #1178
Comments
|
むずいですね。 |
|
vim/vim@master...ichizok:wip/script_lnum
|
@ichizok |
Thank you for working on this! I've done a more direct route in vim/vim#3329, but thought about the same like you did here. I would really love to have a "Source:" line in the ":profile" output, like here: https://github.com/vim/vim/pull/3329/files#diff-7837e28891d0e1dc09cd563abf114dc2R2622 |
This will add the source to the functions in the profiling output: diff --git i/src/userfunc.c w/src/userfunc.c
index 0831990b3..ee94c4c85 100644
--- i/src/userfunc.c
+++ w/src/userfunc.c
@@ -2609,6 +2609,9 @@ func_dump_profile(FILE *fd)
fprintf(fd, "FUNCTION <SNR>%s()\n", fp->uf_name + 3);
else
fprintf(fd, "FUNCTION %s()\n", fp->uf_name);
+ fprintf(fd, " Source: %s:%li\n",
+ get_scriptname(fp->uf_sctx.sc_scid),
+ fp->uf_sctx.sc_lnum);
if (fp->uf_tm_count == 1)
fprintf(fd, "Called 1 time\n");
else |
Have you considered the increased memory usage this will cause? It is not that much in current times, but maybe this should be enabled explicitly, given that it is only used occasionally. For the function's line numbers I thought about only tracking them when profiling is enabled/used. (I have ~2k functions defined according to |
Related vim/vim issue: vim/vim#3286 |
vim-jp/issues#1178 + Patch to display "Source" in func_dump_profile (vim-jp/issues#1178 (comment))
@h-east @blueyed Sorry for the late reply.
Maybe +10kB~1MB at most. I think it is acceptable cost for the better usability: |
I would recommend that. What do you think about my patch on top? |
Sent vim/vim#3362.
Since it changes profile-log format, from the point of the compatibility I didn't include it but introduced as application example. |
todolisted
|
8.1.0362 |
Congrats! |
関連: #937 #1174
Problem
関数内で現在行のファイル先頭からの行番号を取る簡便な手段がない。
Cレベルでも、実行時の行番号は
:source
中しか取れない (はず) 。Solution proposal
ufunc_T
構造体に、定義位置の行番号を記録するフィールドを追加。current_SID
と同じように、現在の行番号を記録する変数を追加する (current_SLN
) 。関数定義時に
sourcing_lnum
を記録し、関数呼び出し時にcurrent_SLN
にufunc_T
から行番号を取得することで、current_SLN + sourcing_lnum
が現在行の行番号になる。この値を返すキーを
eval_vars()
に追加すればよい。その他の構造体でも同様に行番号フィールドを追加し、定義時に記録することで、
map
やautocmd
等で定義位置の行番号を保持できる。vim/vim@master...ichizok:wip/script_lnum
この branch では、以下の構造体を定義して各構造体の
scid_T
をsctx_T
に置き換えている。The text was updated successfully, but these errors were encountered: