-
Notifications
You must be signed in to change notification settings - Fork 5
Added quoting modes #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
86851d2
95d35b5
308ec92
7a733c6
01ff9f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 :) | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -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 | ||||||||||||||||||||||||
|
Comment on lines
+29
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, using a different mode ( |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| for i = 1, #quotePairs do | ||||||||||||||||||||||||
| if r == quotePairs[i][1] or r == quotePairs[i][2] then | ||||||||||||||||||||||||
| quote(bp, quotePairs[i][1], quotePairs[i][2]) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
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.jsonin this pull request too if it will be changed in source code.