core.lua 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. local core = require "core"
  2. local common = require "core.common"
  3. local command = require "core.command"
  4. local keymap = require "core.keymap"
  5. local Doc = require "core.doc"
  6. local DocView = require "core.docview"
  7. local LogView = require "core.logview"
  8. command.add(nil, {
  9. ["core:quit"] = function()
  10. core.quit()
  11. end,
  12. ["core:force-quit"] = function()
  13. core.quit(true)
  14. end,
  15. ["core:reload-module"] = function()
  16. core.command_view:enter("Reload Module", function(text, item)
  17. local text = item and item.text or text
  18. core.reload_module(text)
  19. core.log("Reloaded module %q", text)
  20. end, function(text)
  21. local items = {}
  22. for name in pairs(package.loaded) do
  23. table.insert(items, name)
  24. end
  25. return common.fuzzy_match(items, text)
  26. end)
  27. end,
  28. ["core:do-command"] = function()
  29. local commands = command.get_all_valid()
  30. core.command_view:enter("Do Command", function(text, item)
  31. if item then
  32. command.perform(item.command)
  33. end
  34. end, function(text)
  35. local res = common.fuzzy_match(commands, text)
  36. for i, name in ipairs(res) do
  37. res[i] = {
  38. text = command.prettify_name(name),
  39. info = keymap.get_binding(name),
  40. command = name,
  41. }
  42. end
  43. return res
  44. end)
  45. end,
  46. ["core:new-doc"] = function()
  47. core.root_view:open_doc(core.open_doc())
  48. end,
  49. ["core:open-project-file"] = function()
  50. core.command_view:enter("Open Project File", function(text, item)
  51. text = core.project_dir .. _PATHSEP .. (item and item.text or text)
  52. core.root_view:open_doc(core.open_doc(text))
  53. end, function(text)
  54. local files = {}
  55. for _, item in pairs(core.project_files) do
  56. if item.type == "file" then
  57. table.insert(files, item.filename:sub(#core.project_dir + 2))
  58. end
  59. end
  60. return common.fuzzy_match(files, text)
  61. end)
  62. end,
  63. ["core:open-file"] = function()
  64. core.command_view:enter("Open File", function(text)
  65. core.root_view:open_doc(core.open_doc(text))
  66. end, common.path_suggest)
  67. end,
  68. ["core:open-log"] = function()
  69. local node = core.root_view:get_active_node()
  70. node:add_view(LogView())
  71. end,
  72. })