From 6c7cb500350377e89a930228747c4aa5f13e8716 Mon Sep 17 00:00:00 2001 From: jgmdev Date: Fri, 11 Mar 2022 07:03:46 -0400 Subject: autowrap: fixed missing require 'core.common', added toggle command --- plugins/autowrap.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'plugins/autowrap.lua') diff --git a/plugins/autowrap.lua b/plugins/autowrap.lua index 0f34eec..e318fd3 100644 --- a/plugins/autowrap.lua +++ b/plugins/autowrap.lua @@ -2,9 +2,13 @@ require "plugins.reflow" local config = require "core.config" local command = require "core.command" +local common = require "core.common" local DocView = require "core.docview" -config.plugins.autowrap = common.merge({ files = { "%.md$", "%.txt$" } }, config.plugins.autowrap) +config.plugins.autowrap = common.merge({ + enable = false, + files = { "%.md$", "%.txt$" } +}, config.plugins.autowrap) local on_text_input = DocView.on_text_input @@ -12,6 +16,8 @@ local on_text_input = DocView.on_text_input DocView.on_text_input = function(self, ...) on_text_input(self, ...) + if not config.plugins.autowrap.enable then return end + -- early-exit if the filename does not match a file type pattern local filename = self.doc.filename or "" local matched = false @@ -35,3 +41,9 @@ DocView.on_text_input = function(self, ...) command.perform("doc:move-to-end-of-line") end end + +command.add(nil, { + ["auto-wrap:toggle"] = function() + config.plugins.autowrap.enable = not config.plugins.autowrap.enable + end +}) -- cgit v1.2.3