init.lua 8.3 KB

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