diff --git a/complete.go b/complete.go index faf6371..e3aad91 100644 --- a/complete.go +++ b/complete.go @@ -193,10 +193,10 @@ func escapeFilename(fname string) string { // The completions interface deals with tab completions. func completionLoader(rtm *rt.Runtime) *rt.Table { exports := map[string]util.LuaExport{ - "bins": {luaBinaryComplete, 3, false}, - "call": {callLuaCompleter, 4, false}, - "files": {luaFileComplete, 3, false}, - "handler": {completionHandler, 2, false}, + "bins": {hcmpBins, 3, false}, + "call": {hcmpCall, 4, false}, + "files": {hcmpFiles, 3, false}, + "handler": {hcmpHandler, 2, false}, } mod := rt.NewTable() @@ -231,7 +231,7 @@ hilbish.complete('command.sudo', function(query, ctx, fields) end) #example */ -func luaBinaryComplete(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { +func hcmpBins(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { query, ctx, fds, err := getCompleteParams(t, c) if err != nil { return nil, err @@ -257,7 +257,7 @@ func luaBinaryComplete(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { // #param query string // #param ctx string // #param fields table -func callLuaCompleter(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { +func hcmpCall(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { if err := c.CheckNArgs(4); err != nil { return nil, err } @@ -304,7 +304,7 @@ func callLuaCompleter(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { // #param query string // #param ctx string // #param fields table -func luaFileComplete(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { +func hcmpFiles(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { query, ctx, fds, err := getCompleteParams(t, c) if err != nil { return nil, err @@ -341,7 +341,7 @@ function hilbish.completion.handler(line, pos) end #example */ -func completionHandler(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { +func hcmpHandler(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { return c.Next(), nil } diff --git a/docs/api/hilbish/hilbish.completion.md b/docs/api/hilbish/hilbish.completion.md index cf2477b..7379719 100644 --- a/docs/api/hilbish/hilbish.completion.md +++ b/docs/api/hilbish/hilbish.completion.md @@ -13,10 +13,52 @@ The completions interface deals with tab completions. ## Functions ||| |----|----| -|call(name, query, ctx, fields) -> completionGroups (table), prefix (string)|Calls a completer function. This is mainly used to call a command completer, which will have a `name`| -|handler(line, pos)|This function contains the general completion handler for Hilbish. This function handles| |bins(query, ctx, fields) -> entries (table), prefix (string)|Return binaries/executables based on the provided parameters.| +|call(name, query, ctx, fields) -> completionGroups (table), prefix (string)|Calls a completer function. This is mainly used to call a command completer, which will have a `name`| |files(query, ctx, fields) -> entries (table), prefix (string)|Returns file matches based on the provided parameters.| +|handler(line, pos)|This function contains the general completion handler for Hilbish. This function handles| + +
+

+hilbish.completion.bins(query, ctx, fields) -> entries (table), prefix (string) + + + +

+ +Return binaries/executables based on the provided parameters. +This function is meant to be used as a helper in a command completion handler. + + +#### Parameters +`string` **`query`** + + +`string` **`ctx`** + + +`table` **`fields`** + + +#### Example +```lua +-- an extremely simple completer for sudo. +hilbish.complete('command.sudo', function(query, ctx, fields) + table.remove(fields, 1) + if #fields[1] then + -- return commands because sudo runs a command as root..! + + local entries, pfx = hilbish.completion.bins(query, ctx, fields) + return { + type = 'grid', + items = entries + }, pfx + end + + -- ... else suggest files or anything else .. +end) +```` +

@@ -42,6 +84,28 @@ You can check the Completions doc or `doc completions` for info on the `completi `table` **`fields`** +

+ +
+

+hilbish.completion.files(query, ctx, fields) -> entries (table), prefix (string) + + + +

+ +Returns file matches based on the provided parameters. +This function is meant to be used as a helper in a command completion handler. +#### Parameters +`string` **`query`** + + +`string` **`ctx`** + + +`table` **`fields`** + +

@@ -79,67 +143,3 @@ end ````
-
-

-hilbish.completion.bins(query, ctx, fields) -> entries (table), prefix (string) - - - -

- -Return binaries/executables based on the provided parameters. -This function is meant to be used as a helper in a command completion handler. - - -#### Parameters -`string` **`query`** - - -`string` **`ctx`** - - -`table` **`fields`** - - -#### Example -```lua --- an extremely simple completer for sudo. -hilbish.complete('command.sudo', function(query, ctx, fields) - table.remove(fields, 1) - if #fields[1] then - -- return commands because sudo runs a command as root..! - - local entries, pfx = hilbish.completion.bins(query, ctx, fields) - return { - type = 'grid', - items = entries - }, pfx - end - - -- ... else suggest files or anything else .. -end) -```` -
- -
-

-hilbish.completion.files(query, ctx, fields) -> entries (table), prefix (string) - - - -

- -Returns file matches based on the provided parameters. -This function is meant to be used as a helper in a command completion handler. -#### Parameters -`string` **`query`** - - -`string` **`ctx`** - - -`table` **`fields`** - - -
- diff --git a/emmyLuaDocs/hilbish.lua b/emmyLuaDocs/hilbish.lua index fe258b2..f6d58a4 100644 --- a/emmyLuaDocs/hilbish.lua +++ b/emmyLuaDocs/hilbish.lua @@ -14,18 +14,6 @@ function hilbish.aliases.add(alias, cmd) end --- @param cb function function hilbish.runner.setMode(cb) end ---- Calls a completer function. This is mainly used to call a command completer, which will have a `name` ---- in the form of `command.name`, example: `command.git`. ---- You can check the Completions doc or `doc completions` for info on the `completionGroups` return value. -function hilbish.completion.call(name, query, ctx, fields) end - ---- This function contains the general completion handler for Hilbish. This function handles ---- completion of everything, which includes calling other command handlers, binaries, and files. ---- This function can be overriden to supply a custom handler. Note that alias resolution is required to be done in this function. ---- ---- -function hilbish.completion.handler(line, pos) end - --- Returns the current input line. function hilbish.editor.getLine() end @@ -45,6 +33,28 @@ function hilbish.editor.getChar() end --- @param text string function hilbish.editor.setVimRegister(register, text) end +--- Return binaries/executables based on the provided parameters. +--- This function is meant to be used as a helper in a command completion handler. +--- +--- +function hilbish.completion.bins(query, ctx, fields) end + +--- Calls a completer function. This is mainly used to call a command completer, which will have a `name` +--- in the form of `command.name`, example: `command.git`. +--- You can check the Completions doc or `doc completions` for info on the `completionGroups` return value. +function hilbish.completion.call(name, query, ctx, fields) end + +--- Returns file matches based on the provided parameters. +--- This function is meant to be used as a helper in a command completion handler. +function hilbish.completion.files(query, ctx, fields) end + +--- This function contains the general completion handler for Hilbish. This function handles +--- completion of everything, which includes calling other command handlers, binaries, and files. +--- This function can be overriden to supply a custom handler. Note that alias resolution is required to be done in this function. +--- +--- +function hilbish.completion.handler(line, pos) end + --- Sets an alias, with a name of `cmd` to another command. --- --- @@ -168,16 +178,6 @@ function hilbish.which(name) end --- Puts a job in the background. This acts the same as initially running a job. function hilbish.jobs:background() end ---- Return binaries/executables based on the provided parameters. ---- This function is meant to be used as a helper in a command completion handler. ---- ---- -function hilbish.completion.bins(query, ctx, fields) end - ---- Returns file matches based on the provided parameters. ---- This function is meant to be used as a helper in a command completion handler. -function hilbish.completion.files(query, ctx, fields) end - --- Puts a job in the foreground. This will cause it to run like it was --- executed normally and wait for it to complete. function hilbish.jobs:foreground() end