init.lua 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. -- LOAD PACKAGES
  35. -- ============================================================================
  36. -- which-key: Display available keybindings for prefix keys
  37. dofile("lua/packages/which-key.lua")
  38. -- doom-modeline: Doom Emacs-style modeline customization
  39. dofile("lua/packages/doom-modeline.lua")
  40. -- smartparens: Auto-pairing of brackets, quotes, etc.
  41. dofile("lua/packages/smartparens.lua")
  42. -- rainbow-delimiters: Colorize nested delimiters by depth
  43. dofile("lua/packages/rainbow-delimiters.lua")
  44. -- ido: Enhanced fuzzy completion (optional, provides utilities)
  45. dofile("lua/packages/ido.lua")
  46. -- ============================================================================
  47. -- MINOR MODES (User-defined extensions)
  48. -- ============================================================================
  49. -- Auto-save minor mode
  50. lumacs.define_minor_mode("auto-save-mode", {
  51. global = false,
  52. setup = function()
  53. editor:message("[auto-save-mode] Auto-save enabled")
  54. end,
  55. cleanup = function()
  56. editor:message("[auto-save-mode] Auto-save disabled")
  57. end
  58. })
  59. -- Line numbers minor mode (toggle control)
  60. lumacs.define_minor_mode("line-numbers-mode", {
  61. global = true,
  62. setup = function()
  63. editor.config:set("show_line_numbers", true)
  64. editor:message("[line-numbers-mode] Line numbers enabled")
  65. end,
  66. cleanup = function()
  67. editor.config:set("show_line_numbers", false)
  68. editor:message("[line-numbers-mode] Line numbers disabled")
  69. end
  70. })
  71. -- ============================================================================
  72. -- CUSTOM KEYBINDINGS (User overrides)
  73. -- ============================================================================
  74. -- Example: Custom keybinding for inserting timestamp
  75. editor:bind_key("C-c t", function()
  76. local cursor_pos = editor.cursor
  77. local timestamp = os.date("%Y-%m-%d %H:%M:%S")
  78. editor.buffer:insert(cursor_pos, timestamp)
  79. editor:message("Inserted timestamp")
  80. end)
  81. -- Example: Find TODO comments in buffer
  82. editor:bind_key("C-c o", function()
  83. local buf = editor.buffer
  84. local cursor = editor.cursor
  85. local search_start = lumacs.Position(cursor.line, cursor.column + 1)
  86. local res = buf:find("TODO", search_start)
  87. if res then
  88. editor.cursor = res.start
  89. editor:message("Found TODO at " .. res.start.line .. ":" .. res.start.column)
  90. else
  91. editor:message("No more TODOs found")
  92. end
  93. end)
  94. -- Line swapping (like VS Code Alt+Up/Down)
  95. local function swap_line_up()
  96. local buf = editor.buffer
  97. local cursor = editor.cursor
  98. if cursor.line == 0 then
  99. editor:message("Already at first line")
  100. return
  101. end
  102. local current_line = buf:line(cursor.line)
  103. local above_line = buf:line(cursor.line - 1)
  104. local delete_start = lumacs.Position(cursor.line - 1, 0)
  105. local delete_end = lumacs.Position(cursor.line, #current_line)
  106. buf:erase(lumacs.Range(delete_start, delete_end))
  107. local text = current_line .. "\n" .. above_line
  108. buf:insert(lumacs.Position(cursor.line - 1, 0), text)
  109. editor.cursor = lumacs.Position(cursor.line - 1, cursor.column)
  110. editor:message("Swapped line up")
  111. end
  112. local function swap_line_down()
  113. local buf = editor.buffer
  114. local cursor = editor.cursor
  115. if cursor.line >= buf:line_count() - 1 then
  116. editor:message("Already at last line")
  117. return
  118. end
  119. local current_line = buf:line(cursor.line)
  120. local below_line = buf:line(cursor.line + 1)
  121. local delete_start = lumacs.Position(cursor.line, 0)
  122. local delete_end = lumacs.Position(cursor.line + 1, #below_line)
  123. buf:erase(lumacs.Range(delete_start, delete_end))
  124. local text = below_line .. "\n" .. current_line
  125. buf:insert(lumacs.Position(cursor.line, 0), text)
  126. editor.cursor = lumacs.Position(cursor.line + 1, cursor.column)
  127. editor:message("Swapped line down")
  128. end
  129. editor:bind_key("M-ArrowUp", swap_line_up)
  130. editor:bind_key("M-ArrowDown", swap_line_down)
  131. -- ============================================================================
  132. -- CUSTOM COMMANDS
  133. -- ============================================================================
  134. -- Auto-theme based on time of day
  135. editor:register_command("auto-theme", "Automatically set theme based on time of day", function(args)
  136. local hour = tonumber(os.date("%H"))
  137. local theme_name
  138. if hour >= 6 and hour < 18 then
  139. theme_name = "gruvbox-light"
  140. elseif hour >= 18 and hour < 22 then
  141. theme_name = "everforest-dark"
  142. else
  143. theme_name = "nord"
  144. end
  145. local success, message = editor:execute_command("set-theme", {theme_name})
  146. if success then
  147. return {success = true, message = string.format("Auto-selected %s theme for %d:00", theme_name, hour)}
  148. else
  149. return {success = false, message = "Failed to auto-select theme: " .. message}
  150. end
  151. end, false)
  152. -- Theme demo command
  153. editor:register_command("theme-demo", "Demonstrate theme switching", function(args)
  154. local themes = {"solarized-dark", "nord", "gruvbox-light", "dracula"}
  155. local success, message = editor:execute_command("set-theme", {themes[1]})
  156. if success then
  157. return {success = true, message = "Theme demo - switched to " .. themes[1]}
  158. else
  159. return {success = false, message = "Demo failed: " .. message}
  160. end
  161. end, false)
  162. -- Evaluate Lua expression
  163. editor:register_command("eval-expression", "Evaluate Lua expression", function(args)
  164. if #args == 0 then
  165. return {success = false, message = "Lua expression required"}
  166. end
  167. local expr = table.concat(args, " ")
  168. local func, err = load("return " .. expr)
  169. if not func then
  170. return {success = false, message = "Parse error: " .. err}
  171. end
  172. local success, result = pcall(func)
  173. if success then
  174. return {success = true, message = tostring(result)}
  175. else
  176. return {success = false, message = "Error: " .. tostring(result)}
  177. end
  178. end, true, "s")
  179. -- ============================================================================
  180. -- CONFIGURATION OVERRIDES
  181. -- ============================================================================
  182. -- Uncomment to change defaults:
  183. -- editor.config:set("tab_width", 2)
  184. -- editor.config:set("indent_tabs_mode", true)
  185. -- editor.config:set("scroll_margin", 5)
  186. -- ============================================================================
  187. -- AUTO-ACTIVATE MAJOR MODE
  188. -- ============================================================================
  189. -- This is called after loading to ensure file-specific modes are activated
  190. lumacs.auto_activate_major_mode()
  191. -- Welcome message (override default)
  192. editor:message("Lumacs ready! C-h ? for help, M-x for commands, C-x t for themes")