Кто-нибудь может объяснить, зачем нужна "очистка" строки-дубликата, т.е. замена её пустой строкой? В чём смысл?
Я сделал такую операцию, поскольку она есть в плагине SortStrings, но что-то не могу понять, зачем это может понадобиться.
Удалить дубликат - понятно, а очистить - не очень.
Duplicate Fighter (Анти-дубликатор)
Posted: Fri 30 Oct, 2015 19:31
by Shmuel
Заменил в первом сообщении вложение на версию 2.
- Справка - как коммент в начале файла (пока только на английском).
- Вместо меню - диалог.
- Добавилась (опциональная) возможность использовать Lua-выражения.
- Почти не тестировалось, буду благодарен за багрепорты.
Duplicate Fighter (Анти-дубликатор)
Posted: Sat 31 Oct, 2015 00:01
by fml2
Я самим макро еще не пользовался, а только почитал справку, т.е. комментарий в начале файла. И у меня такие замечания:
1.
Definition:
Two lines are considered "duplicate" to each other if they both have the same value
as the result of some expression specified by the user.
Examples:
a) two lines are identical.
b) two lines become identical after stripping white spaces from both their ends.
c) two lines begin with the same 20 character sequence.
* Actions (radio-boxes):
"Remove duplicates" : remove all duplicate lines in each group of duplicates except the first one
"Clear duplicates" : clear all duplicate lines in each group of duplicates except the first one
"Remove non-uniques" : remove all duplicate lines including the first one
"Clear non-uniques" : clear all duplicate lines including the first one
* "Use Expression"
If unchecked then two lines considered duplicate only when they are identical. I.e. the text of a
line is considered the value of the expression.
If checked then the "Expression" edit box should contain a Lua expression that will be applied to each
selected line (or part of it in the case of a vertical block) and the results of the expression will be
compared rather than the lines themselves.
* The expression can use the variable L that will hold the text of the line when the expression is evaluated.
* If the expression evaluates to a string or a number this is considered the value used for comparison.
* If the expression evaluates to false/nil/nothing then the line is considered a DUPLICATE.
* Otherwise the line is considered a NON-DUPLICATE.
Examples of expressions resulting in either string or number:
a) L:lower()
Two lines are considered duplicates if they only differ by case.
b) L:sub(10,20)
Two lines are considered duplicates if their [10,20] substrings are equal.
c) L:len()
Two lines are considered duplicates if they have the same length.
d) L:match("foobar")
Two lines are considered duplicates if they both contain "foobar".
* "Convert to boolean"
If checked then the result of expression is converted to boolean that is: not not X
Examples of expressions resulting in a boolean:
a) L:match("foobar")
This line is considered non-duplicate (regardless of other lines) if it contains "foobar"
otherwise it is considered duplicate.
b) not L:match("foobar")
This line is considered duplicate (regardless of other lines) if it contains "foobar"
otherwise it is considered non-duplicate.
c) L:match("foo") and L:match("bar")
This line is considered non-duplicate (regardless of other lines) if it contains both "foo" and "bar".
2. (главное) Мне кажется, было бы логичнее, если бы дупликатами считались строки, для которых булевский результат выражения true, а не false. Т.е. смысл выражения таков: "Это -- дупликат?"
Duplicate Fighter (Анти-дубликатор)
Posted: Sat 31 Oct, 2015 09:03
by Shmuel
fml2, спасибо за ваши замечания.
По поводу справки: ещё буду редактировать, сравню с вашим вариантом.
По поводу трактовки булевого результата: вначале сделал именно так, как вы предлагаете, то-есть true означал дубликат. Но потом поймал себя на ощущении, что мне важнее определить, что хочется оставить, чем то, что хочется удалить, после чего сделал как сейчас. Буду думать ещё.
Duplicate Fighter (Анти-дубликатор)
Posted: Sat 31 Oct, 2015 10:33
by fml2
Shmuel wrote:Но потом поймал себя на ощущении, что мне важнее определить, что хочется оставить, чем то, что хочется удалить
Я согласен, что возможны обе трактовки. Но тогда надо бы заголовок поля "Expression" сделать более информативным, т.е. чтобы прямо в диалоге было понятно, что означает выражение (true -- это "оставить" или "стереть"?).
Duplicate Fighter (Анти-дубликатор)
Posted: Sun 01 Nov, 2015 17:32
by Shmuel
Заменил в первом сообщении вложение на версию 3.
- Справка поправлена и расширена.
- При отсутствии выделения обрабатывается весь файл.
- Изменена и упрощена логика определения дубликатов (описано в справке).
Любые замечания и предложения приветствуются.
Duplicate Fighter (Анти-дубликатор)
Posted: Mon 02 Nov, 2015 17:33
by Arama
Shmuel,
Неприятный момент, удаляет как дубликаты пустые строки, что ломает форматирование, так задумано?
Duplicate Fighter (Анти-дубликатор)
Posted: Mon 02 Nov, 2015 17:52
by Shmuel
Пустые строки равны друг другу, поэтому воспринимаются как дубликаты и удаляются.
Можно, конечно, обойти это: