nvim/lua/settings.lua
ray 8d303ae4f4 add autocommand for theme update on SIGUSR1 signal
This change sets up an autocommand to update the colorscheme
when the system theme changes, triggered by the SIGUSR1 signal
from an external watcher script.
2026-01-19 19:21:17 +00:00

196 lines
6.8 KiB
Lua

-- Minimal settings for bootstrap and Phase 3.2
-- Disable unused language providers early; enable later only if a plugin requires them
vim.g.loaded_ruby_provider = 0
vim.g.loaded_perl_provider = 0
vim.g.loaded_node_provider = 0
-- Auto-detect system theme (Linux/GNOME)
local function set_background_from_system()
local handle = io.popen('gsettings get org.gnome.desktop.interface color-scheme 2>/dev/null')
if handle then
local result = handle:read("*a")
handle:close()
if result:match("dark") then
vim.o.background = 'dark'
else
vim.o.background = 'light'
end
end
end
-- Set background based on system theme on startup
set_background_from_system()
-- Handle SIGUSR1 signal to update theme when system theme changes
-- External watcher script (scripts/theme-watcher.sh) sends this signal
vim.api.nvim_create_autocmd('Signal', {
pattern = 'SIGUSR1',
callback = function()
set_background_from_system()
end,
desc = 'Update colorscheme when system theme changes',
})
-- Store initial working directory as project root
-- Used by netrw navigation to return to project root after following symlinks
vim.g.project_root = vim.fn.getcwd()
-- Prevent automatic directory changes when switching files
vim.opt.autochdir = false -- Keep working directory at project root
-- Enable project-local configuration files
vim.opt.exrc = true -- Load .nvim.lua from project root
vim.opt.secure = true -- Prompt before loading untrusted files
-- Custom tabline configuration
-- Load utils module for custom tabline function
local utils = require('utils')
-- Configure number of parent directories to show in full (default: 1)
-- Examples:
-- 1: /path/to/my/project/src/file.txt → pat/to/my/project/src/file.txt
-- 2: /path/to/my/project/src/file.txt → pat/to/my/project/src/file.txt
utils.tabline_full_parents = 1
-- Configure number of characters to show for shortened directories (default: 3)
-- Examples:
-- 3: /path/to/my → pat/to/my
-- 1: /path/to/my → p/t/m
utils.tabline_shorten_length = 4
-- Use custom tabline function
vim.opt.tabline = '%!v:lua.require("utils").custom_tabline()'
vim.opt.showtabline = 1 -- Show tabline only when there are 2+ tabs
-- Phase 3.2: non-plugin settings (legacy values where specified)
-- Completion UI for nvim-cmp
vim.opt.completeopt = { "menu", "menuone", "noselect" }
-- Built-in completion popup style (for Ctrl-X Ctrl-N/F completions)
-- Use floating window with border for native completion
vim.opt.pumblend = 0 -- No transparency
-- Note: Native completion (pumvisible) doesn't support custom borders like LSP floats
-- The Pmenu* highlight groups control its appearance
-- Spelling
vim.opt.spell = true
vim.opt.spelllang = { "en_gb" }
vim.opt.spelloptions = { "camel,noplainbuffer" }
-- Search behavior
vim.opt.ignorecase = true -- Case-insensitive search by default
vim.opt.smartcase = true -- Case-sensitive when search contains uppercase letters
vim.opt.incsearch = true -- Show matches as you type
vim.opt.hlsearch = true -- Highlight all search matches
-- Keyword characters (add $ for PHP/shell variables, - for CSS/HTML/config files)
vim.opt.iskeyword:append("$")
vim.opt.iskeyword:append("-")
-- Terminal and color support
vim.opt.termguicolors = true -- Enable 24-bit RGB color (required for colored underlines)
-- Visuals
vim.opt.showbreak = " ↳"
vim.opt.listchars = {
eol = "¬",
tab = "│ ",
trail = "~",
extends = ">",
precedes = "<",
space = "·",
}
-- Enable line numbers and relative line numbers
vim.opt.number = true
vim.opt.relativenumber = true
-- Scrolloff settings
vim.opt.scrolloff = 4
-- Phase 6.2: UX settings
vim.opt.signcolumn = "yes" -- Always show sign column (for LSP diagnostics, git signs, etc.)
vim.opt.cursorline = true -- Highlight current line
vim.opt.colorcolumn = "80,120" -- Visual guides at 80 and 120 characters
-- Phase 9.4: Default indentation (per-filetype overrides in after/ftplugin/)
vim.opt.tabstop = 4 -- Display tabs as 4 spaces
vim.opt.shiftwidth = 4 -- Indent by 4
vim.opt.softtabstop = 4 -- Backspace removes 4 spaces
vim.opt.expandtab = true -- Use spaces by default (overridden per-filetype)
vim.opt.autoindent = true -- Copy indent from current line when starting new line
vim.opt.smartindent = true -- Smart autoindenting (C-like programs, PHP, etc.)
-- Persistent undo
vim.opt.undofile = true -- Enable persistent undo
vim.opt.undodir = vim.fn.stdpath("config") .. "/undodir" -- Store undo files in config directory
-- LSP diagnostics configuration
vim.diagnostic.config({
virtual_text = {
spacing = 4,
prefix = "●",
-- Show severity (ERROR, WARN, INFO, HINT)
format = function(diagnostic)
return string.format("%s: %s", diagnostic.source or "", diagnostic.message)
end,
},
signs = false, -- Disable signs (redundant with background highlights and virtual text)
underline = true, -- Use background highlights on problematic text
update_in_insert = false, -- Don't update diagnostics while typing
severity_sort = true, -- Sort by severity (errors first)
float = {
border = "single",
source = "always", -- Show diagnostic source
header = "",
prefix = "",
},
})
-- Configure LSP floating windows with borders and padding
-- Custom border with box-drawing characters flush to window edges
-- Using heavy/light box-drawing characters positioned at cell edges
local border = {
{ "🭽", "FloatBorder" }, -- top-left corner
{ "▔", "FloatBorder" }, -- top horizontal line (at top edge)
{ "🭾", "FloatBorder" }, -- top-right corner
{ "▕", "FloatBorder" }, -- right vertical line (at right edge)
{ "🭿", "FloatBorder" }, -- bottom-right corner
{ "▁", "FloatBorder" }, -- bottom horizontal line (at bottom edge)
{ "🭼", "FloatBorder" }, -- bottom-left corner
{ "▏", "FloatBorder" }, -- left vertical line (at left edge)
}
-- Override the default open_floating_preview to add padding by modifying content
local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview
function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...)
opts = opts or {}
opts.border = opts.border or border
-- Add padding by wrapping content with empty lines and spacing
if type(contents) == "table" and #contents > 0 then
-- Add empty lines at top and bottom
table.insert(contents, 1, "")
table.insert(contents, 1, "")
table.insert(contents, "")
table.insert(contents, "")
-- Add horizontal padding (spaces) to each content line
for i = 3, #contents - 2 do
if type(contents[i]) == "string" then
contents[i] = " " .. contents[i] .. " "
end
end
end
return orig_util_open_floating_preview(contents, syntax, opts, ...)
end
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {
border = border,
})
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {
border = border,
})