我試圖讓選擇中的文本最初傳遞給函數 find_max_eq_filter。我試圖修改的函數有一個 的「s」參數,我認爲它是選擇文本。我想要更改 函數以允許用戶傳遞的參數。有人可以通過 瞭解如何做到這一點?將選定的文本作爲參數傳遞給slickC
_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是的輔助函數的參數而不是一個全球的變量爲它。但是,當我試圖做到這一點時,它會打破。另外,我不太瞭解提示函數的第一個參數。它是什麼意思?如果用戶沒有輸入任何內容,它是默認值嗎?
嗯,我實際上試圖修改一個來自valen的例子,以允許我指定我想要對齊的字符,而不是始終是等號。 http://community.slickedit.com/index.php?topic=5899.0 – Flethuseo
感謝您的編輯......但由於我不完全知道(或關心知道)整個腳本的目的 - 我們可以減少它只是你想要做的選擇? (1)在調用你的函數之前用戶將會強調什麼?一個字,一個字?完整的行? (2)_select_typ()返回給你什麼? (3)如果你確實減少了功能,你可以跳過提示嗎?我想重現您的選擇問題,而無需調試您的整個腳本,謝謝:) – nhed
我已更新與我想改變的代碼的問題。我用它來處理一個全局變量。我也不明白他們提示函數的第一個參數是什麼。 – Flethuseo