init.lua 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. -- Lumacs User Configuration File
  2. -- ============================================================================
  3. -- This file runs AFTER defaults.hpp, allowing you to customize and extend
  4. -- the default Emacs-like behavior. The mode system, keybindings, and commands
  5. -- are already set up - use this file to:
  6. -- 1. Load additional major modes
  7. -- 2. Load themes
  8. -- 3. Add custom keybindings
  9. -- 4. Define custom commands
  10. -- 5. Override default settings
  11. -- ============================================================================
  12. -- ============================================================================
  13. -- LOAD MAJOR MODES
  14. -- ============================================================================
  15. -- Load individual major mode definitions
  16. dofile("lua/major_modes/lua_mode.lua")
  17. dofile("lua/major_modes/c_cpp_mode.lua")
  18. -- ============================================================================
  19. -- LOAD THEMES
  20. -- ============================================================================
  21. -- Load individual theme definitions
  22. dofile("lua/themes/default.lua")
  23. dofile("lua/themes/dracula.lua")
  24. dofile("lua/themes/everforest-dark.lua")
  25. dofile("lua/themes/gruvbox-light.lua")
  26. dofile("lua/themes/nord.lua")
  27. dofile("lua/themes/solarized-dark.lua")
  28. dofile("lua/themes/catppuccin-mocha.lua")
  29. dofile("lua/themes/tokyo-night.lua")
  30. dofile("lua/themes/ayu-dark.lua")
  31. -- Load theme switching functions and keybindings
  32. dofile("lua/themes/themes_init.lua")
  33. -- ============================================================================
  34. -- MINOR MODES (User-defined extensions)
  35. -- ============================================================================
  36. -- Auto-save minor mode
  37. lumacs.define_minor_mode("auto-save-mode", {
  38. global = false,
  39. setup = function()
  40. editor:message("[auto-save-mode] Auto-save enabled")
  41. end,
  42. cleanup = function()
  43. editor:message("[auto-save-mode] Auto-save disabled")
  44. end
  45. })
  46. -- Line numbers minor mode (toggle control)
  47. lumacs.define_minor_mode("line-numbers-mode", {
  48. global = true,
  49. setup = function()
  50. editor.config:set("show_line_numbers", true)
  51. editor:message("[line-numbers-mode] Line numbers enabled")
  52. end,
  53. cleanup = function()
  54. editor.config:set("show_line_numbers", false)
  55. editor:message("[line-numbers-mode] Line numbers disabled")
  56. end
  57. })
  58. -- ============================================================================
  59. -- CUSTOM KEYBINDINGS (User overrides)
  60. -- ============================================================================
  61. -- Example: Custom keybinding for inserting timestamp
  62. editor:bind_key("C-c t", function()
  63. local cursor_pos = editor.cursor
  64. local timestamp = os.date("%Y-%m-%d %H:%M:%S")
  65. editor.buffer:insert(cursor_pos, timestamp)
  66. editor:message("Inserted timestamp")
  67. end)
  68. -- Example: Find TODO comments in buffer
  69. editor:bind_key("C-c o", function()
  70. local buf = editor.buffer
  71. local cursor = editor.cursor
  72. local search_start = lumacs.Position(cursor.line, cursor.column + 1)
  73. local res = buf:find("TODO", search_start)
  74. if res then
  75. editor.cursor = res.start
  76. editor:message("Found TODO at " .. res.start.line .. ":" .. res.start.column)
  77. else
  78. editor:message("No more TODOs found")
  79. end
  80. end)
  81. -- Line swapping (like VS Code Alt+Up/Down)
  82. local function swap_line_up()
  83. local buf = editor.buffer
  84. local cursor = editor.cursor
  85. if cursor.line == 0 then
  86. editor:message("Already at first line")
  87. return
  88. end
  89. local current_line = buf:line(cursor.line)
  90. local above_line = buf:line(cursor.line - 1)
  91. local delete_start = lumacs.Position(cursor.line - 1, 0)
  92. local delete_end = lumacs.Position(cursor.line, #current_line)
  93. buf:erase(lumacs.Range(delete_start, delete_end))
  94. local text = current_line .. "\n" .. above_line
  95. buf:insert(lumacs.Position(cursor.line - 1, 0), text)
  96. editor.cursor = lumacs.Position(cursor.line - 1, cursor.column)
  97. editor:message("Swapped line up")
  98. end
  99. local function swap_line_down()
  100. local buf = editor.buffer
  101. local cursor = editor.cursor
  102. if cursor.line >= buf:line_count() - 1 then
  103. editor:message("Already at last line")
  104. return
  105. end
  106. local current_line = buf:line(cursor.line)
  107. local below_line = buf:line(cursor.line + 1)
  108. local delete_start = lumacs.Position(cursor.line, 0)
  109. local delete_end = lumacs.Position(cursor.line + 1, #below_line)
  110. buf:erase(lumacs.Range(delete_start, delete_end))
  111. local text = below_line .. "\n" .. current_line
  112. buf:insert(lumacs.Position(cursor.line, 0), text)
  113. editor.cursor = lumacs.Position(cursor.line + 1, cursor.column)
  114. editor:message("Swapped line down")
  115. end
  116. editor:bind_key("M-ArrowUp", swap_line_up)
  117. editor:bind_key("M-ArrowDown", swap_line_down)
  118. -- ============================================================================
  119. -- CUSTOM COMMANDS
  120. -- ============================================================================
  121. -- Auto-theme based on time of day
  122. editor:register_command("auto-theme", "Automatically set theme based on time of day", function(args)
  123. local hour = tonumber(os.date("%H"))
  124. local theme_name
  125. if hour >= 6 and hour < 18 then
  126. theme_name = "gruvbox-light"
  127. elseif hour >= 18 and hour < 22 then
  128. theme_name = "everforest-dark"
  129. else
  130. theme_name = "nord"
  131. end
  132. local success, message = editor:execute_command("set-theme", {theme_name})
  133. if success then
  134. return {success = true, message = string.format("Auto-selected %s theme for %d:00", theme_name, hour)}
  135. else
  136. return {success = false, message = "Failed to auto-select theme: " .. message}
  137. end
  138. end, false)
  139. -- Theme demo command
  140. editor:register_command("theme-demo", "Demonstrate theme switching", function(args)
  141. local themes = {"solarized-dark", "nord", "gruvbox-light", "dracula"}
  142. local success, message = editor:execute_command("set-theme", {themes[1]})
  143. if success then
  144. return {success = true, message = "Theme demo - switched to " .. themes[1]}
  145. else
  146. return {success = false, message = "Demo failed: " .. message}
  147. end
  148. end, false)
  149. -- Evaluate Lua expression
  150. editor:register_command("eval-expression", "Evaluate Lua expression", function(args)
  151. if #args == 0 then
  152. return {success = false, message = "Lua expression required"}
  153. end
  154. local expr = table.concat(args, " ")
  155. local func, err = load("return " .. expr)
  156. if not func then
  157. return {success = false, message = "Parse error: " .. err}
  158. end
  159. local success, result = pcall(func)
  160. if success then
  161. return {success = true, message = tostring(result)}
  162. else
  163. return {success = false, message = "Error: " .. tostring(result)}
  164. end
  165. end, true, "s")
  166. -- ============================================================================
  167. -- CONFIGURATION OVERRIDES
  168. -- ============================================================================
  169. -- Uncomment to change defaults:
  170. -- editor.config:set("tab_width", 2)
  171. -- editor.config:set("indent_tabs_mode", true)
  172. -- editor.config:set("scroll_margin", 5)
  173. -- ============================================================================
  174. -- AUTO-ACTIVATE MAJOR MODE
  175. -- ============================================================================
  176. -- This is called after loading to ensure file-specific modes are activated
  177. lumacs.auto_activate_major_mode()
  178. -- Welcome message (override default)
  179. editor:message("Lumacs ready! C-h ? for help, M-x for commands, C-x t for themes")