diff options
Diffstat (limited to 'modules/textadept')
-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 |
5 files changed, 54 insertions, 67 deletions
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}, |