diff --git a/.config/kitty/kitty.conf b/.config/kitty/kitty.conf index 9ded724..a98e784 100644 --- a/.config/kitty/kitty.conf +++ b/.config/kitty/kitty.conf @@ -38,7 +38,7 @@ scrollback_pager bash -c "exec nvim 63<&0 0 q enabled_layouts tall,stack,fat,grid -kitty_mod alt +kitty_mod ctrl+alt map alt+f no_op map alt+b no_op diff --git a/.config/magit/early-init.el b/.config/magit/early-init.el new file mode 100644 index 0000000..f4a6336 --- /dev/null +++ b/.config/magit/early-init.el @@ -0,0 +1,45 @@ +;; -*- lexical-binding: t -*- +(defvar default-file-name-handler-alist file-name-handler-alist) +(setq file-name-handler-alist nil) +(setq gc-cons-threshold (expt 2 32)) + +(add-hook 'emacs-startup-hook + (lambda () + "Restore defalut values after init." + (setq file-name-handler-alist default-file-name-handler-alist) + (if (boundp 'after-focus-change-function) + (add-function :after after-focus-change-function + (lambda () + (unless (frame-focus-state) + (garbage-collect)))) + (add-hook 'focus-out-hook 'garbage-collect)))) + +(setq native-comp-async-report-warnings-errors nil) +(setq native-comp-deferred-compilation t) +(setq max-specpdl-size 1200) +(setq max-lisp-eval-depth 800) + +(scroll-bar-mode -1) +(tool-bar-mode -1) +(menu-bar-mode -1) +(tooltip-mode -1) +(setq package-enable-at-startup nil) + +(setq load-prefer-newer nil) + +(setq safe-local-variable-values + '((org-src-preserve-indentation . t) + (eval add-hook 'after-save-hook + '(lambda nil + (org-babel-tangle)) + nil t))) + +(setq default-input-method nil) +(setq utf-translate-cjk-mode nil) ; disable CJK coding/encoding (Chinese/Japanese/Korean characters) +(set-language-environment 'utf-8) +(set-keyboard-coding-system 'utf-8-mac) ; For old Carbon emacs on OS X only +(setq locale-coding-system 'utf-8) +(set-default-coding-systems 'utf-8) +(set-terminal-coding-system 'utf-8) +(set-selection-coding-system 'utf-8) +(prefer-coding-system 'utf-8) diff --git a/.config/magit/init.el b/.config/magit/init.el new file mode 100644 index 0000000..98db545 --- /dev/null +++ b/.config/magit/init.el @@ -0,0 +1,147 @@ +;; -*- lexical-binding: t -*- + +(defvar bootstrap-version) +(let ((bootstrap-file + (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory)) + (bootstrap-version 6)) + (unless (file-exists-p bootstrap-file) + (with-current-buffer + (url-retrieve-synchronously + "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el" + 'silent 'inhibit-cookies) + (goto-char (point-max)) + (eval-print-last-sexp))) + (load bootstrap-file nil 'nomessage)) + +(straight-use-package 'doom-themes) +(setq custom-safe-themes t) + +(custom-set-variables + '(custom-enabled-themes '(doom-palenight))) +(custom-set-faces + '(dashboard-items-face ((t (:inherit widget-button :weight normal))))) + + +(set-face-attribute 'default nil :family "Fira Code Nerd Font Mono" :height 120) + +(setq-default c-basic-offset 4) ;; This is annoying +(setq-default indent-tabs-mode nil) +(setq-default tab-width 4) +(setq-default line-spacing 5) +(setq indent-line-function #'indent-relative) + +(set-default 'truncate-lines t) +(set-default 'truncate-partial-width-windows nil) + +(setq evil-want-keybinding nil) +(setq evil-want-C-u-scroll t) +(setq evil-want-Y-yank-to-eol t) +(setq evil-disable-insert-state-bindings t) +(setq evil-echo-state nil) +(straight-use-package 'evil) +(straight-use-package 'evil-collection) + +(evil-mode t) +(evil-collection-init) + +;; TODO: We need 3 bindings; 1.) close buffer 2.) close window 3.) close buffer and window +;; To disable a keybinding just bind it to nil +(evil-set-leader nil (kbd "C-SPC")) +(evil-set-leader 'normal (kbd "SPC")) + +(evil-global-set-key 'insert (kbd "C-w") #'evil-delete-backward-word) +(evil-global-set-key 'normal (kbd "C-s") #'save-buffer) + +(straight-use-package 'all-the-icons-completion) +(straight-use-package '(vertico :files (:defaults "extensions/*") + :includes (vertico-indexed + vertico-repeat + vertico-directory))) + +(vertico-mode) + +(define-key vertico-map (kbd "C-w") #'vertico-directory-delete-word) +(vertico-indexed-mode) + +(setq vertico-count 17 + vertico-resize nil + vertico-cycle t) + +(require 'savehist) +(savehist-mode) +(add-hook 'minibuffer-setup-hook #'vertico-repeat-save) +(add-to-list 'savehist-additional-variables 'vertico-repeat-history) + +(straight-use-package 'vertico-directory) + +(defun embark-which-key-indicator () + "An embark indicator that displays keymaps using which-key. +The which-key help message will show the type and value of the +current target followed by an ellipsis if there are further +targets." + (lambda (&optional keymap targets prefix) + (if (null keymap) + (which-key--hide-popup-ignore-command) + (which-key--show-keymap + (if (eq (plist-get (car targets) :type) 'embark-become) + "Become" + (format "Act on %s '%s'%s" + (plist-get (car targets) :type) + (embark--truncate-target (plist-get (car targets) :target)) + (if (cdr targets) "…" ""))) + (if prefix + (pcase (lookup-key keymap prefix 'accept-default) + ((and (pred keymapp) km) km) + (_ (key-binding prefix 'accept-default))) + keymap) + nil nil t (lambda (binding) + (not (string-suffix-p "-argument" (cdr binding)))))))) + +(setq embark-indicators + '(embark-which-key-indicator + embark-highlight-indicator + embark-isearch-highlight-indicator)) + +(defun embark-hide-which-key-indicator (fn &rest args) + "Hide the which-key indicator immediately when using the completing-read prompter." + (which-key--hide-popup-ignore-command) + (let ((embark-indicators + (remq #'embark-which-key-indicator embark-indicators))) + (apply fn args))) + +(advice-add #'embark-completing-read-prompter + :around #'embark-hide-which-key-indicator) + +(global-set-key (kbd "C-'") #'embark-act) + +(straight-use-package 'embark-consult) + +(straight-use-package 'marginalia) +(setq marginalia-annotators '(marginalia-annotators-heavy marginalia-annotators-light nil)) +(setq marginalia-align 'right) +(setq marginalia-max-relative-age most-positive-fixnum) +(marginalia-mode) +(define-key minibuffer-local-map (kbd "M-A") #'marginalia-cycle) +(require 'all-the-icons-completion) +(all-the-icons-completion-mode) +(all-the-icons-completion-marginalia-setup) + +(add-hook 'marginalia-mode-hook #'all-the-icons-completion-marginalia-setup) + +(straight-use-package 'orderless) +(setq completion-styles '(orderless basic) + completion-category-overrides '((file (styles basic partial-completion)))) + + +(straight-use-package 'magit) + +(defun joe/magit-kill-buffers (param) + "Restore window configuration and kill all Magit buffers." + (let ((buffers (magit-mode-get-buffers))) + (magit-restore-window-configuration) + (mapc #'kill-buffer buffers)) + (kill-emacs)) + +(setq magit-bury-buffer-function #'joe/magit-kill-buffers) +(setq magit-clone-set-remote.pushDefault t) +(setq magit-clone-default-directory "~/Development/") diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index e8b3bf5..9e34d54 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -1,30 +1,102 @@ --- This file can be loaded by calling `lua require('plugins')` from your init.vim - require('plugins') local map = vim.keymap.set +local set = vim.opt -vim.o.clipboard = 'unnamedplus' -vim.o.wrap = false -vim.o.hlsearch = false -vim.wo.number = true -vim.wo.relativenumber = true -vim.o.ignorecase = true -vim.o.smartcase = true -vim.o.termguicolors = true - +set.clipboard = 'unnamedplus' +set.wrap = false +set.number = true +set.relativenumber = true +set.ignorecase = true +set.smartcase = true +set.termguicolors = true +set.swapfile = false +set.backup = false +set.undodir = os.getenv("XDG_CACHE_HOME") .. "/nvim/undo" +set.undofile = true +set.hlsearch = false +set.incsearch = true +set.cursorline = true +set.cmdheight = 0 +set.mouse = 'a' +set.splitright = true +set.splitbelow = true +set.updatetime = 600 +set.signcolumn = "yes" +set.tabstop = 4 +set.softtabstop = 4 +set.shiftwidth = 4 +set.expandtab = true vim.g.mapleader = " " +map("v", "J", ":m '>+1gv=gv") +map("v", "K", ":m '<-2gv=gv") +map("x", "J", ":m '>+1gv-gv", opts) +map("x", "K", ":m '<-2gv-gv", opts) + +map("v", "<", "", ">gv", opts) + +map("n", "J", "mzJ`z") + map("n", "", vim.cmd.w) map("n", "", vim.cmd.wq) +map("n", "", vim.cmd.source) + map("n", "vv", "^vg_", { noremap = true }) -local telescope = require('telescope.builtin') -map('n', 'f', telescope.find_files, {}) -map('n', 'g', telescope.live_grep, {}) -map('n', 'b', telescope.buffers, {}) -map('n', 't', telescope.help_tags, {}) +map("n", "-", vim.cmd.Ex, {}) +map('n', 'U', vim.cmd.redo) + +local ts = require('telescope.builtin') + +map('n', 'f', ts.find_files, {}) +map('n', 'g', ts.live_grep, {}) +map('n', 'b', ts.buffers, {}) +map('n', 't', ts.help_tags, {}) +map('n', 'c', ts.commands, {}) + +-- TODO If we use this one a lot, might be better to bind it to something easier +map('n', 'bb', ':b#') +map('n', 'bn', vim.cmd.bnext) +map('n', 'bk', vim.cmd.bdelete) + +-- Window management + +map('n', 'wo', 'o') +map('n', 'wc', 'c') +map('n', 'wv', 'v') +map('n', 'ws', 's') +map('n', 'ww', 'p') +map('n', 'wr', 'r') +map('n', 'wx', 'x') +map('n', 'wt', 'T') +map('n', 'wh', 'H') +map('n', 'wj', 'J') +map('n', 'wk', 'K') +map('n', 'wl', 'L') + +map("n", "", ":resize -2", opts) +map("n", "", ":resize +2", opts) +map("n", "", ":vertical resize -2", opts) +map("n", "", ":vertical resize +2", opts) + +map('n', '', 'h', {}) +map('n', '', 'j', {}) +map('n', '', 'k', {}) +map('n', '', 'l', {}) -- local neogit = require('neogit') -- -- neogit.setup {} +function ToggleInlayHints() + local rt = require("rust-tools") + if _G.inlay_hints_toggle == true then + rt.inlay_hints.enable() + else + rt.inlay_hints.disable() + end + _G.inlay_hints_toggle = not _G.inlay_hints_toggle +end +vim.keymap.set('n', 'li', ':lua ToggleInlayHints()') + diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua index 6d31450..bce1062 100644 --- a/.config/nvim/lua/plugins.lua +++ b/.config/nvim/lua/plugins.lua @@ -10,53 +10,107 @@ local ensure_packer = function() end local packer_bootstrap = ensure_packer() -local packer = require('packer') + +-- Use a protected call so we don't error out on first use +local status_ok, packer = pcall(require, "packer") +if not status_ok then + return +end + +-- Have packer use a popup window +packer.init({ + display = { + open_fn = function() + return require("packer.util").float({ border = "rounded" }) + end, + }, +}) + packer.startup(function(use) - -- Packer can manage itself - use 'wbthomason/packer.nvim' - use 'nvim-lua/plenary.nvim' - use { - 'nvim-telescope/telescope-fzf-native.nvim', - run = 'make', - cond = vim.fn.executable 'make' == 1 -} - use { - 'marko-cerovac/material.nvim', - config = function() - vim.g.material_style = "palenight" - vim.cmd [[colorscheme material]] - end - } - use { - 'nvim-treesitter/nvim-treesitter', - run = function() - local ts_update = require('nvim-treesitter.install').update({ with_sync = true }) - ts_update() - end - } - use { -- Additional text objects via treesitter - 'nvim-treesitter/nvim-treesitter-textobjects', - after = 'nvim-treesitter', - } - use { - 'nvim-telescope/telescope.nvim', tag = '0.1.0', - requires = { {'nvim-lua/plenary.nvim'} } - } - use { - 'numToStr/Comment.nvim', - config = function() - require('Comment').setup() - end - } - use { - "kylechui/nvim-surround", - tag = "*", -- Use for stability; omit to use `main` branch for the latest features - config = function() - require("nvim-surround").setup({}) + -- Packer can manage itself + use 'wbthomason/packer.nvim' + use 'nvim-lua/plenary.nvim' + use { + 'nvim-telescope/telescope-fzf-native.nvim', + run = 'make', + cond = vim.fn.executable 'make' == 1 + } + use { + 'marko-cerovac/material.nvim', + config = function() + vim.g.material_style = "palenight" + vim.cmd [[colorscheme material]] end - } --- use { 'TimUntersberger/neogit', requires = 'nvim-lua/plenary.nvim' } + } + use { + 'nvim-treesitter/nvim-treesitter', + run = function() + local ts_update = require('nvim-treesitter.install').update({ with_sync = true }) + ts_update() + end + } + use { -- Additional text objects via treesitter + 'nvim-treesitter/nvim-treesitter-textobjects', + after = 'nvim-treesitter', + } + use 'neovim/nvim-lspconfig' + use { + 'simrat39/rust-tools.nvim', + config = function() + local rt = require("rust-tools") + rt.setup({ + server = { + on_attach = function(_, bufnr) + -- Hover actions + vim.keymap.set("n", "", rt.hover_actions.hover_actions, { buffer = bufnr }) + -- Code action groups + vim.keymap.set("n", "a", rt.code_action_group.code_action_group, { buffer = bufnr }) + end, + }, + }) + end + } + use { + 'WhoIsSethDaniel/toggle-lsp-diagnostics.nvim', + config = function() + require'toggle_lsp_diagnostics'.init() + vim.keymap.set('n', 'e', vim.cmd.ToggleDiag) + end + } + use { + 'nvim-telescope/telescope.nvim', tag = '0.1.0', + requires = { {'nvim-lua/plenary.nvim'} } + } + use 'mfussenegger/nvim-dap' + use { + "rcarriga/nvim-dap-ui", + requires = {"mfussenegger/nvim-dap"}, + config = function() + require("dapui").setup() + end, + } + use 'mbbill/undotree' + use { + 'numToStr/Comment.nvim', + config = function() + require('Comment').setup() + end + } + use { + "kylechui/nvim-surround", + tag = "*", -- Use for stability; omit to use `main` branch for the latest features + config = function() + require("nvim-surround").setup({}) + end + } + use { + 'm4xshen/autoclose.nvim', + config = function() + require("autoclose").setup({}) + end + } + -- use { 'TimUntersberger/neogit', requires = 'nvim-lua/plenary.nvim' } end) if packer_bootstrap then @@ -68,75 +122,154 @@ local augroup = vim.api.nvim_create_augroup autocmd(('BufWritePost'), { - group = augroup('packer_user_config', { clear = true }), - pattern = "plugins.lua", - once = true, - callback = function() - vim.cmd('source ~/.config/nvim/lua/plugins.lua') - packer.compile() - end + group = augroup('packer_user_config', { clear = true }), + pattern = "plugins.lua", + once = true, + callback = function() + vim.cmd('source ~/.config/nvim/lua/plugins.lua') + packer.compile() + end }) require('nvim-treesitter.configs').setup { - -- Add languages to be installed here that you want installed for treesitter - ensure_installed = { 'c', 'cpp', 'go', 'lua', 'bash', 'rust', 'go', 'help', 'haskell', 'ocaml' }, - highlight = { - enable = true, - additional_vim_regex_highlighting = false - }, - indent = { enable = true }, - incremental_selection = { - enable = true, - keymaps = { - init_selection = '', - node_incremental = '', - scope_incremental = '', - node_decremental = '', + -- Add languages to be installed here that you want installed for treesitter + ensure_installed = { 'c', 'cpp', 'go', 'lua', 'bash', 'rust', 'go', 'help', 'haskell', 'ocaml' }, + highlight = { + enable = true, + additional_vim_regex_highlighting = false }, - }, - textobjects = { - select = { - enable = true, - lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim - keymaps = { - -- You can use the capture groups defined in textobjects.scm - ['aa'] = '@parameter.outer', - ['ia'] = '@parameter.inner', - ['af'] = '@function.outer', - ['if'] = '@function.inner', - ['ac'] = '@class.outer', - ['ic'] = '@class.inner', - }, + indent = { enable = true }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = '', + node_incremental = '', + scope_incremental = '', + node_decremental = '', + }, }, - move = { - enable = true, - set_jumps = true, -- whether to set jumps in the jumplist - goto_next_start = { - [')'] = '@function.outer', - [']]'] = '@class.outer', - }, - goto_next_end = { - [']M'] = '@function.outer', - [']['] = '@class.outer', - }, - goto_previous_start = { - ['('] = '@function.outer', - ['[['] = '@class.outer', - }, - goto_previous_end = { - ['[M'] = '@function.outer', - ['[]'] = '@class.outer', - }, + textobjects = { + select = { + enable = true, + lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim + keymaps = { + -- You can use the capture groups defined in textobjects.scm + ['aa'] = '@parameter.outer', + ['ia'] = '@parameter.inner', + ['af'] = '@function.outer', + ['if'] = '@function.inner', + ['ac'] = '@class.outer', + ['ic'] = '@class.inner', + }, + }, + move = { + enable = true, + set_jumps = true, -- whether to set jumps in the jumplist + goto_next_start = { + [')'] = '@function.outer', + [']]'] = '@class.outer', + }, + goto_next_end = { + [']M'] = '@function.outer', + [']['] = '@class.outer', + }, + goto_previous_start = { + ['('] = '@function.outer', + ['[['] = '@class.outer', + }, + goto_previous_end = { + ['[M'] = '@function.outer', + ['[]'] = '@class.outer', + }, + }, + -- TODO: Fix this + swap = { + enable = true, + swap_next = { + ['a'] = '@parameter.inner', + }, + swap_previous = { + ['A'] = '@parameter.inner', + }, + }, }, --- TODO: Fix this - swap = { - enable = true, - swap_next = { - ['a'] = '@parameter.inner', - }, - swap_previous = { - ['A'] = '@parameter.inner', - }, - }, - }, } + +local dap = require('dap') +dap.adapters.lldb = { + type = 'executable', + command = '/usr/bin/lldb-vscode', -- adjust as needed, must be absolute path + name = 'lldb' +} + +dap.configurations.rust = { + { + name = 'Launch', + type = 'lldb', + request = 'launch', + program = function() + return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') + end, + cwd = '${workspaceFolder}', + stopOnEntry = false, + args = {}, + }, +} + +-- If you want to use this for Rust and C, add something like this: + +dap.configurations.c = dap.configurations.rust +dap.configurations.cpp = dap.configurations.rust + +local on_attach = function(client, bufnr) + -- Enable completion triggered by + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + vim.diagnostic.config({ + virtual_text = true, + signs = true, + underline = true, + update_in_insert = false, + severity_sort = false, + }) + -- Mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local bufopts = { noremap=true, silent=true, buffer=bufnr } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, bufopts) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, bufopts) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, bufopts) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, bufopts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufopts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) + vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) + vim.keymap.set('n', 'f', function() vim.lsp.buf.format { async = true } end, bufopts) +end + +require('lspconfig')['rust_analyzer'].setup{ + on_attach = on_attach, + flags = lsp_flags, + settings = { + ["rust-analyzer"] = {} + } +} +local hints = false + +show_hints = false + +toggle_hints = function() + local hints = require("rust-tools").inlay_hints + if show_hints then + hints.enable() + else + hints.disable() + end + show_hints = not show_hints +end + +vim.keymap.set("n", "li", toggle_hints) diff --git a/.gitignore b/.gitignore index af774ae..837b3f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ .config/emacs/* !.config/emacs/init.org /.config/nvim/plugin/ +.config/magit/* +!.config/magit/init.el +!.config/magit/early-init.el