More configuration for nvim and small tweaks/optimizations for magit
This commit is contained in:
		
							parent
							
								
									8c5caf3c05
								
							
						
					
					
						commit
						064e282804
					
				| @ -1108,7 +1108,6 @@ startup. Reason we have to call this is so the vterm fucntion can call `vterm--i | |||||||
| #+begin_src emacs-lisp | #+begin_src emacs-lisp | ||||||
| (straight-use-package 'dap-mode) | (straight-use-package 'dap-mode) | ||||||
| #+end_src | #+end_src | ||||||
| 
 |  | ||||||
| ** Languages | ** Languages | ||||||
| *** Rust | *** Rust | ||||||
| #+begin_src emacs-lisp | #+begin_src emacs-lisp | ||||||
|  | |||||||
| @ -5,7 +5,7 @@ | |||||||
| 
 | 
 | ||||||
| (add-hook 'emacs-startup-hook | (add-hook 'emacs-startup-hook | ||||||
|           (lambda () |           (lambda () | ||||||
|             "Restore defalut values after init." |             "Restore defaults values after init." | ||||||
|             (setq file-name-handler-alist default-file-name-handler-alist) |             (setq file-name-handler-alist default-file-name-handler-alist) | ||||||
|             (if (boundp 'after-focus-change-function) |             (if (boundp 'after-focus-change-function) | ||||||
|                 (add-function :after after-focus-change-function |                 (add-function :after after-focus-change-function | ||||||
| @ -27,13 +27,6 @@ | |||||||
| 
 | 
 | ||||||
| (setq load-prefer-newer 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 default-input-method nil) | ||||||
| (setq utf-translate-cjk-mode nil) ; disable CJK coding/encoding (Chinese/Japanese/Korean characters) | (setq utf-translate-cjk-mode nil) ; disable CJK coding/encoding (Chinese/Japanese/Korean characters) | ||||||
| (set-language-environment 'utf-8) | (set-language-environment 'utf-8) | ||||||
|  | |||||||
| @ -53,15 +53,11 @@ | |||||||
| (evil-global-set-key 'normal (kbd "C-s") #'save-buffer) | (evil-global-set-key 'normal (kbd "C-s") #'save-buffer) | ||||||
| 
 | 
 | ||||||
| (straight-use-package 'all-the-icons-completion) | (straight-use-package 'all-the-icons-completion) | ||||||
| (straight-use-package '(vertico :files (:defaults "extensions/*") | (straight-use-package '(vertico :files (:defaults "extensions/*"))) | ||||||
|                                 :includes (vertico-indexed |  | ||||||
|                                            vertico-repeat |  | ||||||
|                                            vertico-directory))) |  | ||||||
| 
 | 
 | ||||||
| (vertico-mode) | (vertico-mode) | ||||||
| 
 | 
 | ||||||
| (define-key vertico-map (kbd "C-w") #'vertico-directory-delete-word) | (define-key vertico-map (kbd "C-w") #'vertico-directory-delete-word) | ||||||
| (vertico-indexed-mode) |  | ||||||
| 
 | 
 | ||||||
| (setq vertico-count 17 | (setq vertico-count 17 | ||||||
|       vertico-resize nil |       vertico-resize nil | ||||||
| @ -72,62 +68,6 @@ | |||||||
| (add-hook 'minibuffer-setup-hook #'vertico-repeat-save) | (add-hook 'minibuffer-setup-hook #'vertico-repeat-save) | ||||||
| (add-to-list 'savehist-additional-variables 'vertico-repeat-history) | (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) | (straight-use-package 'orderless) | ||||||
| (setq completion-styles '(orderless basic) | (setq completion-styles '(orderless basic) | ||||||
|       completion-category-overrides '((file (styles basic partial-completion)))) |       completion-category-overrides '((file (styles basic partial-completion)))) | ||||||
|  | |||||||
| @ -4,16 +4,7 @@ local set = vim.opt | |||||||
| 
 | 
 | ||||||
| set.clipboard = 'unnamedplus' | set.clipboard = 'unnamedplus' | ||||||
| set.wrap = false | set.wrap = false | ||||||
| set.number = true | 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.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.incsearch = true | ||||||
| set.cursorline = true | set.cursorline = true | ||||||
| set.cmdheight = 0 | set.cmdheight = 0 | ||||||
| @ -40,7 +31,8 @@ map("n", "J", "mzJ`z") | |||||||
| 
 | 
 | ||||||
| map("n", "<C-s>", vim.cmd.w) | map("n", "<C-s>", vim.cmd.w) | ||||||
| map("n", "<C-q>", vim.cmd.wq) | map("n", "<C-q>", vim.cmd.wq) | ||||||
| map("n", "<C-r>", vim.cmd.source) | map("n", "<C-S-r>", vim.cmd.source) | ||||||
|  | map("n", "<C-r>", "<nop>") | ||||||
| 
 | 
 | ||||||
| map("n", "vv", "^vg_", { noremap = true }) | map("n", "vv", "^vg_", { noremap = true }) | ||||||
| 
 | 
 | ||||||
| @ -89,14 +81,4 @@ map('n', '<C-l>', '<C-w>l', {}) | |||||||
| --  | --  | ||||||
| -- neogit.setup {} | -- neogit.setup {} | ||||||
| 
 | 
 | ||||||
| function ToggleInlayHints() | vim.keymap.set("n", "<leader>tw", ":set wrap!<CR>") | ||||||
|     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', '<leader>li', ':lua ToggleInlayHints()<CR>') |  | ||||||
| 
 |  | ||||||
|  | |||||||
| @ -50,37 +50,122 @@ packer.startup(function(use) | |||||||
|             ts_update() |             ts_update() | ||||||
|         end |         end | ||||||
|     } |     } | ||||||
|     use { -- Additional text objects via treesitter |     use { | ||||||
|         'nvim-treesitter/nvim-treesitter-textobjects', |         'nvim-treesitter/nvim-treesitter-textobjects', | ||||||
|         after = 'nvim-treesitter', |         after = 'nvim-treesitter', | ||||||
|     } |     } | ||||||
|     use 'neovim/nvim-lspconfig' |  | ||||||
|     use { |     use { | ||||||
|         'simrat39/rust-tools.nvim', |         'neovim/nvim-lspconfig', | ||||||
|         config = function() |         config = function() | ||||||
|             local rt = require("rust-tools") |             local rt = require("rust-tools") | ||||||
|  |             local capabilities = require("cmp_nvim_lsp").default_capabilities() | ||||||
|  |             local on_attach = function(_, bufnr) | ||||||
|  |                 show_hints = false | ||||||
|  | 
 | ||||||
|  |                 toggle_hints = function() | ||||||
|  |                     if show_hints then | ||||||
|  |                         rt.inlay_hints.enable() | ||||||
|  |                     else | ||||||
|  |                         rt.inlay_hints.disable() | ||||||
|  |                     end | ||||||
|  |                     show_hints = not show_hints | ||||||
|  |                 end | ||||||
|  |                 vim.diagnostic.config { | ||||||
|  |                     float = { border = "rounded" }, | ||||||
|  |                 } | ||||||
|  |                 vim.keymap.set("n", "<leader>ti", toggle_hints) | ||||||
|  |                 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", "<C-space>", rt.hover_actions.hover_actions, { buffer = bufnr }) | ||||||
|  |                 vim.keymap.set("n", "<Leader>a", rt.code_action_group.code_action_group, { buffer = bufnr }) | ||||||
|  |                 vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) | ||||||
|  |                 vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, 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', '<C-k>', vim.lsp.buf.signature_help, bufopts) | ||||||
|  |                 vim.keymap.set('n', '<space>lwa', vim.lsp.buf.add_workspace_folder, bufopts) | ||||||
|  |                 vim.keymap.set('n', '<space>lwr', vim.lsp.buf.remove_workspace_folder, bufopts) | ||||||
|  |                 local ws_folders = function() | ||||||
|  |                     print(vim.inspect(vim.lsp.buf.list_workspace_folders())) | ||||||
|  |                 end | ||||||
|  |                 vim.keymap.set('n', '<space>lwl', ws_folders, bufopts) | ||||||
|  |                 vim.keymap.set('n', 'gt', vim.lsp.buf.type_definition, bufopts) | ||||||
|  |                 vim.keymap.set('n', '<space>lr', vim.lsp.buf.rename, bufopts) | ||||||
|  |                 vim.keymap.set('n', '<space>la', vim.lsp.buf.code_action, bufopts) | ||||||
|  |                 vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) | ||||||
|  |                 vim.keymap.set('n', '<space>lf', function() vim.lsp.buf.format { async = true } end, bufopts) | ||||||
|  | 
 | ||||||
|  |                 vim.keymap.set('n', '<space>ee', vim.diagnostic.open_float, opts) | ||||||
|  |                 vim.keymap.set('n', '<M-S-e>', vim.diagnostic.goto_prev, opts) | ||||||
|  |                 vim.keymap.set('n', '<M-e>', vim.diagnostic.goto_next, opts) | ||||||
|  |             end | ||||||
|             rt.setup({ |             rt.setup({ | ||||||
|                 server = { |                 server = { | ||||||
|                     on_attach = function(_, bufnr) |                     on_attach = on_attach, | ||||||
|                         -- Hover actions |                     capabilities = capabilities | ||||||
|                         vim.keymap.set("n", "<C-space>", rt.hover_actions.hover_actions, { buffer = bufnr }) |  | ||||||
|                         -- Code action groups |  | ||||||
|                         vim.keymap.set("n", "<Leader>a", rt.code_action_group.code_action_group, { buffer = bufnr }) |  | ||||||
|                     end, |  | ||||||
|                 }, |                 }, | ||||||
|             }) |             }) | ||||||
|         end |         end | ||||||
|     } |     } | ||||||
|  |     use 'hrsh7th/cmp-nvim-lsp' | ||||||
|  |     use 'hrsh7th/cmp-buffer' | ||||||
|  |     use 'hrsh7th/cmp-path' | ||||||
|  |     use 'hrsh7th/cmp-cmdline' | ||||||
|  |     use { | ||||||
|  |         'hrsh7th/nvim-cmp', | ||||||
|  |         config = function() | ||||||
|  |             local cmp = require('cmp') | ||||||
|  |             cmp.setup({ | ||||||
|  |                 window = { | ||||||
|  |                     completion = cmp.config.window.bordered(), | ||||||
|  |                     documentation = cmp.config.window.bordered(), | ||||||
|  |                 }, | ||||||
|  |                 completion = { | ||||||
|  |                     autocomplete = false | ||||||
|  |                 }, | ||||||
|  |                 mapping = cmp.mapping.preset.insert({ | ||||||
|  |                     ['<C-u>'] = cmp.mapping.scroll_docs(-4), | ||||||
|  |                     ['<C-d>'] = cmp.mapping.scroll_docs(4), | ||||||
|  |                     ['<C-Space>'] = cmp.mapping.complete(), | ||||||
|  |                     ['<C-e>'] = cmp.mapping.abort(), | ||||||
|  |                     ['<C-f>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. | ||||||
|  |                 }), | ||||||
|  |                 sources = cmp.config.sources({ | ||||||
|  |                     { name = 'nvim_lsp' }, | ||||||
|  |                     { name = 'buffer' }, | ||||||
|  |                     { name = 'path' }, | ||||||
|  |                 }), | ||||||
|  |                 experimental = { | ||||||
|  |                     ghost_text = true, | ||||||
|  |                 }, | ||||||
|  |             }) | ||||||
|  |             vim.keymap.set('i', '<C-Space>', cmp.complete) | ||||||
|  |         end | ||||||
|  |     } | ||||||
|  |     use { | ||||||
|  |         'simrat39/rust-tools.nvim' | ||||||
|  |     } | ||||||
|     use { |     use { | ||||||
|         'WhoIsSethDaniel/toggle-lsp-diagnostics.nvim', |         'WhoIsSethDaniel/toggle-lsp-diagnostics.nvim', | ||||||
|         config = function() |         config = function() | ||||||
|             require'toggle_lsp_diagnostics'.init() |             require'toggle_lsp_diagnostics'.init() | ||||||
|             vim.keymap.set('n', '<Leader>e', vim.cmd.ToggleDiag) |             vim.keymap.set('n', '<Leader>te', vim.cmd.ToggleDiag) | ||||||
|         end |         end | ||||||
|     } |     } | ||||||
|     use { |     use { | ||||||
|         'nvim-telescope/telescope.nvim', tag = '0.1.0', |         'j-hui/fidget.nvim', | ||||||
|         requires = { {'nvim-lua/plenary.nvim'} } |         after = 'rust-tools.nvim', | ||||||
|  |         config = function() | ||||||
|  |             require("fidget").setup({}) | ||||||
|  |         end | ||||||
|     } |     } | ||||||
|     use 'mfussenegger/nvim-dap' |     use 'mfussenegger/nvim-dap' | ||||||
|     use { |     use { | ||||||
| @ -91,6 +176,10 @@ packer.startup(function(use) | |||||||
|         end, |         end, | ||||||
|     } |     } | ||||||
|     use 'mbbill/undotree' |     use 'mbbill/undotree' | ||||||
|  |     use { | ||||||
|  |         'nvim-telescope/telescope.nvim', tag = '0.1.0', | ||||||
|  |         requires = { {'nvim-lua/plenary.nvim'} } | ||||||
|  |     } | ||||||
|     use { |     use { | ||||||
|         'numToStr/Comment.nvim', |         'numToStr/Comment.nvim', | ||||||
|         config = function() |         config = function() | ||||||
| @ -220,56 +309,3 @@ dap.configurations.rust = { | |||||||
| 
 | 
 | ||||||
| dap.configurations.c = dap.configurations.rust | dap.configurations.c = dap.configurations.rust | ||||||
| dap.configurations.cpp = dap.configurations.rust | dap.configurations.cpp = dap.configurations.rust | ||||||
| 
 |  | ||||||
| local on_attach = function(client, bufnr) |  | ||||||
|     -- Enable completion triggered by <c-x><c-o> |  | ||||||
|     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', '<C-k>', vim.lsp.buf.signature_help, bufopts) |  | ||||||
|     vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts) |  | ||||||
|     vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts) |  | ||||||
|     vim.keymap.set('n', '<space>wl', function() |  | ||||||
|         print(vim.inspect(vim.lsp.buf.list_workspace_folders())) |  | ||||||
|     end, bufopts) |  | ||||||
|     vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts) |  | ||||||
|     vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts) |  | ||||||
|     vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts) |  | ||||||
|     vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) |  | ||||||
|     vim.keymap.set('n', '<space>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", "<leader>li", toggle_hints) |  | ||||||
|  | |||||||
							
								
								
									
										4
									
								
								.config/nvim/lua/rust.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								.config/nvim/lua/rust.lua
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,4 @@ | |||||||
|  | 
 | ||||||
|  | return function rust() | ||||||
|  |      | ||||||
|  | end | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user