Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions help/quoter.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
37 changes: 37 additions & 0 deletions modes.lua
Original file line number Diff line number Diff line change
@@ -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 :)
}
21 changes: 18 additions & 3 deletions quoter.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
VERSION = "1.0.2"
VERSION = "1.1.0"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is probably better to update repo.json in this pull request too if it will be changed in source code.


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

Expand All @@ -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
Comment on lines +29 to +34
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a typo and I realized that it wouldn't probably be good if an error is always displayed, so I think these changes can be done:

Suggested change
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
if not quotePairs then
bp.Buf:SetOption("quoter.mode", "default")
quotePairs = modes["default"]
micro.InfoBar():Message("Unknown quoter mode: \"" .. mode .. "\". Mode is set to \"default\".")
end

Copy link

@niten94 niten94 Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, using a different mode (default) is not expected so it's probably better to instead only display an error about changing it (like in settings.json then running reload), and returning false to not insert the character.


for i = 1, #quotePairs do
if r == quotePairs[i][1] or r == quotePairs[i][2] then
quote(bp, quotePairs[i][1], quotePairs[i][2])
Expand Down
7 changes: 7 additions & 0 deletions repo.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down