init.lua 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. -- Lumacs Configuration File
  2. -- This file is executed on startup and allows you to customize keybindings,
  3. -- create commands, and extend the editor with Lua.
  4. print("Loading init.lua...")
  5. -- Example: Custom keybindings
  6. -- Syntax: bind_key("key", function() ... end)
  7. -- Emacs-style navigation (Ctrl+N/P for next/previous line)
  8. bind_key("C-n", function()
  9. editor:move_down()
  10. message("Moved down")
  11. end)
  12. bind_key("C-p", function()
  13. editor:move_up()
  14. message("Moved up")
  15. end)
  16. bind_key("C-f", function()
  17. editor:move_right()
  18. end)
  19. bind_key("C-b", function()
  20. editor:move_left()
  21. end)
  22. -- Emacs-style line navigation
  23. bind_key("C-a", function()
  24. editor:move_to_line_start()
  25. end)
  26. bind_key("C-e", function()
  27. editor:move_to_line_end()
  28. end)
  29. -- Custom command: Save buffer
  30. bind_key("C-s", function()
  31. local buf = editor:buffer()
  32. if buf:save() then
  33. message("Buffer saved: " .. buf:name())
  34. else
  35. message("Failed to save buffer")
  36. end
  37. end)
  38. -- Custom command: Insert timestamp
  39. bind_key("C-t", function()
  40. local cursor_pos = editor:cursor()
  41. local timestamp = os.date("%Y-%m-%d %H:%M:%S")
  42. editor:buffer():insert(cursor_pos, timestamp)
  43. message("Inserted timestamp")
  44. end)
  45. -- Example: Helper functions you can define
  46. function goto_line(line_num)
  47. local pos = lumacs.Position(line_num - 1, 0)
  48. editor:set_cursor(pos)
  49. message("Jumped to line " .. line_num)
  50. end
  51. -- Example: Buffer inspection
  52. function buffer_info()
  53. local buf = editor:buffer()
  54. local cursor = editor:cursor()
  55. message(string.format(
  56. "Buffer: %s | Lines: %d | Cursor: %d,%d | Modified: %s",
  57. buf:name(),
  58. buf:line_count(),
  59. cursor.line + 1,
  60. cursor.column + 1,
  61. buf:is_modified() and "yes" or "no"
  62. ))
  63. end
  64. -- Bind to show buffer info
  65. bind_key("C-i", buffer_info)
  66. -- Welcome message
  67. message("Lumacs initialized! Press C-i for buffer info, C-s to save.")