From 50d6df2de7940209f515e6289cdc7949ec62d670 Mon Sep 17 00:00:00 2001 From: Dane Sabo Date: Sun, 23 Mar 2025 13:39:59 -0400 Subject: [PATCH] made rust keybinds for cargo. leader c {(b)uild (r)un (n)ew} --- lua/custom/chadrc.lua | 2 +- lua/custom/configs/lspconfig.lua | 11 ++++- .../language_specific_commands/rust.lua | 45 +++++++++++++++++++ lua/custom/mappings.lua | 1 + lua/custom/plugins.lua | 35 ++++++++------- 5 files changed, 75 insertions(+), 19 deletions(-) create mode 100644 lua/custom/language_specific_commands/rust.lua diff --git a/lua/custom/chadrc.lua b/lua/custom/chadrc.lua index 7031f55..8903a5f 100644 --- a/lua/custom/chadrc.lua +++ b/lua/custom/chadrc.lua @@ -1,7 +1,7 @@ ---@type ChadrcConfig local M = {} -M.ui = { theme = 'melange' } +M.ui = { theme = 'oceanic-light' } M.plugins = 'custom.plugins' M.mappings = require "custom.mappings" return M diff --git a/lua/custom/configs/lspconfig.lua b/lua/custom/configs/lspconfig.lua index 2c97b7a..589a4f7 100644 --- a/lua/custom/configs/lspconfig.lua +++ b/lua/custom/configs/lspconfig.lua @@ -73,8 +73,17 @@ lspconfig.clangd.setup { filetypes = { "c", "cpp" }, } +local function marksman_on_attach(client, bufnr) + -- Call the global version first + on_attach(client, bufnr) + + -- Then do the Markdown-specific logic + -- vim.api.nvim_set_option_value("spell", true, { buf = bufnr }) + -- vim.api.nvim_set_option_value("spelllang", "en_us", { buf = bufnr }) +end + lspconfig.marksman.setup { - on_attach = on_attach, + on_attach = marksman_on_attach, capabilities = capabilities, filetypes = { "markdown" }, } diff --git a/lua/custom/language_specific_commands/rust.lua b/lua/custom/language_specific_commands/rust.lua new file mode 100644 index 0000000..252b29a --- /dev/null +++ b/lua/custom/language_specific_commands/rust.lua @@ -0,0 +1,45 @@ +-- We modify our previously defined Cargo user command: +vim.api.nvim_create_user_command("Cargo", function(opts) + -- Split the entire command-line input (opts.args) by spaces. + -- For example, if someone types :Cargo new test_project --bin + -- the split might be {"new", "test_project", "--bin"}. + local args = vim.split(opts.args, "%s+") + + -- The first item is the subcommand: "run", "build", or "new". + local subcommand = args[1] + + if subcommand == "run" then + vim.cmd "!cargo run" + elseif subcommand == "build" then + vim.cmd "!cargo build" + elseif subcommand == "new" then + -- Everything after 'new' is the project name plus optional flags. + -- Let's remove 'new' from the table, then join the rest with spaces. + table.remove(args, 1) -- remove 'new' + local new_args = table.concat(args, " ") + if #new_args == 0 then + print "Usage: :Cargo new [options]" + return + end + + -- Run "cargo new whatever-is-left" + vim.cmd("!cargo new " .. new_args) + else + print( + "Please provide 'run', 'build', or 'new' as an argument to :Cargo. " + .. "For 'new', also specify [options]." + ) + end +end, { + -- We make nargs = '*' so you can type multiple arguments + -- e.g. ':Cargo new test_project --bin' + nargs = "*", +}) + +-- Keymaps remain the same, or you could add more if you want: +vim.keymap.set("n", "cr", ":Cargo run", { desc = "Cargo: run" }) +vim.keymap.set("n", "cb", ":Cargo build", { desc = "Cargo: build" }) +-- Optionally, bind something for "new": +vim.keymap.set("n", "cn", ":Cargo new ", { desc = "Cargo: new" }) +-- Notice we didn't put at the end of ':Cargo new ' because you typically +-- want to type your project name before pressing Enter. diff --git a/lua/custom/mappings.lua b/lua/custom/mappings.lua index 5096990..e799c04 100644 --- a/lua/custom/mappings.lua +++ b/lua/custom/mappings.lua @@ -46,5 +46,6 @@ vim.api.nvim_create_autocmd("CursorHold", { vim.api.nvim_set_keymap("n", "e", "lua vim.diagnostic.open_float()", { noremap = true, silent = true }) require "custom.language_specific_commands.matlab" +require "custom.language_specific_commands.rust" return M diff --git a/lua/custom/plugins.lua b/lua/custom/plugins.lua index df20e8d..38a834a 100644 --- a/lua/custom/plugins.lua +++ b/lua/custom/plugins.lua @@ -11,6 +11,7 @@ local plugins = { "matlab-language-server", "clangd", "marksman", + "pyright", --- formatters "stylua", @@ -101,7 +102,22 @@ local plugins = { keys = { -- Will use Telescope if installed or a vim.ui.select picker otherwise { "fs", "SessionSearch", desc = "Session search" }, - { "ws", "SessionSave", desc = "Save session" }, + { + "ws", + function() + -- prompt for a session name using the built-in input function: + local session_name = vim.fn.input "Enter session name: " + + -- optionally check if the user provided something + if session_name ~= nil and session_name ~= "" then + -- construct the command with the chosen name + vim.cmd("SessionSave " .. session_name) + else + print "No session name given. Session not saved." + end + end, + desc = "Save session (prompts for name)", + }, { "wa", "SessionToggleAutoSave", desc = "Toggle autosave" }, }, ---enables autocomplete for opts @@ -109,6 +125,7 @@ local plugins = { ---@type AutoSession.Config opts = { suppressed_dirs = { "~/", "~/Projects", "~/Downloads", "/" }, + root_dir = os.getenv "HOME" .. "/Documents/Dane's Vault/.sessions/", }, }, { @@ -181,44 +198,28 @@ local plugins = { local logo = { [[ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ]], - [[ %%%%===========================================%%%% ]], [[ %%%%%=-------------------------------------------=#%%% ]], - [[ %%%%%=---------------------------------------------=#%%% ]], [[ %%%%%=-----------------------------------------------=#%% ]], - [[ %%%%%====----------==========================---------+%% ]], - [[ %%%%%%%%#----------*%%%%%%%%%%%%%%%%%%%%%%%%%---------+%% ]], [[ %%%%%%%%#----------*%%%%%%%%%%%%%%%%%%%%%%%%%---------+%% ]], [[ %%%%#----------*%%%%%%%%%%%%%%%%%%%%%%%%%---------+%% ]], [[ %%%%#----------*%% %%%%%---------+%% ]], - [[ %%%%#----------*%% %%%%%---------+%% ]], - [[ %%%%#----------*%####################%%%%---------+%% ]], [[ %%%%#----------+*************************---------+%% ]], - [[ %%%%#---------------------------------------------+%% ]], [[ %%%%#--------------------------------------------+%%% ]], - [[ %%%%#------------------------------------------=#%%%% ]], [[ %%%%#-----------------------------------------#%%%% ]], - [[ %%%%#----------=============================+%%%% ]], [[ %%%%#----------*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ]], - [[ %%%%#----------*%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ]], [[ %%%%#----------*%%%%%%%%%%%%%%%%%%%%%%%%%%% ]], [[ %%%%#----------*%% ]], [[ %%%%#----------*%% %%%##**++++++*#%%%%%%% %%#***#%% ]], - [[%#+=% %%%%#----------*%% %%%#=--------==---------------------=%===+#%%##% ]], [[%==% %%%%#----------*%%%%=+#=-----------+------------=+-------+==--=*=#=-==%% ]], [[#-=% %%%%#---------=#*===**------------*=-----------++-------=%=----*=--=+=*%*# ]], - [[%*-#% %%%%#----==*#+--=+#%#----------=*+------------*=-------=+=----+#------+%=# ]], [[ %*==#%%%%#*##*==-=**#%%%+=--------+*=+**----------*++=----+*#=---=*#%*+==-* % ]], [[ %#+==--==+*#*+===*#*=--------=*+*%%%%%#+=-==----%#=---+#=---=#%%%%%% %*+% ]], - [[ %%%%#=-----**=----=+*#####% %%%%%%% %#*+=#=#==--++-=+#%%%%%%%*==%% ]], [[ %%%%#-----+*==*#%% %#++==#% %%%%%%#=--=% %%#*=+#=-=+%% ]], [[ %%%%#----+*-=%#%%% %+=-*% %% %#=-=# %%#==--=*#%%%% ]], - [[ %%%%%%%#----*=---=*#%%%% %+-===%#% %*=-==*#% %####==-+** ]], [[ %%%%%=----------------#%% %%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%]], [[ %%%%%=----------------#%% %%-----------+%% %%=-------------------=%% %%--------------------=%%]], - [[ %%%%%=----------------#%% %%%%%%=---*%%%%% %%=----#%%*----%%%%=--=%% %%-----#%%+---=%%%%=--=%%]], [[ %%%%%=----------------#%% %%=---*% %%%%%%%%%%*----%%%%%%%%%% %%%%%%%%%%+---=%%%%%%%%%%]], [[ %%%%%=----------------#%% %%=---*% %*----%% %+---=%% ]], - [[ %%%%%##################%% %%%%%%=---*%%%%% %%%%%*----%%%%% %%%%%+---=%%%%%% ]], [[ %%%%%%%%%%%%%%%%%%%%%%%%% %%-----------+%% %%=----------*%% %%=----------*%% ]], [[ %%%%%%%%%%%%%%%%%%%%%%%%% %%############%% %%###########%%% %%############%% ]], }