about summary refs log tree commit diff
path: root/Completion/Base/_match_pattern
blob: 91930a571faf4bb35dab6a4271dd45d3bab8b9c7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#autoload

# This function is called from functions that do matching whenever they
# need to build a pattern that is used to match possible completions.
# It gets the name of the calling function and two names of parameters
# as arguments. The first one is used in the calling function to build
# the pattern used for matching possible completions. The content of this
# parameter on entry to this function is the string taken from the line.
# Here it parameter should be changed to a pattern that matches words as
# the match specs currently in use do.
# In the calling function this pattern may be changed again or used only 
# in parts. The second parameter whose name is given as the third argument
# allows to give pattern flags like `(#l)' that are to be used whenever
# matching is done.
#
# As an example, if you have global match specifications like:
#
#  compctl -M 'm:{a-z}={A-Z}' 'm:{a-z}={A-Z} r:|[.-]=* r:|=*'
#
# This function would look like:
#
#   eval "${3}='(#l)'"
#   [[ compstate[matcher] -eq 2 ]] && eval "$2='${(P)2:gs/./*./:gs/-/*-/}'"
#
# The first line makes sure that matching is done case-insensitive as
# specified by `m:{a-z}={A-Z}'. The second line replaces dots and hyphens
# in the given string by patterns matching any characters before them,
# like the `r:|[.-]=* r:|=*'. To make this work, the function `_match_test'
# would have to be changed to `(( compstate[matcher] <= 2 ))'
#
# When automatic correction is used (see the file `_main_complete'), you
# probably don't want to set matching flags here as that may make the
# results slightly unpredictable. For this, change the line above to:
#
#   [[ compstate[matcher] -lt 0 ]] && eval "${3}='(#l)'"
#
# The default implementation of this function is empty.