aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/align_carets.lua9
-rw-r--r--plugins/autoinsert.lua10
-rw-r--r--plugins/bracketmatch.lua8
-rw-r--r--plugins/copyfilelocation.lua4
-rw-r--r--plugins/datetimestamps.lua16
-rw-r--r--plugins/eval.lua8
-rw-r--r--plugins/exec.lua8
-rw-r--r--plugins/force_syntax.lua31
-rw-r--r--plugins/ghmarkdown.lua6
-rw-r--r--plugins/gofmt.lua14
-rw-r--r--plugins/indent_convert.lua10
-rw-r--r--plugins/lfautoinsert.lua4
-rw-r--r--plugins/markers.lua10
-rw-r--r--plugins/minimap.lua4
-rw-r--r--plugins/openfilelocation.lua6
-rw-r--r--plugins/openselected.lua6
-rw-r--r--plugins/pdfview.lua6
-rw-r--r--plugins/primary_selection.lua4
-rw-r--r--plugins/regexreplacepreview.lua5
-rw-r--r--plugins/sort.lua6
-rw-r--r--plugins/spellcheck.lua4
-rw-r--r--plugins/texcompile.lua8
-rw-r--r--plugins/titleize.lua4
-rw-r--r--plugins/togglesnakecamel.lua4
24 files changed, 93 insertions, 102 deletions
diff --git a/plugins/align_carets.lua b/plugins/align_carets.lua
index 2a1db2a..d9e76a7 100644
--- a/plugins/align_carets.lua
+++ b/plugins/align_carets.lua
@@ -31,18 +31,17 @@ local function has_selections()
if not check_doc() then return false end
local selections, has_multilines = doc_get_selection_status(core.active_view.doc)
-- we want this to be true if there are only single lines selections
- return selections and not has_multilines
+ return selections and not has_multilines, core.active_view.doc
end
local function has_no_selections()
if not check_doc() then return false end
- return not doc_get_selection_status(core.active_view.doc)
+ return not doc_get_selection_status(core.active_view.doc), core.active_view.doc
end
-local function align(right)
- local doc = core.active_view.doc
+local function align(doc, right)
local max_col = 0
local done = { }
@@ -76,5 +75,5 @@ command.add(has_no_selections, {
command.add(has_selections, {
["doc:left-align-selections"] = align,
- ["doc:right-align-selections"] = function() align(true) end,
+ ["doc:right-align-selections"] = function(doc) align(doc, true) end,
})
diff --git a/plugins/autoinsert.lua b/plugins/autoinsert.lua
index c49887a..a02b6a5 100644
--- a/plugins/autoinsert.lua
+++ b/plugins/autoinsert.lua
@@ -81,13 +81,12 @@ end
local function predicate()
- return getmetatable(core.active_view) == DocView
- and not core.active_view.doc:has_selection()
+ return core.active_view:is(DocView)
+ and not core.active_view.doc:has_selection(), core.active_view.doc
end
command.add(predicate, {
- ["autoinsert:backspace"] = function()
- local doc = core.active_view.doc
+ ["autoinsert:backspace"] = function(doc)
local l, c = doc:get_selection()
if c > 1 then
local chr = doc:get_char(l, c)
@@ -99,8 +98,7 @@ command.add(predicate, {
command.perform "doc:backspace"
end,
- ["autoinsert:delete-to-previous-word-start"] = function()
- local doc = core.active_view.doc
+ ["autoinsert:delete-to-previous-word-start"] = function(doc)
local le, ce = translate.previous_word_start(doc, doc:get_selection())
while true do
local l, c = doc:get_selection()
diff --git a/plugins/bracketmatch.lua b/plugins/bracketmatch.lua
index 6119330..c32a428 100644
--- a/plugins/bracketmatch.lua
+++ b/plugins/bracketmatch.lua
@@ -245,16 +245,16 @@ end
command.add("core.docview", {
- ["bracket-match:move-to-matching"] = function()
+ ["bracket-match:move-to-matching"] = function(dv)
update_state()
if state.line2 then
- core.active_view.doc:set_selection(state.line2, state.col2)
+ dv.doc:set_selection(state.line2, state.col2)
end
end,
- ["bracket-match:select-to-matching"] = function()
+ ["bracket-match:select-to-matching"] = function(dv)
update_state()
if state.line2 then
- core.active_view.doc:set_selection(state.line, state.col, state.line2, state.col2 + select_adj)
+ dv.doc:set_selection(state.line, state.col, state.line2, state.col2 + select_adj)
end
end,
})
diff --git a/plugins/copyfilelocation.lua b/plugins/copyfilelocation.lua
index eb7b1a9..34f55d8 100644
--- a/plugins/copyfilelocation.lua
+++ b/plugins/copyfilelocation.lua
@@ -3,8 +3,8 @@ local core = require "core"
local command = require "core.command"
command.add("core.docview", {
- ["copy-file-location:copy-file-location"] = function()
- local doc = core.active_view.doc
+ ["copy-file-location:copy-file-location"] = function(dv)
+ local doc = dv.doc
if not doc.abs_filename then
core.error "Cannot copy location of unsaved doc"
return
diff --git a/plugins/datetimestamps.lua b/plugins/datetimestamps.lua
index f16af83..4867c08 100644
--- a/plugins/datetimestamps.lua
+++ b/plugins/datetimestamps.lua
@@ -57,29 +57,29 @@ config.plugins.datetimestamps = common.merge({
}
}, config.plugins.datetimestamps)
-local function datestamp()
+local function datestamp(dv)
local sOut = os.date(config.plugins.datetimestamps.format_datestamp)
- core.active_view.doc:text_input(sOut)
+ dv.doc:text_input(sOut)
end
-local function datetimestamp()
+local function datetimestamp(dv)
local sOut = os.date(config.plugins.datetimestamps.format_datetimestamp)
- core.active_view.doc:text_input(sOut)
+ dv.doc:text_input(sOut)
end
-local function timestamp()
+local function timestamp(dv)
local sOut = os.date(config.plugins.datetimestamps.format_timestamp)
- core.active_view.doc:text_input(sOut)
+ dv.doc:text_input(sOut)
end
command.add("core.docview", {
["datetimestamps:insert-datestamp"] = datestamp,
["datetimestamps:insert-timestamp"] = timestamp,
["datetimestamps:insert-datetimestamp"] = datetimestamp,
- ["datetimestamps:insert-custom"] = function()
+ ["datetimestamps:insert-custom"] = function(dv)
core.command_view:enter("Date format eg: %H:%M:%S", {
submit = function(cmd)
- core.active_view.doc:text_input(os.date(cmd) or "")
+ dv.doc:text_input(os.date(cmd) or "")
end
})
end,
diff --git a/plugins/eval.lua b/plugins/eval.lua
index c2eb19e..1f507fb 100644
--- a/plugins/eval.lua
+++ b/plugins/eval.lua
@@ -12,18 +12,18 @@ end
command.add("core.docview", {
- ["eval:insert"] = function()
+ ["eval:insert"] = function(dv)
core.command_view:enter("Evaluate And Insert Result", {
submit = function(cmd)
- core.active_view.doc:text_input(eval(cmd))
+ dv.doc:text_input(eval(cmd))
end
})
end,
- ["eval:replace"] = function()
+ ["eval:replace"] = function(dv)
core.command_view:enter("Evaluate And Replace With Result", {
submit = function(cmd)
- core.active_view.doc:replace(function(str)
+ dv.doc:replace(function(str)
return eval(cmd)
end)
end
diff --git a/plugins/exec.lua b/plugins/exec.lua
index b8f61c5..f05d2b6 100644
--- a/plugins/exec.lua
+++ b/plugins/exec.lua
@@ -27,18 +27,18 @@ end
command.add("core.docview", {
- ["exec:insert"] = function()
+ ["exec:insert"] = function(dv)
core.command_view:enter("Insert Result Of Command", {
submit = function(cmd)
- core.active_view.doc:text_input(exec(cmd))
+ dv.doc:text_input(exec(cmd))
end
})
end,
- ["exec:replace"] = function()
+ ["exec:replace"] = function(dv)
core.command_view:enter("Replace With Result Of Command", {
submit = function(cmd)
- core.active_view.doc:replace(function(str)
+ dv.doc:replace(function(str)
return exec(
"printf %b " .. printfb_quote(str:gsub("%\n$", "") .. "\n") .. " | eval '' " .. shell_quote(cmd),
str:find("%\n$")
diff --git a/plugins/force_syntax.lua b/plugins/force_syntax.lua
index ae5a138..102ab01 100644
--- a/plugins/force_syntax.lua
+++ b/plugins/force_syntax.lua
@@ -8,9 +8,9 @@ local style = require "core.style"
local StatusView = require "core.statusview"
local DocView = require "core.docview"
-local function doc()
- if core.active_view and getmetatable(core.active_view) == DocView then return core.active_view.doc end
- if core.last_active_view and getmetatable(core.last_active_view) == DocView then return core.last_active_view.doc end
+local function get_doc()
+ if core.active_view then return core.active_view:is(DocView), core.active_view.doc end
+ if core.last_active_view then return core.last_active_view:is(DocView), core.last_active_view.doc end
end
-- Force plaintext syntax to have a name
@@ -40,13 +40,12 @@ local function get_syntax_name(s)
end
core.status_view:add_item({
- predicate = function()
- return core.active_view and getmetatable(core.active_view) == DocView
- end,
+ predicate = get_doc,
name = "doc:syntax",
alignment = StatusView.Item.RIGHT,
get_item = function()
- local syntax_name = get_syntax_name(doc().syntax)
+ local _, doc = get_doc()
+ local syntax_name = get_syntax_name(doc.syntax)
return {
style.text,
syntax_name
@@ -58,9 +57,9 @@ core.status_view:add_item({
separator = core.status_view.separator2
})
-local function get_syntax_list()
+local function get_syntax_list(doc)
local pt_name = plain_text_syntax.name
- if doc().syntax == plain_text_syntax then
+ if doc.syntax == plain_text_syntax then
pt_name = "Current: "..pt_name
end
local list = { ["Auto detect"] = false,
@@ -75,7 +74,7 @@ local function get_syntax_list()
i = i + 1
fullname = name.." ("..i..")"
end
- if doc().syntax == s then
+ if doc.syntax == s then
fullname = "Current: "..fullname
end
list[fullname] = s
@@ -101,17 +100,17 @@ local function bias_sorter(a, b)
return sorter(a, b)
end
-command.add("core.docview", {
+command.add(get_doc, {
["force-syntax:select-file-syntax"] =
- function()
+ function(doc)
core.command_view:enter("Set syntax for this file", {
submit = function(text, item)
- local list, _ = get_syntax_list()
- doc().force_syntax = list[item.text]
- doc():reset_syntax()
+ local list, _ = get_syntax_list(doc)
+ doc.force_syntax = list[item.text]
+ doc:reset_syntax()
end,
suggest = function(text)
- local _, keylist = get_syntax_list()
+ local _, keylist = get_syntax_list(doc)
local res = common.fuzzy_match(keylist, text)
-- Force Current and Auto detect syntax to the bottom
-- if the text is empty
diff --git a/plugins/ghmarkdown.lua b/plugins/ghmarkdown.lua
index 244b144..c7fabdd 100644
--- a/plugins/ghmarkdown.lua
+++ b/plugins/ghmarkdown.lua
@@ -40,10 +40,8 @@ local html = [[
]]
-command.add("core.docview", {
- ["ghmarkdown:show-preview"] = function()
- local dv = core.active_view
-
+command.add("core.docview!", {
+ ["ghmarkdown:show-preview"] = function(dv)
local content = dv.doc:get_text(1, 1, math.huge, math.huge)
local esc = { ['"'] = '\\"', ["\n"] = '\\n' }
local text = html:gsub("${(.-)}", {
diff --git a/plugins/gofmt.lua b/plugins/gofmt.lua
index fec95e4..a8e3576 100644
--- a/plugins/gofmt.lua
+++ b/plugins/gofmt.lua
@@ -29,17 +29,17 @@ local function update_doc(cmd, doc)
doc:set_selection(table.unpack(sel))
end
-command.add("core.docview", {
- ["gofmt:gofmt"] = function()
- update_doc("gofmt", core.active_view.doc)
+command.add("core.docview!", {
+ ["gofmt:gofmt"] = function(dv)
+ update_doc("gofmt", dv.doc)
end,
- ["gofmt:goimports"] = function()
- update_doc("goimports", core.active_view.doc)
+ ["gofmt:goimports"] = function(dv)
+ update_doc("goimports", dv.doc)
end,
- ["gofmt:goreturns"] = function()
- update_doc("goreturns", core.active_view.doc)
+ ["gofmt:goreturns"] = function(dv)
+ update_doc("goreturns", dv.doc)
end,
})
diff --git a/plugins/indent_convert.lua b/plugins/indent_convert.lua
index 3a950f5..45d8640 100644
--- a/plugins/indent_convert.lua
+++ b/plugins/indent_convert.lua
@@ -102,8 +102,8 @@ local function get_indent_size(doc)
return indent_size
end
-local function tabs_to_spaces()
- local doc = core.active_view.doc
+local function tabs_to_spaces(dv)
+ local doc = dv.doc
local indent_size = get_indent_size(doc)
local selections = doc.selections
doc:replace(replacer(doc, tabs_replacer, indent_size))
@@ -118,8 +118,8 @@ local function tabs_to_spaces()
end
end
-local function spaces_to_tabs()
- local doc = core.active_view.doc
+local function spaces_to_tabs(dv)
+ local doc = dv.doc
local indent_size = get_indent_size(doc)
local selections = doc.selections
doc:replace(replacer(doc, spaces_replacer, indent_size))
@@ -134,7 +134,7 @@ local function spaces_to_tabs()
end
end
-command.add("core.docview", {
+command.add("core.docview!", {
["indent-convert:tabs-to-spaces"] = tabs_to_spaces,
["indent-convert:spaces-to-tabs"] = spaces_to_tabs
}
diff --git a/plugins/lfautoinsert.lua b/plugins/lfautoinsert.lua
index ae3da75..add57f4 100644
--- a/plugins/lfautoinsert.lua
+++ b/plugins/lfautoinsert.lua
@@ -65,10 +65,10 @@ local function indent_size(doc, line)
end
command.add("core.docview!", {
- ["autoinsert:newline"] = function()
+ ["autoinsert:newline"] = function(dv)
command.perform("doc:newline")
- local doc = core.active_view.doc
+ local doc = dv.doc
local line, col = doc:get_selection()
local text = doc.lines[line - 1]
diff --git a/plugins/markers.lua b/plugins/markers.lua
index e2ec68e..d1a3aae 100644
--- a/plugins/markers.lua
+++ b/plugins/markers.lua
@@ -61,9 +61,9 @@ function DocView:draw_line_gutter(line, x, y, width)
end
-command.add("core.docview", {
- ["markers:toggle-marker"] = function()
- local doc = core.active_view.doc
+command.add("core.docview!", {
+ ["markers:toggle-marker"] = function(dv)
+ local doc = dv.doc
local line = doc:get_selection()
local markers = cache[doc]
@@ -74,8 +74,8 @@ command.add("core.docview", {
end
end,
- ["markers:go-to-next-marker"] = function()
- local doc = core.active_view.doc
+ ["markers:go-to-next-marker"] = function(dv)
+ local doc = dv.doc
local line = doc:get_selection()
local markers = cache[doc]
diff --git a/plugins/minimap.lua b/plugins/minimap.lua
index c2dd8f0..603e173 100644
--- a/plugins/minimap.lua
+++ b/plugins/minimap.lua
@@ -652,8 +652,8 @@ command.add(nil, {
})
command.add("core.docview!", {
- ["minimap:toggle-visibility-for-current-view"] = function()
- local sb = core.active_view.v_scrollbar
+ ["minimap:toggle-visibility-for-current-view"] = function(dv)
+ local sb = dv.v_scrollbar
if sb.enabled ~= nil then
sb.enabled = not sb.enabled
else
diff --git a/plugins/openfilelocation.lua b/plugins/openfilelocation.lua
index 603c7b6..dd88248 100644
--- a/plugins/openfilelocation.lua
+++ b/plugins/openfilelocation.lua
@@ -28,9 +28,9 @@ config.plugins.openfilelocation = common.merge({
}
}, config.plugins.openfilelocation)
-command.add("core.docview", {
- ["open-file-location:open-file-location"] = function()
- local doc = core.active_view.doc
+command.add("core.docview!", {
+ ["open-file-location:open-file-location"] = function(dv)
+ local doc = dv.doc
if not doc.filename then
core.error "Cannot open location of unsaved doc"
return
diff --git a/plugins/openselected.lua b/plugins/openselected.lua
index 6333da9..955c144 100644
--- a/plugins/openselected.lua
+++ b/plugins/openselected.lua
@@ -31,9 +31,9 @@ config.plugins.openselected = common.merge({
}
}, config.plugins.openselected)
-command.add("core.docview", {
- ["open-selected:open-selected"] = function()
- local doc = core.active_view.doc
+command.add("core.docview!", {
+ ["open-selected:open-selected"] = function(dv)
+ local doc = dv.doc
if not doc:has_selection() then
core.error("No text selected")
return
diff --git a/plugins/pdfview.lua b/plugins/pdfview.lua
index 199584e..56d5eba 100644
--- a/plugins/pdfview.lua
+++ b/plugins/pdfview.lua
@@ -3,10 +3,8 @@ local core = require "core"
local command = require "core.command"
local keymap = require "core.keymap"
-command.add("core.docview", {
- ["pdfview:show-preview"] = function()
- local av = core.active_view
-
+command.add("core.docview!", {
+ ["pdfview:show-preview"] = function(av)
-- User's home directory
local homedir = ""
diff --git a/plugins/primary_selection.lua b/plugins/primary_selection.lua
index 388caf0..4f8d71a 100644
--- a/plugins/primary_selection.lua
+++ b/plugins/primary_selection.lua
@@ -154,7 +154,7 @@ end
command.add("core.docview", {
- ["primary-selection:paste"] = function(x, y, clicks, ...)
+ ["primary-selection:paste"] = function(dv, x, y, clicks, ...)
if not config.plugins.primary_selection.command_out
or #config.plugins.primary_selection.command_out == 0 then
core.warn("No primary selection paste command set")
@@ -176,7 +176,7 @@ command.add("core.docview", {
table.insert(text, buffer or "")
until not buffer
if #text > 0 then
- core.active_view.doc:text_input(table.concat(text))
+ dv.doc:text_input(table.concat(text))
end
end
})
diff --git a/plugins/regexreplacepreview.lua b/plugins/regexreplacepreview.lua
index 18d692b..dfc9e45 100644
--- a/plugins/regexreplacepreview.lua
+++ b/plugins/regexreplacepreview.lua
@@ -87,10 +87,9 @@ local function regex_replace_file(view, pattern, old_lines, raw, start_line, end
return old_lines, line_scroll ~= nil
end
-command.add("core.docview", {
- ["regex-replace-preview:find-replace-regex"] = function()
+command.add("core.docview!", {
+ ["regex-replace-preview:find-replace-regex"] = function(view)
local old_lines = {}
- local view = core.active_view
local doc = view.doc
local original_selection = { doc:get_selection(true) }
local selection = doc:has_selection() and { doc:get_selection(true) } or {}
diff --git a/plugins/sort.lua b/plugins/sort.lua
index 1ad4034..b933bb4 100644
--- a/plugins/sort.lua
+++ b/plugins/sort.lua
@@ -11,9 +11,9 @@ local function split_lines(text)
return res
end
-command.add("core.docview", {
- ["sort:sort"] = function()
- local doc = core.active_view.doc
+command.add("core.docview!", {
+ ["sort:sort"] = function(dv)
+ local doc = dv.doc
local l1, c1, l2, c2, swap = doc:get_selection(true)
l1, c1 = translate.start_of_line(doc, l1, c1)
diff --git a/plugins/spellcheck.lua b/plugins/spellcheck.lua
index f55cf1f..29db94c 100644
--- a/plugins/spellcheck.lua
+++ b/plugins/spellcheck.lua
@@ -181,7 +181,7 @@ command.add("core.docview", {
end,
- ["spell-check:replace"] = function()
+ ["spell-check:replace"] = function(dv)
local word, s, e = get_word_at_caret()
-- find suggestions
@@ -202,7 +202,7 @@ command.add("core.docview", {
-- sort suggestions table and convert to properly-capitalized text
table.sort(suggestions, function(a, b) return a.diff < b.diff end)
- local doc = core.active_view.doc
+ local doc = dv.doc
local line = doc:get_selection()
local has_upper = doc.lines[line]:sub(s, s):match("[A-Z]")
for k, v in pairs(suggestions) do
diff --git a/plugins/texcompile.lua b/plugins/texcompile.lua
index af31aed..557e404 100644
--- a/plugins/texcompile.lua
+++ b/plugins/texcompile.lua
@@ -34,11 +34,11 @@ local keymap = require "core.keymap"
-- Note that in the example we have used "^ " for spaces that appear in the path.
-- It is required on Windows for path or file names that contains space characters.
-command.add("core.docview", {
- ["texcompile:tex-compile"] = function()
+command.add("core.docview!", {
+ ["texcompile:tex-compile"] = function(dv)
-- The current (La)TeX file and path
- local texname = core.active_view:get_name()
- local texpath = common.dirname(core.active_view:get_filename())
+ local texname = dv:get_name()
+ local texpath = common.dirname(dv:get_filename())
local pdfname = texname:gsub("%.tex$", ".pdf")
-- LaTeX compiler as configured in config.texcompile
diff --git a/plugins/titleize.lua b/plugins/titleize.lua
index 16d20b0..096265c 100644
--- a/plugins/titleize.lua
+++ b/plugins/titleize.lua
@@ -3,8 +3,8 @@ local core = require "core"
local command = require "core.command"
command.add("core.docview", {
- ["titleize:titleize"] = function()
- core.active_view.doc:replace(function(text)
+ ["titleize:titleize"] = function(dv)
+ dv.doc:replace(function(text)
return text:gsub("%f[%w](%w)", string.upper)
end)
end,
diff --git a/plugins/togglesnakecamel.lua b/plugins/togglesnakecamel.lua
index c055933..fd1da13 100644
--- a/plugins/togglesnakecamel.lua
+++ b/plugins/togglesnakecamel.lua
@@ -21,8 +21,8 @@ end
command.add("core.docview", {
- ["toggle-snake-camel:toggle"] = function()
- core.active_view.doc:replace(function(text)
+ ["toggle-snake-camel:toggle"] = function(dv)
+ dv.doc:replace(function(text)
return text:gsub("[%w][%w%d_]*", toggle)
end)
end,