[vim/vim] Provide a way to query the effective prompt text for a prompt buffer (#6851)

14 views
Skip to first unread message

Ben Jackson

unread,
Sep 3, 2020, 12:28:50 PM9/3/20
to vim/vim, Subscribed

This adds the (optional) prompt key to the return from getbufinfo() in order to see the effective prompt text for a prompt buffer.

This is useful when writing an omnifunc for prompt buffers, i.e. you can find the real text being entered with something like:

let line = getline( line( '.' ) )[ len( getbufinfo( '%' )[ 0 ].prompt ) : ]

This means that you don't have to know a-priori what the prompt will be and/or don't need to find a way to push this into your omnifunc callback.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/6851

Commit Summary

  • Provide a way to query the effective prompt text for a prompt buffer

File Changes

Patch Links:


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Yegappan Lakshmanan

unread,
Sep 3, 2020, 12:39:30 PM9/3/20
to vim_dev, reply+ACY5DGDQNNBZXLKX6U...@reply.github.com, vim/vim, Subscribed
Hi Ben,

On Thu, Sep 3, 2020 at 9:28 AM Ben Jackson <vim-dev...@256bit.org> wrote:

This adds the (optional) prompt key to the return from getbufinfo() in order to see the effective prompt text for a prompt buffer.

This is useful when writing an omnifunc for prompt buffers, i.e. you can find the real text being entered with something like:

let line = getline( line( '.' ) )[ len( getbufinfo( '%' )[ 0 ].prompt ) : ]

This means that you don't have to know a-priori what the prompt will be and/or don't need to find a way to push this into your omnifunc callback.


Instead of returning the prompt text in the getbufinfo() function, do you think a
new prompt_getinfo() function should be added that returns the information set by the
prompt_setcallback(),  prompt_setinterrupt() abd prompt_setprompt() functions?

Regards,
Yegappan

vim-dev ML

unread,
Sep 3, 2020, 12:40:06 PM9/3/20
to vim/vim, vim-dev ML, Your activity

Hi Ben,

On Thu, Sep 3, 2020 at 9:28 AM Ben Jackson <vim-dev...@256bit.org>
wrote:

> This adds the (optional) prompt key to the return from getbufinfo() in
> order to see the effective prompt text for a prompt buffer.
>
> This is useful when writing an omnifunc for prompt buffers, i.e. you can
> find the real text being entered with something like:
>
> let line = getline( line( '.' ) )[ len( getbufinfo( '%' )[ 0 ].prompt ) : ]
>
> This means that you don't have to know a-priori what the prompt will be
> and/or don't need to find a way to push this into your omnifunc callback.
>

Instead of returning the prompt text in the getbufinfo() function, do you
think a
new prompt_getinfo() function should be added that returns the information
set by the
prompt_setcallback(), prompt_setinterrupt() abd prompt_setprompt()
functions?

Regards,
Yegappan

codecov[bot]

unread,
Sep 3, 2020, 12:53:13 PM9/3/20
to vim/vim, vim-dev ML, Comment

Codecov Report

Merging #6851 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@

##           master    #6851   +/-   ##

=======================================

  Coverage   88.50%   88.51%           

=======================================

  Files         147      147           

  Lines      160916   160920    +4     

=======================================

+ Hits       142423   142441   +18     

+ Misses      18493    18479   -14     
Impacted Files Coverage Δ
src/edit.c 92.31% <100.00%> (+<0.01%) ⬆️
src/evalbuffer.c 96.29% <100.00%> (+0.01%) ⬆️
src/netbeans.c 76.07% <0.00%> (-0.23%) ⬇️
src/gui.c 63.30% <0.00%> (-0.10%) ⬇️
src/terminal.c 91.02% <0.00%> (ø)
src/channel.c 89.83% <0.00%> (+0.03%) ⬆️
src/gui_gtk_x11.c 58.73% <0.00%> (+0.04%) ⬆️
src/sign.c 95.03% <0.00%> (+0.08%) ⬆️
src/search.c 91.43% <0.00%> (+0.10%) ⬆️
src/gui_gtk.c 31.71% <0.00%> (+0.27%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a60053b...244ca1e. Read the comment docs.


You are receiving this because you commented.

Ben Jackson

unread,
Sep 3, 2020, 1:21:11 PM9/3/20
to vim/vim, vim-dev ML, Comment

I guess that's a possibility, but I think there is less of an obvious use case for the other properties, at least I can't think of an obvious reason to check what the prompt callback for a buffer is (assuming you created the buffer). In the case of the effective prompt text:

This certainly seemed simpler, but of course the alternative, more complete solution also works.


You are receiving this because you commented.

Bram Moolenaar

unread,
Sep 3, 2020, 2:25:43 PM9/3/20
to vim/vim, vim-dev ML, Comment


Ben Jackson wrote:

> This adds the (optional) `prompt` key to the return from
> `getbufinfo()` in order to see the effective prompt text for a prompt
> buffer.
>
> This is useful when writing an `omnifunc` for prompt buffers, i.e. you
> can find the real text being entered with something like:
>
> ```
> let line = getline( line( &#39;.&#39; ) )[ len( getbufinfo( &#39;%&#39; )[ 0 ].prompt ) : ]
> ```
>
> This means that you don&#39;t have to know a-priori what the prompt
> will be and/or don&#39;t need to find a way to push this into your
> omnifunc callback.

I can see getting the prompt is useful. But if you just want to get the
prompt then getbufinfo() is a bit of a blunt instrument. And other uses
of getbufinfo() are unlikely to use the prompt.

How about adding a separate function: prompt_getprompt() ?
That fits nicely next to prompt_setprompt().


--
A mathematician is a device for turning coffee into theorems.
Paul Erdos
A computer programmer is a device for turning coffee into bugs.
Bram Moolenaar

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///


You are receiving this because you commented.

Ben Jackson

unread,
Sep 3, 2020, 2:48:47 PM9/3/20
to vim/vim, vim-dev ML, Comment

How about adding a separate function: prompt_getprompt() ?
That fits nicely next to prompt_setprompt().

Sure thing. This was my initial thought. I went for getbufinfo() on the basis that it was a smaller change. Reviewing the current values for it though, I think you're (both!) right, it doesn't fit well.

This actually makes it easier to check for this feature exists( '*prompt_getprompt' ), rather than has_patch( ... ) I guess.

Completing the thought process, if in future we might add more prompt_set* attributes, at which point Yegappan's suggestion of prompt_getinfo() or equivalent might be better. Let's say we add a prompt history (I think that's in the todo list), maybe we add prompt_sethistorylen( 10 ) or something. Perhaps we'd then put that in prompt_getinfo(), but again the use-case for requesting this is much more vague, and having to calculate it for every completion request (in the case of a omnifunc) is wasteful. We can therefore add prompt_getprompt() now, and if we ever need to, add prompt_getinfo() later.


You are receiving this because you commented.

Ben Jackson

unread,
Sep 3, 2020, 3:18:30 PM9/3/20
to vim/vim, vim-dev ML, Comment

That's done, I think.


You are receiving this because you commented.

Ben Jackson

unread,
Sep 3, 2020, 3:19:46 PM9/3/20
to vim/vim, vim-dev ML, Push

@puremourning pushed 1 commit.

  • 5617d83 Provide a way to query the effective prompt text for a prompt buffer


You are receiving this because you are subscribed to this thread.

View it on GitHub or unsubscribe.

Bram Moolenaar

unread,
Sep 3, 2020, 4:34:30 PM9/3/20
to vim...@googlegroups.com, Yegappan Lakshmanan, reply+ACY5DGDQNNBZXLKX6U...@reply.github.com
That would also work. We don't have much need to get the callbacks
though. ch_info() also doesn't list the callbacks.

--
ARTHUR: Well, I AM king...
DENNIS: Oh king, eh, very nice. An' how'd you get that, eh? By exploitin'
the workers -- by 'angin' on to outdated imperialist dogma which
perpetuates the economic an' social differences in our society! If
there's ever going to be any progress--
The Quest for the Holy Grail (Monty Python)

Bram Moolenaar

unread,
Sep 3, 2020, 4:34:31 PM9/3/20
to vim...@googlegroups.com, Ben Jackson

Ben Jackson wrote:

> > How about adding a separate function: prompt_getprompt() ?
> > That fits nicely next to prompt_setprompt().
>
> Sure thing. This was my initial thought. I went for getbufinfo() on
> the basis that it was a smaller change. Reviewing the current values
> for it though, I think you're (both!) right, it doesn't fit well.
>
> This actually makes it easier to check for this feature `exists(
> '*prompt_getprompt' )`, rather than `has_patch( ... )` I guess.
>
> Completing the thought process, if in future we might add more
> `prompt_set*` attributes, at which point Yegappan's suggestion of
> `prompt_getinfo()` or equivalent might be better. Let's say we add a
> prompt history (I think that's in the todo list), maybe we add
> `prompt_sethistorylen( 10 )` or something. Perhaps we'd then put that
> in `prompt_getinfo()`, but again the use-case for requesting this is
> much more vague, and having to calculate it for every completion
> request (in the case of a omnifunc) is wasteful. We can therefore add
> `prompt_getprompt()` now, and if we ever need to, add
> `prompt_getinfo()` later.

The history mentioned is for the typed commands, not for the prompt.
Any settings for the history would fit in though.

--
Vim is like Emacs without all the typing. (John "Johann" Spetz)

vim-dev ML

unread,
Sep 3, 2020, 4:34:54 PM9/3/20
to vim/vim, vim-dev ML, Your activity


Yegappan wrote:

> On Thu, Sep 3, 2020 at 9:28 AM Ben Jackson <vim-dev...@256bit.org>
> wrote:
>
> > This adds the (optional) prompt key to the return from getbufinfo() in
> > order to see the effective prompt text for a prompt buffer.
> >
> > This is useful when writing an omnifunc for prompt buffers, i.e. you can
> > find the real text being entered with something like:
> >
> > let line = getline( line( '.' ) )[ len( getbufinfo( '%' )[ 0 ].prompt ) : ]
> >
> > This means that you don't have to know a-priori what the prompt will be
> > and/or don't need to find a way to push this into your omnifunc callback.
> >
>
> Instead of returning the prompt text in the getbufinfo() function, do you
> think a new prompt_getinfo() function should be added that returns the
> information set by the prompt_setcallback(), prompt_setinterrupt()
> abd prompt_setprompt() functions?

That would also work. We don't have much need to get the callbacks
though. ch_info() also doesn't list the callbacks.

--
ARTHUR: Well, I AM king...
DENNIS: Oh king, eh, very nice. An' how'd you get that, eh? By exploitin'
the workers -- by 'angin' on to outdated imperialist dogma which
perpetuates the economic an' social differences in our society! If
there's ever going to be any progress--
The Quest for the Holy Grail (Monty Python)

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Ben Jackson

unread,
Sep 3, 2020, 6:56:15 PM9/3/20
to vim/vim, vim-dev ML, Comment

OK tests fixed, this is ready now.


You are receiving this because you commented.

Bram Moolenaar

unread,
Sep 4, 2020, 10:36:19 AM9/4/20
to vim/vim, vim-dev ML, Comment

Closed #6851 via 077cc7a.


You are receiving this because you commented.

Reply all
Reply to author
Forward
0 new messages