visidata icon indicating copy to clipboard operation
visidata copied to clipboard

More sensible and legible autocomplete order

Open reagle opened this issue 1 year ago • 2 comments

Following a thought in a related issue, when I'm at the expression prompt and I hit tab to autocomplete the column name, it presents them in an odd order that I can't identify. It's not left to right. It'd be nice if it started with current column then it could move: leftward, rightward, or back to 0 then rightward.

reagle avatar Dec 20 '23 15:12 reagle

The column names are in alphabetical order (and case sensitive).

The line that determines this is: https://github.com/saulpw/visidata/blob/e9e8ef88849e75420017d42cbe250c778d822c10/visidata/expr.py#L23

Or to start at the column right of the current column, going rightward and wrapping around back the leftmost:

import itertools   #at the top of expr.py

#...

pivot = self.sheet.cursorColIndex
cols = [self.sheet.columns[i] for i in itertools.chain(range(pivot+1, len(self.sheet.columns)), range(0, pivot+1))]
varnames.extend((base+col.name) for col in cols if col.name.startswith(partial))

To instead start at the leftmost column, change it to:

varnames.extend((base+col.name) for col in self.sheet.columns if col.name.startswith(partial))

Personally, I find alphabetical order intuitive, since that's what shell completions often use.

midichef avatar Mar 12 '24 06:03 midichef

@midichef, thanks for the clarification. I was so dead set of thinking about column order I hadn't appreciated some might like alphabetical. I'd be curious what others prefer.

reagle avatar Mar 12 '24 10:03 reagle