aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2016-04-07 18:12:40 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2016-04-07 18:12:40 -0400
commit44d2aed66ed13f5d45f1ae3894df2576f7a1623f (patch)
tree3daf88092b3f238ff3f84fd81c460878e24d25dc
parented84b2a0789fb32a39779015d3fc937ca3a627ae (diff)
downloadtextadept-44d2aed66ed13f5d45f1ae3894df2576f7a1623f.tar.gz
textadept-44d2aed66ed13f5d45f1ae3894df2576f7a1623f.zip
Only show snippet trigger and text in selection dialog.
-rw-r--r--core/locale.conf1
-rw-r--r--core/locales/locale.ar.conf1
-rw-r--r--core/locales/locale.de.conf1
-rw-r--r--core/locales/locale.es.conf1
-rw-r--r--core/locales/locale.fr.conf1
-rw-r--r--core/locales/locale.it.conf1
-rw-r--r--core/locales/locale.pl.conf1
-rw-r--r--core/locales/locale.ru.conf1
-rw-r--r--core/locales/locale.sv.conf1
-rw-r--r--modules/textadept/snippets.lua33
10 files changed, 14 insertions, 28 deletions
diff --git a/core/locale.conf b/core/locale.conf
index 10dafa15..4e4c9f3b 100644
--- a/core/locale.conf
+++ b/core/locale.conf
@@ -273,5 +273,4 @@ files or more were found. Showing the first = files or more were found. Showing
% modules/textadept/snippets.lua
Select Snippet = Select Snippet
Trigger = Trigger
-Scope = Scope
Snippet Text = Snippet Text
diff --git a/core/locales/locale.ar.conf b/core/locales/locale.ar.conf
index 1f72e099..75b9b6fc 100644
--- a/core/locales/locale.ar.conf
+++ b/core/locales/locale.ar.conf
@@ -274,5 +274,4 @@ files or more were found. Showing the first = وجدت ملفات. سأعرض ا
% modules/textadept/snippets.lua
Select Snippet = اختر قصاصة
Trigger = الدافع
-Scope = النطاق
Snippet Text = نص القصاصة
diff --git a/core/locales/locale.de.conf b/core/locales/locale.de.conf
index 54a05f2c..7f1d9f4b 100644
--- a/core/locales/locale.de.conf
+++ b/core/locales/locale.de.conf
@@ -263,5 +263,4 @@ files or more were found. Showing the first = Dateien oder mehr gefunden. Zeige
% modules/textadept/snippets.lua
Select Snippet = Snippet auswählen
Trigger = Trigger
-Scope = Scope
Snippet Text = Snippet-Text
diff --git a/core/locales/locale.es.conf b/core/locales/locale.es.conf
index bd8a5079..9982b07a 100644
--- a/core/locales/locale.es.conf
+++ b/core/locales/locale.es.conf
@@ -274,5 +274,4 @@ files or more were found. Showing the first = ficheros o más han sido encontrad
% modules/textadept/snippets.lua
Select Snippet = Seleccionar fragmento
Trigger = Disparador
-Scope = Ámbito
Snippet Text = Texto del fragmento
diff --git a/core/locales/locale.fr.conf b/core/locales/locale.fr.conf
index 42b37b1b..f5900410 100644
--- a/core/locales/locale.fr.conf
+++ b/core/locales/locale.fr.conf
@@ -275,5 +275,4 @@ files or more were found. Showing the first = fichiers ou plus trouvés. Afficha
% modules/textadept/snippets.lua
Select Snippet = Choisir le fragment
Trigger = Déclencheur
-Scope = Contexte
Snippet Text = Texte du fragment
diff --git a/core/locales/locale.it.conf b/core/locales/locale.it.conf
index bef5dbab..aaa4e084 100644
--- a/core/locales/locale.it.conf
+++ b/core/locales/locale.it.conf
@@ -274,5 +274,4 @@ files or more were found. Showing the first = file o più sono stati trovati. So
% modules/textadept/snippets.lua
Select Snippet = Inserisci un frammento
Trigger = Innesco
-Scope = Contesto
Snippet Text = Testo del frammento
diff --git a/core/locales/locale.pl.conf b/core/locales/locale.pl.conf
index 557a0b25..67ef5552 100644
--- a/core/locales/locale.pl.conf
+++ b/core/locales/locale.pl.conf
@@ -274,5 +274,4 @@ files or more were found. Showing the first = lub więcej plików zostało znale
% modules/textadept/snippets.lua
Select Snippet = Wybierz skrawek
Trigger = Wyzwalacz
-Scope = Zakres
Snippet Text = Treść skrawka
diff --git a/core/locales/locale.ru.conf b/core/locales/locale.ru.conf
index 8c4b2c13..19fb8fd4 100644
--- a/core/locales/locale.ru.conf
+++ b/core/locales/locale.ru.conf
@@ -263,5 +263,4 @@ files or more were found. Showing the first = файлов или более б
% modules/textadept/snippets.lua
Select Snippet = Выбрать заготовку
Trigger = Триггер
-Scope = Область видимости
Snippet Text = Текст заготовки
diff --git a/core/locales/locale.sv.conf b/core/locales/locale.sv.conf
index 16ffa42d..17d9ab6d 100644
--- a/core/locales/locale.sv.conf
+++ b/core/locales/locale.sv.conf
@@ -275,5 +275,4 @@ files or more were found. Showing the first = eller fler filer funna. Visar de f
% modules/textadept/snippets.lua
Select Snippet = Välj snippet
Trigger = Trigger
-Scope = Scope
Snippet Text = Snippet-text
diff --git a/modules/textadept/snippets.lua b/modules/textadept/snippets.lua
index 64b9c385..972669ec 100644
--- a/modules/textadept/snippets.lua
+++ b/modules/textadept/snippets.lua
@@ -75,7 +75,7 @@ local M = {}
-- transform with the process' standard output (stdout). The code may use a `%`
-- character to represent placeholder *n*'s text. An example is
--
--- snippets['env'] = '$%1(HOME) = %1[echo $%]'
+-- snippets['env'] = '$%1(HOME) = %1[echo $%1]'
--
-- ### `%%`
--
@@ -168,12 +168,10 @@ local function new_snippet(text, trigger)
end
if #lines > 1 then
-- Match indentation on all lines after the first.
- local indent_size = #buffer:get_cur_line():match('^%s*')
- if not use_tabs then
- -- Need integer division and LuaJIT does not have // operator.
- indent_size = math.floor(indent_size / buffer.tab_width)
- end
- local additional_indent = indent[use_tabs]:rep(indent_size)
+ local line = buffer:line_from_position(buffer.current_pos)
+ -- Need integer division and LuaJIT does not have // operator.
+ local level = math.floor(buffer.line_indentation[line] / buffer.tab_width)
+ local additional_indent = indent[use_tabs]:rep(level)
for i = 2, #lines do lines[i] = additional_indent..lines[i] end
end
text = table.concat(lines, ({[0] = '\r\n', '\r', '\n'})[buffer.eol_mode])
@@ -348,26 +346,22 @@ end
-- language-specific snippets.
-- @name _select
function M._select()
- local list, t = {}, {}
+ local list, items = {}, {}
for trigger, text in pairs(snippets) do
- if type(text) == 'string' then list[#list + 1] = trigger..'\0 \0'..text end
+ if type(text) == 'string' then list[#list + 1] = trigger..'|'..text end
end
- local lexer = buffer:get_lexer(true)
- for trigger, text in pairs(snippets[lexer] or {}) do
- if type(text) == 'string' then
- list[#list + 1] = string.format('%s\0%s\0%s', trigger, lexer, text)
- end
+ for trigger, text in pairs(snippets[buffer:get_lexer(true)] or {}) do
+ if type(text) == 'string' then list[#list + 1] = trigger..'|'..text end
end
table.sort(list)
for i = 1, #list do
- t[#t + 1], t[#t + 2], t[#t + 3] = list[i]:match('^(%Z+)%z(%Z+)%z(%Z+)$')
+ items[#items + 1], items[#items + 2] = list[i]:match('^([^|]+)|(.+)$')
end
local button, i = ui.dialogs.filteredlist{
- title = _L['Select Snippet'],
- columns = {_L['Trigger'], _L['Scope'], _L['Snippet Text']}, items = t,
- width = CURSES and ui.size[1] - 2 or nil
+ title = _L['Select Snippet'], columns = {_L['Trigger'], _L['Snippet Text']},
+ items = items, width = CURSES and ui.size[1] - 2 or nil
}
- if button == 1 and i then M._insert(t[i * 3]) end
+ if button == 1 and i then M._insert(items[i * 2]) end
end
-- Metatable for a snippet object.
@@ -534,6 +528,7 @@ M._snippet_mt = {
setmetatable(env, {__index = _G}))
return f and select(2, pcall(f)) or result or ''
elseif placeholder.sh_code then
+ -- Note: cannot use spawn since $env variables are not expanded.
local command = placeholder.sh_code:gsub('%f[%%]%%%f[^%%]', text)
local p = io.popen(command)
local result = p:read('*a'):sub(1, -2) -- chop '\n'