diff --git a/help/quoter.md b/help/quoter.md index df48896..5b123a8 100644 --- a/help/quoter.md +++ b/help/quoter.md @@ -2,11 +2,45 @@ ## Enable Plugin -Once installed, enable the plugin by setting quoter.enable to on - +Once installed, enable the plugin by setting `quoter.enable` to on: `set quoter.enable on` ## Use Select some text and press a quote or bracket button to surround the selected text with quotes or matching brackets. + +## Quoting modes + +Depending on the type of the current file, Quoter can apply different quote and +grouping symbols. For example, while in most languages backticks are usually +used in pairs, as in `` `backticked` ``, to represent strings, infix operators, +etc., in latex, to quote text, one would quote it with a backtick and an +apostrophe, as ` ``quote'' `. Quoting modes allow to resolve these conflicting +cases. + +However, these modes are not applied automatically but can be set by the user +in the `settings.json` file, in a per filetype basis, like other user settings, +through the `quoter.mode` setting. For example, setting the mode to tex for tex +files: + +```json +{ + "ft:tex": { + "quoter.mode": "tex" + } +} +``` + +The available modes are: `default`, `c_style` and `tex`. The mode of the +current file can also be changed in the command-bar with: +`setlocal quoter.mode 'mode'` + +Check the file `micro-quoter/modes.lua` in the plugin folder to see the +differences between the different modes. + +### Extending Quoting Modes + +New modes can be added by extending the `modes` table. If you have sophisticated +quoting requisites that fall outside the implemented modes, feel free to extend +the `modes` table and do a pull request [here](https://github.com/sparques/micro-quoter). diff --git a/modes.lua b/modes.lua new file mode 100644 index 0000000..0a684ca --- /dev/null +++ b/modes.lua @@ -0,0 +1,37 @@ +-- you can add more quoting modes in this table +modes = { + -- default quote pairs + default = { + {"\"","\""}, + {"'","'"}, + {"(",")"}, + {"{","}"}, + {"[","]"}, + {"<",">"}, + {"`","`"} + }, + -- extend "default" by allowing to easily introduce /* block comments */ + c_style = { + {"\"","\""}, + {"'","'"}, + {"(",")"}, + {"{","}"}, + {"[","]"}, + {"<",">"}, + {"`","`"}, + {"/","/"}, + {"*","*"}, + }, + -- use `' for quoting text and $ for math mode + tex = { + {"\"","\""}, + {"'","'"}, + {"(",")"}, + {"{","}"}, + {"[","]"}, + {"<",">"}, + {"`","'"}, + {"$","$"}, + }, + -- if you have any quoting suggestions, suggest them :) +} diff --git a/quoter.lua b/quoter.lua index 006ace1..aff7f6a 100644 --- a/quoter.lua +++ b/quoter.lua @@ -1,13 +1,16 @@ -VERSION = "1.0.2" +VERSION = "1.1.0" +local micro = import("micro") local config = import("micro/config") -- TODO: auto-indent when {} are used? -local quotePairs = {{"\"", "\""}, {"'","'"}, {"`","`"}, {"(",")"}, {"{","}"}, {"[","]"}, {"<",">"}, {"`","`"}} +function preinit() + config.RegisterCommonOption("quoter", "enable", true) + config.RegisterCommonOption("quoter", "mode", "default") +end function init() - config.RegisterCommonOption("quoter", "enable", true) config.AddRuntimeFile("quoter", config.RTHelp, "help/quoter.md") end @@ -18,6 +21,18 @@ function preRune(bp, r) if bp.Cursor:HasSelection() == false then return true end + + -- try using user settings, or use "default" + local mode = bp.Buf.Settings["quoter.mode"] + local quotePairs = modes[mode] + + if not quotePairs then + micro.InfoBar():Error("Unknown quoter mode: \"" .. mode .. "\". Appliying mode \"default\".") + -- config.SetGlobalOption("quoter.mode", "default") + mode = "default" + quotePairs = modes["default"] + end + for i = 1, #quotePairs do if r == quotePairs[i][1] or r == quotePairs[i][2] then quote(bp, quotePairs[i][1], quotePairs[i][2]) diff --git a/repo.json b/repo.json index 2d7eee3..48498f1 100644 --- a/repo.json +++ b/repo.json @@ -8,6 +8,13 @@ "quote", "autosurround" ], "Versions": [ + { + "Version": "1.1.0", + "Url": "https://github.com/sparques/micro-quoter/archive/v1.1.0.zip", + "Require": { + "micro": ">=2.0.0" + } + }, { "Version": "1.0.3", "Url": "https://github.com/sparques/micro-quoter/archive/v1.0.3.zip",