quote.lua 569 B

12345678910111213141516171819202122232425262728293031
  1. local core = require "core"
  2. local command = require "core.command"
  3. local keymap = require "core.keymap"
  4. local escapes = {
  5. ["\\"] = "\\\\",
  6. ["\""] = "\\\"",
  7. ["\n"] = "\\n",
  8. ["\r"] = "\\r",
  9. ["\t"] = "\\t",
  10. ["\b"] = "\\b",
  11. }
  12. local function replace(chr)
  13. return escapes[chr] or string.format("\\x%02x", chr:byte())
  14. end
  15. command.add("core.docview", {
  16. ["quote:quote"] = function()
  17. core.active_view.doc:replace(function(text)
  18. return '"' .. text:gsub("[\0-\31\\\"]", replace) .. '"'
  19. end)
  20. end,
  21. })
  22. keymap.add {
  23. ["ctrl+'"] = "quote:quote",
  24. }