src.elv.sh@v0.21.0-dev.0.20240515223629-06979efb9a2a/pkg/edit/completion.d.elv (about)

     1  # A map containing argument completers.
     2  var completion:arg-completer
     3  
     4  # Keybinding for the completion mode.
     5  var completion:binding
     6  
     7  # A map mapping from context names to matcher functions. See the
     8  # [Matcher](#matcher) section.
     9  var completion:matcher
    10  
    11  # Produces a list of filenames found in the directory of the last argument. All
    12  # other arguments are ignored. If the last argument does not contain a path
    13  # (either absolute or relative to the current directory), then the current
    14  # directory is used. Relevant files are output as `edit:complex-candidate`
    15  # objects.
    16  #
    17  # This function is the default handler for any commands without
    18  # explicit handlers in `$edit:completion:arg-completer`. See [Argument
    19  # Completer](#argument-completer).
    20  #
    21  # Example:
    22  #
    23  # ```elvish-transcript
    24  # ~> edit:complete-filename ''
    25  # ▶ (edit:complex-candidate Applications &code-suffix=/ &style='01;34')
    26  # ▶ (edit:complex-candidate Books &code-suffix=/ &style='01;34')
    27  # ▶ (edit:complex-candidate Desktop &code-suffix=/ &style='01;34')
    28  # ▶ (edit:complex-candidate Docsafe &code-suffix=/ &style='01;34')
    29  # ▶ (edit:complex-candidate Documents &code-suffix=/ &style='01;34')
    30  # ...
    31  # ~> edit:complete-filename .elvish/
    32  # ▶ (edit:complex-candidate .elvish/aliases &code-suffix=/ &style='01;34')
    33  # ▶ (edit:complex-candidate .elvish/db &code-suffix=' ' &style='')
    34  # ▶ (edit:complex-candidate .elvish/epm-installed &code-suffix=' ' &style='')
    35  # ▶ (edit:complex-candidate .elvish/lib &code-suffix=/ &style='01;34')
    36  # ▶ (edit:complex-candidate .elvish/rc.elv &code-suffix=' ' &style='')
    37  # ```
    38  fn complete-filename {|@args| }
    39  
    40  # Builds a complex candidate. This is mainly useful in [argument
    41  # completers](#argument-completer).
    42  #
    43  # The `&display` option controls how the candidate is shown in the UI. It can
    44  # be a string or a [styled](builtin.html#styled) text. If it is empty, `$stem`
    45  # is used.
    46  #
    47  # The `&code-suffix` option affects how the candidate is inserted into the code
    48  # when it is accepted. By default, a quoted version of `$stem` is inserted. If
    49  # `$code-suffix` is non-empty, it is added to that text, and the suffix is not
    50  # quoted.
    51  fn complex-candidate {|stem &display='' &code-suffix=''| }
    52  
    53  # For each input, outputs whether the input has $seed as a prefix. Uses the
    54  # result of `to-string` for non-string inputs.
    55  #
    56  # Roughly equivalent to the following Elvish function, but more efficient:
    57  #
    58  # ```elvish
    59  # use str
    60  # fn match-prefix {|seed @input|
    61  #   each {|x| str:has-prefix (to-string $x) $seed } $@input
    62  # }
    63  # ```
    64  fn match-prefix {|seed inputs?| }
    65  
    66  # For each input, outputs whether the input has $seed as a
    67  # [subsequence](https://en.wikipedia.org/wiki/Subsequence). Uses the result of
    68  # `to-string` for non-string inputs.
    69  fn match-subseq {|seed inputs?| }
    70  
    71  # For each input, outputs whether the input has $seed as a substring. Uses the
    72  # result of `to-string` for non-string inputs.
    73  #
    74  # Roughly equivalent to the following Elvish function, but more efficient:
    75  #
    76  # ```elvish
    77  # use str
    78  # fn match-substr {|seed @input|
    79  #   each {|x| str:has-contains (to-string $x) $seed } $@input
    80  # }
    81  # ```
    82  fn match-substr {|seed inputs?| }
    83  
    84  # Start the completion mode.
    85  fn completion:start { }
    86  
    87  # Starts the completion mode after accepting any pending autofix.
    88  #
    89  # If all the candidates share a non-empty prefix and that prefix starts with the
    90  # seed, inserts the prefix instead.
    91  fn completion:smart-start { }