I'm looking at a vim ftplugin named php_getset. It generates getters and setters for php properties. While it works pretty well, it does not correctly guess the indentation. I'm am trying to fix this. The relevant code is as follows:
let s:phpname = '[a-zA-Z_$][a-zA-Z0-9_$]*'
let s:variable = '\(\s*\)\(\([private,protected,public]\s\+\)*\)\$\(' . s:phpname . '\)\s*\(;\|=[^;]\+;\)'
... (inside a function)
let s:indent = substitute(a:variable, s:variable, '\1', '')
let s:varname = substitute(a:variable, s:variable, '\4', '')
let s:funcname = toupper(s:varname[0]) . strpart(s:varname, 1)
From debugging it, I see that a:variable
has the value d $downPayment;
(The d comes from the end of the word "protected"). I don't understand the the third argument to substitute
accomplishes. I've read about backreferences before, but I can't see what they're doing in this code.
Thanks in advance for any help. Let me know if I can make my question more clear or provide more detail.