diff options
author | 2013-04-24 10:06:11 -0400 | |
---|---|---|
committer | 2013-04-24 10:06:11 -0400 | |
commit | 36854c6ca8970714a6c672ca8774da4c5e9bd69e (patch) | |
tree | ce192a95fef1f5f1202dd3008c85402656b35d2c | |
parent | a460a7a12a5465168b6ff89f3021cdc67f54ba76 (diff) | |
download | textadept-36854c6ca8970714a6c672ca8774da4c5e9bd69e.tar.gz textadept-36854c6ca8970714a6c672ca8774da4c5e9bd69e.zip |
Moved `_M.textadept.filter_through` functionality into `editing` module.
-rw-r--r-- | core/locale.conf | 2 | ||||
-rw-r--r-- | core/locales/locale.de.conf | 2 | ||||
-rw-r--r-- | core/locales/locale.es.conf | 2 | ||||
-rw-r--r-- | core/locales/locale.fr.conf | 2 | ||||
-rw-r--r-- | core/locales/locale.ru.conf | 2 | ||||
-rw-r--r-- | modules/textadept/editing.lua | 49 | ||||
-rw-r--r-- | modules/textadept/filter_through.lua | 61 | ||||
-rw-r--r-- | modules/textadept/init.lua | 1 | ||||
-rw-r--r-- | modules/textadept/keys.lua | 8 | ||||
-rw-r--r-- | modules/textadept/menu.lua | 2 |
10 files changed, 59 insertions, 72 deletions
diff --git a/core/locale.conf b/core/locale.conf index ac7aa15f..9a96a8df 100644 --- a/core/locale.conf +++ b/core/locale.conf @@ -136,6 +136,7 @@ _Highlight Word = _Highlight Word Toggle _Block Comment = Toggle _Block Comment T_ranspose Characters = T_ranspose Characters _Join Lines = _Join Lines +_Filter Through = _Filter Through _Select = _Select Select to _Matching Brace = Select to _Matching Brace Select between _XML Tags = Select between _XML Tags @@ -179,7 +180,6 @@ Command _Entry = Command _Entry Select Co_mmand = Select Co_mmand _Run = _Run _Compile = _Compile -_Filter Through = _Filter Through _Adeptsense = _Adeptsense _Complete Symbol = _Complete Symbol Show _Documentation = Show _Documentation diff --git a/core/locales/locale.de.conf b/core/locales/locale.de.conf index 071c16d2..d904b357 100644 --- a/core/locales/locale.de.conf +++ b/core/locales/locale.de.conf @@ -126,6 +126,7 @@ _Highlight Word = Wort hervorheben Toggle _Block Comment = Kommentar T_ranspose Characters = Zeichen vertauschen _Join Lines = Linien verbinden +_Filter Through = Filtern durch _Select = Markieren Select to _Matching Brace = Zugehörige Klammern markieren Select between _XML Tags = Zwischen XML-Tags markieren @@ -169,7 +170,6 @@ Command _Entry = Befehlseingabe Select Co_mmand = Befehl auswählen _Run = Ausführen _Compile = Kompilieren -_Filter Through = Filtern durch _Adeptsense = _Adeptsense _Complete Symbol = Symbol vervollständigen Show _Documentation = Dokumentation anzeigen diff --git a/core/locales/locale.es.conf b/core/locales/locale.es.conf index 3fcad09f..c78c90c6 100644 --- a/core/locales/locale.es.conf +++ b/core/locales/locale.es.conf @@ -137,6 +137,7 @@ _Highlight Word = Res_altar palabra Toggle _Block Comment = Activar/Desactivar co_mentario de bloque T_ranspose Characters = _Intercambiar caracteres _Join Lines = U_nir líneas +_Filter Through = _Filtrar mediante _Select = Se_leccionar Select to _Matching Brace = Seleccionar _hasta paréntesis correspondiente Select between _XML Tags = Seleccionar _entre etiquetas XML @@ -180,7 +181,6 @@ Command _Entry = _Línea de comandos Select Co_mmand = _Seleccionar comandos _Run = _Ejecutar _Compile = _Compilar -_Filter Through = _Filtrar mediante _Adeptsense = _Adeptsense _Complete Symbol = _Completar símbolo Show _Documentation = _Mostrar documentación diff --git a/core/locales/locale.fr.conf b/core/locales/locale.fr.conf index b93d6eaa..162ef267 100644 --- a/core/locales/locale.fr.conf +++ b/core/locales/locale.fr.conf @@ -137,6 +137,7 @@ _Highlight Word = _Surligner mot Toggle _Block Comment = C_ommenter/Décommenter T_ranspose Characters = Ren_verser caractères _Join Lines = _Joindre les lignes +_Filter Through = _Filtrer _Select = _Sélectionner Select to _Matching Brace = Sélectionner jusqu'à l'accolade correspondante Select between _XML Tags = Sélectionner entre tags _XML @@ -180,7 +181,6 @@ Command _Entry = Ligne de _commande Select Co_mmand = Sélectionner co_mmande _Run = _Lancer _Compile = _Compiler -_Filter Through = _Filtrer _Adeptsense = _Adeptsense _Complete Symbol = _Compléter symbole Show _Documentation = Ouvrir _documentation diff --git a/core/locales/locale.ru.conf b/core/locales/locale.ru.conf index c8ff6228..682adbea 100644 --- a/core/locales/locale.ru.conf +++ b/core/locales/locale.ru.conf @@ -126,6 +126,7 @@ _Highlight Word = Под_светить слово Toggle _Block Comment = Изменить комментирование _блока T_ranspose Characters = Пе_реставить символы _Join Lines = _Объединить строки +_Filter Through = Пропустить через _фильтр _Select = В_ыделить Select to _Matching Brace = Выделить до _парной фигурной скобки Select between _XML Tags = Выделить меджу _XML тегами @@ -169,7 +170,6 @@ Command _Entry = Командная _строка Select Co_mmand = Выбрать _команду _Run = _Запустить _Compile = _Скомпилировать -_Filter Through = Пропустить через _фильтр _Adeptsense = _Adeptsense _Complete Symbol = _Завершить символ Show _Documentation = Показать _документацию diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index 9345743d..2be18168 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -536,4 +536,53 @@ end if buffer then set_highlight_properties() end events_connect(events.VIEW_NEW, set_highlight_properties) +--- +-- Passes selected or all buffer text to string shell command *cmd* as standard +-- input (stdin) and replaces the input text with the command's standard output +-- (stdout). +-- Standard input is as follows: +-- +-- 1. If text is selected and spans multiple lines, all text on the lines +-- containing the selection is used. However, if the end of the selection is at +-- the beginning of a line, only the EOL (end of line) characters from the +-- previous line are included as input. The rest of the line is excluded. +-- 2. If text is selected and spans a single line, only the selected text is +-- used. +-- 3. If no text is selected, the entire buffer is used. +-- @param cmd The Linux, BSD, Mac OSX, or Windows shell command to filter text +-- through. +-- @name filter_through +function M.filter_through(cmd) + local buffer = buffer + local s, e = buffer.selection_start, buffer.selection_end + local input + if s ~= e then -- use selected lines as input + local i, j = buffer:line_from_position(s), buffer:line_from_position(e) + if i < j then + s = buffer:position_from_line(i) + if buffer.column[e] > 0 then e = buffer:position_from_line(j + 1) end + end + input = buffer:text_range(s, e) + else -- use whole buffer as input + input = buffer:get_text() + end + local tmpfile = _USERHOME..'/.ft' + local f = io.open(tmpfile, 'wb') + f:write(input) + f:close() + local cmd = (not WIN32 and 'cat' or 'type')..' "'..tmpfile..'" | '..cmd + if WIN32 then cmd = cmd:gsub('/', '\\') end + local p = io.popen(cmd) + if s ~= e then + buffer.target_start, buffer.target_end = s, e + buffer:replace_target(p:read('*all')) + buffer:set_sel(buffer.target_start, buffer.target_end) + else + buffer:set_text(p:read('*all')) + buffer:goto_pos(s) + end + p:close() + os.remove(tmpfile) +end + return M diff --git a/modules/textadept/filter_through.lua b/modules/textadept/filter_through.lua deleted file mode 100644 index 59cb77b0..00000000 --- a/modules/textadept/filter_through.lua +++ /dev/null @@ -1,61 +0,0 @@ --- Copyright 2007-2013 Mitchell mitchell.att.foicica.com. See LICENSE. - -local M = {} - ---[[ This comment is for LuaDoc. ---- --- Filters text through shell commands. -module('_M.textadept.filter_through')]] - -local cat = not WIN32 and 'cat' or 'type' -local tmpfile = _USERHOME..'/.ft' - ---- --- Passes selected or all buffer text to string shell command *cmd* as standard --- input (stdin) and replaces the input text with the command's standard output --- (stdout). --- Standard input is as follows: --- --- 1. If text is selected and spans multiple lines, all text on the lines --- containing the selection is used. However, if the end of the selection is at --- the beginning of a line, only the EOL (end of line) characters from the --- previous line are included as input. The rest of the line is excluded. --- 2. If text is selected and spans a single line, only the selected text is --- used. --- 3. If no text is selected, the entire buffer is used. --- @param cmd The Linux, BSD, Mac OSX, or Windows shell command to filter text --- through. --- @name filter_through -function M.filter_through(cmd) - local buffer = buffer - local s, e = buffer.selection_start, buffer.selection_end - local input - if s ~= e then -- use selected lines as input - local i, j = buffer:line_from_position(s), buffer:line_from_position(e) - if i < j then - s = buffer:position_from_line(i) - if buffer.column[e] > 0 then e = buffer:position_from_line(j + 1) end - end - input = buffer:text_range(s, e) - else -- use whole buffer as input - input = buffer:get_text() - end - local f = io.open(tmpfile, 'wb') - f:write(input) - f:close() - local cmd = cat..' "'..tmpfile..'" | '..cmd - if WIN32 then cmd = cmd:gsub('/', '\\') end - local p = io.popen(cmd) - if s ~= e then - buffer.target_start, buffer.target_end = s, e - buffer:replace_target(p:read('*all')) - buffer:set_sel(buffer.target_start, buffer.target_end) - else - buffer:set_text(p:read('*all')) - buffer:goto_pos(s) - end - p:close() - os.remove(tmpfile) -end - -return M diff --git a/modules/textadept/init.lua b/modules/textadept/init.lua index 951c27b4..c751eef6 100644 --- a/modules/textadept/init.lua +++ b/modules/textadept/init.lua @@ -14,7 +14,6 @@ M.bookmarks = require 'textadept.bookmarks' require 'textadept.command_entry' M.editing = require 'textadept.editing' require 'textadept.find' -M.filter_through = require 'textadept.filter_through' M.mime_types = require 'textadept.mime_types' M.run = require 'textadept.run' M.session = require 'textadept.session' diff --git a/modules/textadept/keys.lua b/modules/textadept/keys.lua index d8b48ff2..c5f4cec1 100644 --- a/modules/textadept/keys.lua +++ b/modules/textadept/keys.lua @@ -41,6 +41,7 @@ local M = {} -- Ctrl+/ |^/ |M-/ |Toggle block comment -- Ctrl+T |^T |^T |Transpose characters -- Ctrl+Shift+J |^J |M-J |Join lines +-- Ctrl+| |⌘| |^\ |Filter text through -- Ctrl+Shift+M |^⇧M |M-S-M |Select to matching brace -- Ctrl+< |⌘< |M-< |Select between XML tags -- Ctrl+> |⌘> |None |Select in XML tag @@ -82,7 +83,6 @@ local M = {} -- Ctrl+Shift+E |⌘⇧E |M-S-C |Select command -- Ctrl+R |⌘R |^R |Run -- Ctrl+Shift+R |⌘⇧R |M-^R |Compile --- Ctrl+| |⌘||^\ |Filter text through -- Ctrl+Space |⌥⎋ |^Space |Complete symbol -- Ctrl+H |^H |M-H<br/>M-S-H|Show documentation -- Tab |⇥ |Tab |Expand snippet or next placeholder @@ -398,6 +398,8 @@ end keys[not OSX and not CURSES and 'c/' or 'm/'] = m_editing.block_comment keys.ct = m_editing.transpose_chars keys[not OSX and (not CURSES and 'cJ' or 'mj') or 'cj'] = m_editing.join_lines +keys[not OSX and (not CURSES and 'c|' or 'c\\') + or 'm|'] = {gui_ce.enter_mode, 'filter_through'} -- Select. keys[not CURSES and 'cM' or 'mM'] = {m_editing.match_brace, 'select'} keys[not OSX and not CURSES and 'c<' @@ -469,8 +471,6 @@ keys[not OSX and (not CURSES and 'cE' or 'mC') or 'mE'] = utils.select_command keys[not OSX and 'cr' or 'mr'] = m_textadept.run.run keys[not OSX and (not CURSES and 'cR' or 'cmr') or 'mR'] = m_textadept.run.compile -keys[not OSX and (not CURSES and 'c|' or 'c\\') - or 'm|'] = {gui_ce.enter_mode, 'filter_through'} -- Adeptsense. keys[not OSX and ((not CURSES or WIN32) and 'c ' or 'c@') or 'aesc'] = m_textadept.adeptsense.complete @@ -598,7 +598,7 @@ keys.lua_command = { ['\n'] = {gui_ce.finish_mode, gui_ce.execute_lua} } keys.filter_through = { - ['\n'] = {gui_ce.finish_mode, m_textadept.filter_through.filter_through}, + ['\n'] = {gui_ce.finish_mode, m_editing.filter_through}, } keys.find_incremental = { ['\n'] = gui_find.find_incremental_next, diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index ede42afc..2c9c3244 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -66,6 +66,7 @@ local menubar = { {_L['Toggle _Block Comment'], m_editing.block_comment}, {_L['T_ranspose Characters'], m_editing.transpose_chars}, {_L['_Join Lines'], m_editing.join_lines}, + {_L['_Filter Through'], {gui.command_entry.enter_mode, 'filter_through'}}, { title = _L['_Select'], {_L['Select to _Matching Brace'], {m_editing.match_brace, 'select'}}, {_L['Select between _XML Tags'], {m_editing.select_enclosed, '>', '<'}}, @@ -119,7 +120,6 @@ local menubar = { SEPARATOR, {_L['_Run'], m_textadept.run.run}, {_L['_Compile'], m_textadept.run.compile}, - {_L['_Filter Through'], {gui.command_entry.enter_mode, 'filter_through'}}, SEPARATOR, { title = _L['_Adeptsense'], {_L['_Complete Symbol'], m_textadept.adeptsense.complete}, |