我试图让选择中的文本最初传递给函数 find_max_eq_filter 。我试图修改的函数有一个“s”参数,我假设它是选择文本。我想更改函数以允许用户传递的参数。有人可以告诉我如何做到这一点吗?
_command void align_equals() name_info(','VSARG2_MARK|VSARG2_REQUIRES_EDITORCTL)
{
if ( _select_type() != "LINE" && _select_type() != "BLOCK" ) {
message("A LINE or BLOCK selection is required for this function");
return;
}
gMaxEqCol = 0;
_str character = prompt(prmt1, 'What do you wish to align?'); /* I want to ask the user for an input string */
filter_selection(find_max_eq_filter(s, character)); /* Here I want to pass the selection with the string taken from the user. */
if (gMaxEqCol == 0) {
// no equal signs
return;
}
filter_selection(align_eq_filter);
_free_selection("");
}
static _str find_max_eq_filter(s, _str toalign)
{
_str inputStr = expand_tabs(s)
int equalsPos = pos(toalign, inputStr, 1, "");
if ( equalsPos > gMaxEqCol ) {
gMaxEqCol = equalsPos;
}
return s;
}
filter_selection(find_max_eq_filter);
任何帮助表示赞赏,
泰德
PS。你想重现我正在做的事情,所以我必须粘贴整个内容:
#include "slick.sh"
static int gMaxEqCol;
static _str gUsrStr;
static _str find_max_char_filter(s)
{
_str inputStr = expand_tabs(s);
int equalsPos = pos(gUsrStr, inputStr, 1, "");
if ( equalsPos > gMaxEqCol ) {
gMaxEqCol = equalsPos;
}
return s;
}
static _str align_char_filter(s)
{
if (gMaxEqCol <= 0 || length(s) == 0) {
return s;
}
_str expandedStr = expand_tabs(s);
int equalsPos = pos(gUsrStr, expandedStr, 1, "");
if (equalsPos == 0) {
return s;
}
_str prefix = substr(expandedStr, 1, equalsPos - 1);
_str postfix = substr(expandedStr,equalsPos);
while (equalsPos < gMaxEqCol ) {
prefix = prefix :+ ' ';
++equalsPos;
}
return prefix :+ postfix;
}
_command void align_chars() name_info(','VSARG2_MARK|VSARG2_REQUIRES_EDITORCTL)
{
if ( _select_type() != "LINE" && _select_type() != "BLOCK" ) {
message("A LINE or BLOCK selection is required for this function");
return;
}
gMaxEqCol = 0;
_str prmpt1 = "";
gUsrStr = prompt(prmpt1, "Please enter a string: ");
filter_selection(find_max_char_filter);
if (gMaxEqCol == 0) {
// no equal signs
return;
}
filter_selection(align_char_filter);
_free_selection("");
}
所以这是我的问题,我想将 gUsrStr 更改为辅助函数的参数,而不是为其设置一个全局变量。但是,当我尝试这样做时,它会中断。另外,我不太明白提示函数的第一个参数。它应该是什么?如果用户不输入任何内容,它是否是默认值?