From ba4e1700e9cd0878b171eab65537e914acc6c79e Mon Sep 17 00:00:00 2001 From: Nate Anderson Date: Thu, 15 Feb 2024 11:22:47 -0700 Subject: [PATCH] Attempting to fix firefox video meetings, further busted kakoune --- nate/dotfiles/kak-lsp/kak-lsp.toml | 2 +- nate/dotfiles/kak/autoload/auto-pairs.kak | 185 ++++++++++++++++++ .../kak/autoload/phantom-selection.kak | 84 ++++++++ nate/dotfiles/kak/kakrc | 130 +++++------- nate/modules/apps/firefox/firefox.nix | 19 +- nate/modules/home-manager/home.nix | 7 +- nate/modules/sway/sway_conf.nix | 1 + 7 files changed, 341 insertions(+), 87 deletions(-) create mode 100644 nate/dotfiles/kak/autoload/auto-pairs.kak create mode 100644 nate/dotfiles/kak/autoload/phantom-selection.kak diff --git a/nate/dotfiles/kak-lsp/kak-lsp.toml b/nate/dotfiles/kak-lsp/kak-lsp.toml index 286505e..d6a78c1 100644 --- a/nate/dotfiles/kak-lsp/kak-lsp.toml +++ b/nate/dotfiles/kak-lsp/kak-lsp.toml @@ -259,7 +259,7 @@ command = "lua-language-server" # diagnostics.enable = true [language.markdown] -filetype = ["md", "markdown"] +filetypes = ["md", "markdown"] roots = [".git", ".hg"] command = "vscode-markdown-language-server" args = ["--stdio"] diff --git a/nate/dotfiles/kak/autoload/auto-pairs.kak b/nate/dotfiles/kak/autoload/auto-pairs.kak new file mode 100644 index 0000000..16798d2 --- /dev/null +++ b/nate/dotfiles/kak/autoload/auto-pairs.kak @@ -0,0 +1,185 @@ +# Auto-pairing of characters +# Heavily based on Visual Studio Code. +# https://code.visualstudio.com +# +# Public commands: ["enable-auto-pairs", "disable-auto-pairs"] +# Public options: ["auto_pairs"] +# +# Usage: +# +# enable-auto-pairs +# +# Configuration: +# +# set-option global auto_pairs ( ) { } [ ] '"' '"' "'" "'" ` ` “ ” ‘ ’ « » ‹ › +# +# How does it work? +# +# The script installs insert hooks on opening pair characters, such as brackets and quotes. +# When auto-closing has been triggered, it activates the following functionalities: +# +# – {closing-pair} ⇒ Insert closing pair or move right in pair +# – Enter ⇒ Insert a new indented line in pair (only for the next key) +# – Control+Enter ⇒ Prompt a count for new indented lines in pair (only for the next key) +# +# When moving or leaving insert mode, the functionalities deactivate. +# +# Technical details: +# +# – Insert hooks are added on opening pair characters from %opt{auto_pairs} option. +# – Evaluates %opt{auto_close_trigger} option to activate auto-pairing. +# – Provides %opt{opening_pair} expansion in expressions. +# – Uses %opt{inserted_pairs} count to keep track of inserted pairs for inserting or moving in pair. +# – Uses the same implementation for nestable (such as brackets) and non-nestable (such as quotes) pairs. +# Since insert hooks are added on opening pair characters (for auto-pairing) and mappings on closing pair characters (for moving in pair), +# we can distinguish same pair characters once auto-pairing has been activated. + +# Configuration ──────────────────────────────────────────────────────────────── + +# List of surrounding pairs +declare-option -docstring 'list of surrounding pairs' str-list auto_pairs ( ) { } [ ] '"' '"' "'" "'" ` ` “ ” ‘ ’ « » ‹ › + +# Auto-pairing of characters activates only when this expression does not fail. +# By default, it avoids non-nestable pairs (such as quotes), escaped pairs and word characters. +declare-option -docstring 'auto-pairing of characters activates only when this expression does not fail' str auto_close_trigger '(\w["''`]|""|''''|``).\z[^\\]?\Q%opt{opening_pair}\E\W\z' + +# Internal variables ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ + +# Retain inserted pairs +declare-option -hidden str opening_pair +declare-option -hidden int inserted_pairs + +# Commands ───────────────────────────────────────────────────────────────────── + +define-command -override enable-auto-pairs -docstring 'enable auto-pairs' %{ + remove-hooks global auto-pairs + evaluate-commands %sh{ + set -- ${kak_opt_auto_pairs} + while [ "$2" ] + do + printf 'auto-close-pair %%<%s> %%<%s>\n' "$1" "$2" + shift 2 + done + } +} + +define-command -override disable-auto-pairs -docstring 'disable auto-pairs' %{ + remove-hooks global auto-pairs +} + +# Internal commands ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ + +define-command -override -hidden auto-close-pair -params 2 %{ + hook -group auto-pairs global InsertChar "\Q%arg{1}" "handle-inserted-opening-pair %%<%arg{1}> %%<%arg{2}>" + hook -group auto-pairs global InsertDelete "\Q%arg{1}" "handle-deleted-opening-pair %%<%arg{1}> %%<%arg{2}>" +} + +# Internal hooks ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ + +define-command -override -hidden handle-inserted-opening-pair -params 2 %{ + try %{ + # Test whether the commands contained in the option pass. + # If not, it will throw an exception and execution will jump to + # the “catch” block below. + set-option window opening_pair %arg{1} + execute-keys -draft %opt{auto_close_trigger} + + # Action: Close pair + execute-keys %arg{2} + + # Keep the track of inserted pairs + increment-inserted-pairs-count + + # Move back in pair (preserve selected text): + try %{ + execute-keys -draft '..' + execute-keys 'H' + } catch %{ + execute-keys 'h' + } + + # Add insert mappings + map -docstring 'insert closing pair or move right in pair' window insert %arg{2} ":insert-closing-pair-or-move-right-in-pair %%🐈%arg{2}🐈" + map -docstring 'insert a new indented line in pair' window insert ':insert-new-line-in-pair' + map -docstring 'prompt a count for new indented lines in pair' window insert ':prompt-insert-new-line-in-pair' + + # Enter is only available on next key. + hook -group auto-pairs -once window InsertChar '.*' %{ + unmap window insert + unmap window insert + } + + # Clean insert mappings and remove hooks + hook -group auto-pairs -once window WinSetOption 'inserted_pairs=0' " + unmap window insert %%🐈%arg{2}🐈 + unmap window insert + unmap window insert + remove-hooks window auto-pairs + " + + # Clean state when moving or leaving insert mode + hook -group auto-pairs -once window InsertMove '.*' %{ + reset-inserted-pairs-count + } + + hook -always -once window ModeChange 'pop:insert:normal' %{ + reset-inserted-pairs-count + } + } +} + +# Backspace ⇒ Erases the whole bracket +define-command -override -hidden handle-deleted-opening-pair -params 2 %{ + try %{ + execute-keys -draft ";\Q%arg{2}" + execute-keys '' + decrement-inserted-pairs-count + } +} + +# Internal mappings ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ + +# {closing-pair} ⇒ Insert closing pair or move right in pair +define-command -override -hidden insert-closing-pair-or-move-right-in-pair -params 1 %{ + try %{ + execute-keys -draft ";\Q%arg{1}" + # Move right in pair + execute-keys 'l' + decrement-inserted-pairs-count + } catch %{ + # Insert character with hooks + execute-keys -with-hooks %arg{1} + } +} + +# Enter ⇒ Insert a new indented line in pair (only for the next key) +define-command -override -hidden insert-new-line-in-pair %{ + execute-keys ';KKj' + execute-keys -with-hooks A + reset-inserted-pairs-count +} + +# Control+Enter ⇒ Prompt a count for new indented lines in pair (only for the next key) +define-command -override -hidden prompt-insert-new-line-in-pair %{ + prompt count: %{ + execute-keys ';KKj' + execute-keys "xHyx%val{text}O""" + execute-keys -with-hooks A + reset-inserted-pairs-count + } +} + +# ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ + +# Increment and decrement inserted pairs count +define-command -override -hidden increment-inserted-pairs-count %{ + set-option -add window inserted_pairs 1 +} + +define-command -override -hidden decrement-inserted-pairs-count %{ + set-option -remove window inserted_pairs 1 +} + +define-command -override -hidden reset-inserted-pairs-count %{ + set-option window inserted_pairs 0 +} diff --git a/nate/dotfiles/kak/autoload/phantom-selection.kak b/nate/dotfiles/kak/autoload/phantom-selection.kak new file mode 100644 index 0000000..e64c468 --- /dev/null +++ b/nate/dotfiles/kak/autoload/phantom-selection.kak @@ -0,0 +1,84 @@ +provide-module phantom-selection %{ + +set-face global PhantomSelection black,green+F + +declare-option -hidden str-list phantom_selections +declare-option -hidden range-specs phantom_selections_ranges + +add-highlighter global/ ranges phantom_selections_ranges + +define-command -hidden phantom-selection-store-and-highlight %{ + set window phantom_selections %reg{^} + set window phantom_selections_ranges %val{timestamp} + eval -no-hooks -draft -itersel %{ + set -add window phantom_selections_ranges "%val{selection_desc}|PhantomSelection" + } +} + +define-command -hidden phantom-selection-iterate-impl -params 1 %{ + eval -save-regs ^ %{ + reg ^ %opt{phantom_selections} + try %{ + exec z + exec %arg{1} + # keep the main selection and put all the other in the mark + # a recent change to Kakoune swaps with "," (and + # with ). Try both to make sure we clear selections + # both with and without this breaking change. Pad them with + # to cancel out the key with the other behavior. + exec -save-regs '' 'Z' + phantom-selection-store-and-highlight + exec '<,>' + } catch %{ + fail 'No phantom selections' + } + } +} + +define-command phantom-selection-iterate-next -docstring " +Turn secondary selections into phantoms and select the next phantom +" %{ + phantom-selection-iterate-impl ')' +} + +define-command phantom-selection-iterate-prev -docstring " +Turn secondary selections into phantoms and select the previous phantom +" %{ + phantom-selection-iterate-impl '(' +} + +define-command phantom-selection-clear -docstring " +Remove all phantom selections +" %{ + unset window phantom_selections + unset window phantom_selections_ranges +} + +define-command phantom-selection-select-all -docstring " +Select all phantom selections +" %{ + eval -save-regs ^ %{ + reg ^ %opt{phantom_selections} + try %{ + exec z + echo "" + } catch %{ + fail 'No phantom selections' + } + } +} + +define-command phantom-selection-add-selection -docstring " +Create phantoms out of the current selections +" %{ + eval -draft -save-regs ^ %{ + reg ^ %opt{phantom_selections} + try %{ exec "a" } + exec -save-regs '' "Z" + phantom-selection-store-and-highlight + } +} + +} + +require-module phantom-selection diff --git a/nate/dotfiles/kak/kakrc b/nate/dotfiles/kak/kakrc index ec330c2..8dd10ec 100644 --- a/nate/dotfiles/kak/kakrc +++ b/nate/dotfiles/kak/kakrc @@ -1,23 +1,3 @@ -# ------------------ -# Plugin Setup -# ------------------ - -# IMORTANT NOTE: -# I needed to open kakoune and type ':plug-install' to actually -# install the plugins listed in this file. I did not see this -# mentioned in wikis or anything, so make sure to do this to -# avoid searching github wikis and reddit needlessly. - -# Creates the /plugins folder if it doesnt exist each startup -evaluate-commands %sh{ - plugins="$kak_config/plugins" - mkdir -p "$plugins" - [ ! -e "$plugins/plug.kak" ] && \ - git clone -q https://github.com/andreyorst/plug.kak.git "$plugins/plug.kak" - printf "%s\n" "source '$plugins/plug.kak/rc/plug.kak'" -} -plug "andreyorst/plug.kak" noload - # ------------------ # Editor Settings # ------------------ @@ -28,17 +8,16 @@ set-option global startup_info_version 30000000 set-option global tabstop 4 set-option global indentwidth 4 set-option global scrolloff 5,3 -declare-option str kakrc_path "~/.config/kak/kakrc" -declare-option str sway_conf_path "~/.config/sway/config.d/default" -declare-option str shell_config "~/.zshrc" -# plug "catppuccin/kakoune" theme config %{ -# colorscheme catppuccin_macchiato -# } +declare-option str kakrc_path "~/system/nate/dotfiles/kak/kakrc" +declare-option str sway_conf_path "~/system/nate/dotfiles/sway/config.d/default" +declare-option str shell_config "~/system/nate/dotfiles/.zshrc" + colorscheme catppuccin_macchiato + # relative line numbers hook global BufCreate .* %{ - add-highlighter buffer/ number-lines -hlcursor + add-highlighter buffer/ number-lines -hlcursor } # Git Gutters @@ -50,7 +29,7 @@ hook global WinCreate .* %{ evaluate-commands %sh{ # Write on unfocus hook global FocusOut .* %{ try %{ - write + write }} hook global BufWritePost .* %{ evaluate-commands 'git update-diff' } @@ -153,7 +132,9 @@ map global normal -docstring 'prev result add selection' map global insert -docstring 'next completion' map global insert -docstring 'prev completion' -# User Mode Bindings +# ------------------ +# User mode Bindings +# ------------------ # Accessed with declare-user-mode git map global user g ': enter-user-mode git' -docstring "Git mode" @@ -173,80 +154,61 @@ map global git d ':git show-diff' -docstring "Show diff" # LSP Configuration # ----------------- -plug "kak-lsp/kak-lsp" do %{ - cargo install --locked --force --path . - mkdir -p ~/.config/kak-lsp - cp -n kak-lsp.toml ~/.config/kak-lsp/ -} config %{ +# plug "kak-lsp/kak-lsp" do %{ +# cargo install --locked --force --path . +# mkdir -p ~/.config/kak-lsp +# cp -n kak-lsp.toml ~/.config/kak-lsp/ +# } config %{ # enable inlay hints - lsp-inlay-hints-enable global - lsp-inlay-diagnostics-enable global - # set global lsp_diagnostic_line_error_sign '║' # set global lsp_diagnostic_line_warning_sign '┊' - define-command lsp-restart -docstring 'restart lsp server' %{ lsp-stop; lsp-start } +define-command lsp-restart -docstring 'restart lsp server' %{ lsp-stop; lsp-start } +map global insert ':try lsp-snippets-select-next-placeholders catch %{ execute-keys -with-hooks tab> }' -docstring 'Select next snippet placeholder' +map global object a 'lsp-object' -docstring 'LSP any symbol' +map global object 'lsp-object' -docstring 'LSP any symbol' +map global object e 'lsp-object Function Method' -docstring 'LSP function or method' +map global object k 'lsp-object Class Interface Struct' -docstring 'LSP class interface or struct' +map global object d 'lsp-diagnostic-object --include-warnings' -docstring 'LSP errors and warnings' +map global object D 'lsp-diagnostic-object' -docstring 'LSP errors' - map global insert ':try lsp-snippets-select-next-placeholders catch %{ execute-keys -with-hooks tab> }' -docstring 'Select next snippet placeholder' - map global object a 'lsp-object' -docstring 'LSP any symbol' - map global object 'lsp-object' -docstring 'LSP any symbol' - map global object e 'lsp-object Function Method' -docstring 'LSP function or method' - map global object k 'lsp-object Class Interface Struct' -docstring 'LSP class interface or struct' - map global object d 'lsp-diagnostic-object --include-warnings' -docstring 'LSP errors and warnings' - map global object D 'lsp-diagnostic-object' -docstring 'LSP errors' - - # load lsp for supported filetypes - set-option global lsp_cmd "kak-lsp -s %val{session} -vvv --log /tmp/kak-lsp.log" - hook global WinSetOption filetype=(rust|python|go|javascript|typescript|c|cpp|zig|dart|ruby) %{ +eval %sh{kak-lsp --kakoune -s $kak_session} # Not needed if you load it with plug.kak. +hook global WinSetOption filetype=(rust|python|go|javascript|typescript|c|cpp|dart|zig|nix|ocaml) %{ lsp-enable-window - # lsp-auto-hover-enable map global user l ': enter-user-mode lsp' -docstring 'lsp mode' map global user h ': enter-user-mode lsph' -docstring 'lsp help' map global user a ': enter-user-mode lspa' -docstring 'lsp code action' - set-option global lsp_hover_anchor false - } - - hook global KakEnd .* lsp-exit + set-option global lsp_hover_anchor true + lsp-inlay-hints-enable global + lsp-inlay-diagnostics-enable global } +hook global KakEnd .* lsp-exit + # load lsp for supported filetypes + # set-option global lsp_cmd "kak-lsp -s %val{session} -vvv --log /tmp/kak-lsp.log" + # hook global WinSetOption filetype=(rust|python|go|javascript|typescript|c|cpp|zig|dart|ruby) %{ + # lsp-enable-window + # # lsp-auto-hover-enable + # map global user l ': enter-user-mode lsp' -docstring 'lsp mode' + # map global user h ': enter-user-mode lsph' -docstring 'lsp help' + # map global user a ': enter-user-mode lspa' -docstring 'lsp code action' + # set-option global lsp_hover_anchor false + # } + + +# } + # ----------------- # Other Plugins # ----------------- +# fzf file picker map global goto f ':prompt -shell-script-candidates %{ fd --type f --hidden } file: %{ edit %val{text} }' -docstring "file" map global goto b ':prompt -buffer-completion buffer: %{ buffer %val{text} }' -docstring "buffer" -# Fzf Plugin -plug "andreyorst/fzf.kak" config %{ - # map global user f ':fzf-modev' -docstring 'fzf file in project' - map global user b ':fzf-modeb' -docstring 'fzf current buffers' - - map global user / ':fzf-modeg' -docstring 'fzf search in project' - - # def fzf_file %{ - # evaluate-commands %sh{ - # printf "%s\n" ":fzf-mode:fzf -items-cmd fd" - # } - # } - -# Change FZF colors -# FZF_DEFAULT_OPTS=" \ -# --color=bg+:#313244,bg:#1e1e2e,spinner:#f5e0dc,hl:#f38ba8 \ -# --color=fg:#cdd6f4,header:#f38ba8,info:#cba6f7,pointer:#f5e0dc \ -# --color=marker:#f5e0dc,fg+:#cdd6f4,prompt:#cba6f7,hl+:#f38ba8" -} - - - -plug "alexherbo2/auto-pairs.kak" %{ - enable-auto-pairs -} - -plug "https://github.com/h-youhei/kakoune-surround" +map global user b ':fzf-modeb' -docstring 'fzf current buffers' +map global user / ':fzf-modeg' -docstring 'fzf search in project' map global normal ':surround' - -# Custom scripts -source "~/.config/kak/rc/fzf_git.kak" diff --git a/nate/modules/apps/firefox/firefox.nix b/nate/modules/apps/firefox/firefox.nix index eb422b5..e874d5f 100644 --- a/nate/modules/apps/firefox/firefox.nix +++ b/nate/modules/apps/firefox/firefox.nix @@ -12,7 +12,13 @@ in }; config = lib.mkIf cfg.enable { programs.firefox = { + # Add pipewire support + package = (pkgs.wrapFirefox (pkgs.firefox-unwrapped.override { pipewireSupport = true;}) {}); enable = true; + # Use system file picker + preferences = { + "widget.use-xdg-desktop-portal.file-picker" = 1; + }; profiles = { default = { id = 0; @@ -33,6 +39,17 @@ in template = "https://www.startpage.com/sp/search?query={searchTerms}"; }]; }; + "Nix Packages" = { + urls = [{ + template = "https://search.nixos.org/packages"; + params = [ + { name = "type"; value = "packages"; } + { name = "query"; value = "{searchTerms}"; } + ]; + }]; + icon = "${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg"; + definedAliases = [ "@np" ]; + }; }; }; settings = { @@ -54,7 +71,7 @@ in "signon.rememberSignon" = false; "extensions.formautofill.creditCards.enabled" = false; "extensions.formautofill.addresses.enabled" = false; - # "browser.bookmarks.showMobileBookmarks" = true; + "browser.toolbars.bookmarks.visibility" = "always"; # "browser.newtabpage.pinned" = [{ # title = "NixOS"; # url = "https://nixos.org"; diff --git a/nate/modules/home-manager/home.nix b/nate/modules/home-manager/home.nix index 94ffcd3..7126fed 100644 --- a/nate/modules/home-manager/home.nix +++ b/nate/modules/home-manager/home.nix @@ -30,7 +30,7 @@ home.packages = with pkgs; [ # nur.repos.crazazy.js.eslint # inputs.nixpkgs-stable.legacyPackages.x86_64-linux.corectrl - + chromium # # Dev Tools # @@ -40,10 +40,12 @@ flutter316 docker docker-compose + jq python310 nodejs_21 zig ### LSP's + kak-lsp rnix-lsp # Nix LSP openscad-lsp nodePackages.typescript-language-server @@ -61,6 +63,7 @@ # Gaming # amdgpu_top + mangohud wine-wayland webcord @@ -75,6 +78,8 @@ ripgrep tre-command gtop + htop + neofetch # Normies unzip diff --git a/nate/modules/sway/sway_conf.nix b/nate/modules/sway/sway_conf.nix index 90b9e66..fc04db1 100644 --- a/nate/modules/sway/sway_conf.nix +++ b/nate/modules/sway/sway_conf.nix @@ -103,6 +103,7 @@ programs.zsh.enable = true; programs.steam.enable = config.swaywm.installGaming; + programs.gamemode.enable = true; programs.adb.enable = true; # kdeconnect setup