// This script extracts from the current text whole words and leaves only those words that don't exist in the dictionary.
// I assume that dictionary file contains one word in each line and is saved as UTF-8 without BOM in location: ...\AkelPad\AkelFiles\Tools\dictionary.txt
//
// Usage:
// Call("Scripts::Main", 1, "Dict2.js", '-minLen=2 -latin=1 -sort=1 -info=0')
//
// Arguments:
// -minLen - minimum length of word in characters (default=2);
// if < 1, shows the input box
// -latin:
// 0 - use also non latin characters in words
// 1 - use latin characters only (default)
// 2 - question message box
// -sort - means that the output list of words will be sorted:
// 0 - not sorted
// 1 - sorted (default)
// 2 - question message box
// -info - information message box after end:
// 0 - don't show (default)
// 1 - show
var nMinLen = AkelPad.GetArgValue("minLen", 2);
var nLatin = AkelPad.GetArgValue("latin", 1);
var nSort = AkelPad.GetArgValue("sort", 1);
var bInfo = AkelPad.GetArgValue("info", 0);
var hMainWnd = AkelPad.GetMainWnd();
var nChoice;
var oRE;
var nTime;
var aWordAll;
var aWord;
var oDict;
var nDictLen;
var i;
if (nMinLen < 1)
{
nMinLen = parseInt(AkelPad.InputBox(hMainWnd, WScript.ScriptName, "Minimum length of word in characters (>0):", "2"), 10);
if ((! nMinLen) || (nMinLen < 1))
WScript.Quit();
}
if ((nLatin != 0) && (nLatin != 1))
{
nChoice = AkelPad.MessageBox(hMainWnd, "Use only latin characters in words?", WScript.ScriptName, 0x23 /*MB_ICONQUESTION|MB_YESNOCANCEL*/);
if (nChoice == 2 /*IDCANCEL*/)
WScript.Quit();
else if (nChoice == 6 /*IDYES*/)
nLatin = 1;
else
nLatin = 0;
}
if ((nSort != 0) && (nSort != 1))
{
nChoice = AkelPad.MessageBox(hMainWnd, "Sort the output list of words?", WScript.ScriptName, 0x23 /*MB_ICONQUESTION|MB_YESNOCANCEL*/);
if (nChoice == 2 /*IDCANCEL*/)
WScript.Quit();
else if (nChoice == 6 /*IDYES*/)
nSort = 1;
else
nSort = 0;
}
if (nLatin)
oRE = new RegExp("[a-z']{" + nMinLen + ",}", "g");
else
oRE = new RegExp("[^\x00-\x26\x28-\x40\x5B-\x60\x7B-\xBF\xD7\xF7]{" + nMinLen + ",}", "g");
nTime = new Date().getTime();
if (aWordAll = AkelPad.GetTextRange(0, -1).toLowerCase().match(oRE))
{
aWord = [];
oDict = {};
if (nDictLen = GetDictionary(oDict))
{
for (i = 0; i < aWordAll.length; ++i)
{
if (! (aWordAll[i] in oDict))
{
aWord.push(aWordAll[i]);
oDict[aWordAll[i]] = true;
}
}
if (nSort)
aWord.sort();
AkelPad.SetSel(0, -1);
AkelPad.ReplaceSel(aWord.join("\r"), -1);
}
}
if (bInfo)
AkelPad.MessageBox(hMainWnd,
"Words in dictionary: " + ((typeof nDictLen == "number") ? nDictLen : "?") + "\n\n" +
"Min length of word: " + nMinLen + "\n" +
"Non latin chracters: " + (nLatin ? "No" : "Yes") + "\n\n" +
"Input words: " + (aWordAll ? aWordAll.length : 0) + "\n" +
"Output words: " + (aWord ? aWord.length + ((aWord.length > 1) && nSort ? " (sorted)" : "") : 0) + "\n\n" +
"Total time: " + (new Date().getTime() - nTime) + " ms",
WScript.ScriptName, 64 /*MB_ICONINFORMATION*/);
function GetDictionary(oDict)
{
var aDict = AkelPad.ReadFile(AkelPad.GetAkelDir(1) + "\\Tools\\dictionary.txt", 0x10 /*OD_ADT_NOMESSAGES*/, 65001 /*UTF-8*/, 0).toLowerCase().match(/[^\r\n]+/g);
var i;
if (aDict)
{
for (i = 0; i < aDict.length; ++i)
oDict[aDict[i]] = true;
return aDict.length;
}
return 0;
}
KDJ
Есть предложение (пожелание) для FindReplaceEx.js. Если заинтересуетесь, не могли бы добавить в скрипт функцию «Extract to Clipboard» (другими словами «Copy Matches»)? Чтобы она помещала в буфер обмена все найденные совпадения. Например, найти: «<[^>\n\r]+>»; заменить: «\0» – нажимаю кнопку «Extract to Clipboard» и у меня в буфере обмена все html-теги из текущего файла. Потом можно вставить результат в новый файл и исследовать его. Мне кажется, что это – очень удобная и полезная функция. Я подсмотрел её в программе EditPad Pro.
KDJ
Many Thanks.
I tested scripts in several modes and files. It is working. Info is useful also.
Please, add script to collection. I think It is interesting for people.
KDJ, а как можно заставить скрипт по-умолчанию запускать интерфейс замены? Если нельзя, не мог бы ты сделать такую возможность. Сейчас приходится два раза нажимать ctrl+H — я скрипт повесил на эту комбинацию
KDJ, а как сделать, чтобы по Ctrl + F вызывался расширенный поиск, а по Ctrl +H расширенную замена? Пока сделал две копии скрипта, одну оригинальную, вторую модифицированную которую повесил на Ctrl +H