Auto-completion window (shift-tab)

Posted by Worstje on Tue 24 Jun 2008 06:07 AM — 5 posts, 15,909 views.

Netherlands #0
Well, reading through some recent changelogs I found out about this feature I didn't even know about. It's not really mentioned anywhere in the helpfile that I can see, but that's not as important.

I'm kind of sad that the little window that pops up is so... limited. The list of words that it can match is limited to Lua only (for as far I can tell), and I'd personally like to throw some Python stuff into it. Or worse... I'd like to use it for totally different purposes. (In advance I want to apologize for having so many suggestions lately. :D)

A bunch of things I am envisioning to be able to use it for are:

- auto-completing Python code
- using it as a word list for ingame languages (see example at bottom)
- context-sensitive popups with choices (travel where? <list of locations>, barter/flirt/threaten for an encount with a merchant, etc)

A bunch of changes that I think would be needed to make it possible: (I'll include code examples in Python, since I will otherwise totally ruin Lua grammar with Pythonisms in it.)

- a way to open the list with choices of my liking. Preferably it passing some kind of list/table as choices, and to specify a callback to use upon completion. Example:

# you get a choice, plugin goes
 world.ShowSuggestions(["barter", "flirt", "threaten"], "MerchantBartering")

# definition of MerchantBartering
def MerchantBartering(choice):
  if (choice != None):
    world.Note("The choice was '%s', and we will insert '%s' in the command window at the current position." % (choice, choice.upper())
    return choice.upper()  # Place choice.upper() at current position in the command-window. None would be the same as not outputting anything.
  else:
    world.Note("Left the choices popup without making a choice.")
    return "run from merchant for wasting his time"


Note that it will just put the stuff in the command window and will require the user to press enter to actually send it. If direct-sending was preferred, world.Send() is your friend. I'm sure there's a command to change the contents of the inputbox somewhere too, in the case people want to adjust it differently.

- Maybe have a lot of little prettiness features, too. For example, basing it on the previous example:

# Put a label with Action above the choices, with flirt selected by default.
world.ShowSuggestions("Action?", ["barter", "flirt", "threaten"], "flirt", "MerchantBartering")


Or maybe an xml-inspired template would be easier and more customisable in the long run:

# Use the template interact_mob:
world.ShowSuggestions(["barter", "flirt", "threaten"], "interact_mob", "MerchantBartering")

# Example XML:
<suggestions>
  <suggestion
    name="interact_mob"
    label="Action?"
    label_fg="#550000"
    label_bg="lightgreen"
    label_font="Verdana"
    label_font_size="12"
    choice_bg="white"
    choice_fg="black"
    choice_selected_bg="lightblue"
    choice_selected_fg="yellow"
    choice_font="Dina"
    choice_font_size="10">
  </suggestion>
</suggestions>


Idea being that it makes it possible to give simple choices that are somewhat customizable and easy to use and understand.



Another example of how I'd like to implement some sort of translation-help. It's a bit pseudo-codish, seeing how I'm pretty tired and it's just to give an idea of the uses.

world.Accelerator("Ctrl+D", "/TranslationHelp()")

Words = {"I":"nia", "love":"goqu", "you":"dii"}

def TranslationHelp():
  world.ShowSuggestions("Word?", Words.getkeys(), "TranslateWord")

def TranslateWord(choice):
  if (choice != None):
    # Pop the dialog up for the next word.
    TranslationHelp()
    # Insert current choice, but translated.
    return Words[choice]


Basic idea: you're writing a say, and your character likes to occasionally speak in his native tongue. You don't want to replace all words, but rather translate specific ones. So when you need them, you go CTRL+D, find "I" (or type it), enter, find "love" (or type it), enter, find "you" (or type it), enter, escape. Then you can happily continue to write the rest of your emote.

The above might be a little troublesome due to popping up a second window from the callback. Probably the API suggestions I made above won't be usable (if only for the horrid choice of naming), but I hope it demonstrates the uses I see with this window+functionality opened up to scripting.
Amended on Tue 24 Jun 2008 06:11 AM by Worstje
Australia Forum Administrator #1
Quote:

I found out about this feature I didn't even know about. It's not really mentioned anywhere in the helpfile that I can see ...


Perhaps not in the help, but see:

http://mushclient.com/scripting

There is even a screen shot of it in operation.

Quote:

I'm kind of sad that the little window that pops up is so... limited.


It completes all of the 320 or so inbuilt script functions, which was its main intention. For example type Col<shift+tab> and you see ColourNote, ColourTell, and ColourNameToRGB.

It was intended to speed up general scripting, so you could get the spelling and capitalization of all the script function names correct.

If you use Lua it also adds in the Lua functions, as that is easily done by a table lookup at program initialization.

Quote:

... I will otherwise totally ruin Lua grammar with Pythonisms ...


Actually we have been listening to Monty Python a bit recently, so I sympathize somewhat. ;)



Anyway, onto your suggestions...

I don't see any great technical difficulty in letting you add your own words to the list. Bearing in mind the list already has all the script functions, you could probably call a new function that simply lets you grow the list with your own words (eg. Python words).

As for the other ideas, would not something like the existing ability to pop up menus (admittedly only available in Lua) work for something like that? Choice of bartering or whatever you are suggesting there?

I can see the usefulness, but am not sure how you establish a context. For example, I gather you are suggesting that if you type, say, "config" then a list of config options might appear. But that isn't really tab-completion exactly. Tab-completion assumes you already know part of the word. And for different options to occur in different contexts you need to know the context (eg. the 2nd last word).

Similarly with the translation idea. If they type "lov<tab>" it is hardly "completing" it to replace it with "goqu".


Quote:

(In advance I want to apologize for having so many suggestions lately. :D)


You have made some very good suggestions, most of which have appeared in the client. :)
Netherlands #2
Quote:
As for the other ideas, would not something like the existing ability to pop up menus (admittedly only available in Lua) work for something like that? Choice of bartering or whatever you are suggesting there?


Well, the reason I liked this dialog in particular is because it is designed to still be accepting entries in what you type. I'm not too familliar with the functionality in Lua you're speaking of (I only use Lua for small stuff that tends to need little interaction), but I assume by popping up menu's you're talking a menu like a rightclick would give. The problem with those is you can't happily keep typing, and are restricted to those accelerator keys mentioned there.

Quote:
I can see the usefulness, but am not sure how you establish a context. For example, I gather you are suggesting that if you type, say, "config" then a list of config options might appear. But that isn't really tab-completion exactly. Tab-completion assumes you already know part of the word. And for different options to occur in different contexts you need to know the context (eg. the 2nd last word).


Well, I guess some of the uses would indeed lack the completion part as it is used with tab-completion. (To be fair, I called it 'auto-completion' in my topic title *flee*). I like to think tab-completion is about completing words to be full. But the window itself has the potential to be used for more generic completions.

Your config example is a nice one. Type 'promptconfig ' and press TAB (or some other key designated to 'complete' assuming we'll leave TAB itself alone). It could pop up various prompt options (health, mana, etc). I can't recall needing it in the past, so maybe it doesn't exist.. but scripts can get to the data in the command-window at any time, right? Some GetInfo() call I bet.

Quote:
Similarly with the translation idea. If they type "lov<tab>" it is hardly "completing" it to replace it with "goqu".


Right. I should have been more clear about the 'standard' completion using (Shift-)TAB, which completes words, and other context-specific completions (initiated through other means) which complete in a wider scope (commands, sentences). They are semantically very different and it wouldn't be a good idea to have basic functionality get amended in drastic ways like that. (If people want to use TAB for context-specific stuff, there's always Accelerator to rebind it to that, and still leave the original functionality alone to be rebinded to another key-combination).
Australia Forum Administrator #3
I have partly implemented your suggestion, see the release notes for version 4.30.
Netherlands #4
Looks sweet. =) I'm going to have fun scripting stuff for that this summer. (That is assuming I have much time for mudding...)