@@ -40,6 +40,11 @@ function ls; exa $argv; end | |||||
function ll; exa -l $argv; end | function ll; exa -l $argv; end | ||||
function vim; nvim $argv; end | function vim; nvim $argv; end | ||||
function k; kubectl $argv; end | |||||
function ka; kubectl $argv --all-namespaces; end | |||||
function kw; watch -n1 "kubectl $argv"; end | |||||
function kx; kubectl config use-context $argv; end | |||||
# Dotfiles management | # Dotfiles management | ||||
function dots | function dots | ||||
if test (count $argv) -eq 1 | if test (count $argv) -eq 1 | ||||
@@ -1,9 +1,8 @@ | |||||
(doom-load-envvars-file (concat doom-private-dir "env.el")) | |||||
;;; -*- lexical-binding: t; -*- | |||||
(setq doom-modeline-major-mode-icon t) | |||||
(doom-load-envvars-file (concat doom-user-dir "env.el")) | |||||
(make-variable-buffer-local 'lexical-binding) | |||||
(setq lexical-binding t) | |||||
(setq doom-modeline-major-mode-icon t) | |||||
(use-package request | (use-package request | ||||
:commands request) | :commands request) | ||||
@@ -53,15 +52,16 @@ returned by `request`." | |||||
("TAB" . "<tab>")))) | ("TAB" . "<tab>")))) | ||||
(my/replace-regexps-in-string str kbd-regex))) | (my/replace-regexps-in-string str kbd-regex))) | ||||
(setq my//kbd-p nil) | |||||
(defun my/kbd!-p () (eq my//kbd-p t)) | |||||
(setq my//vim!-p nil) | |||||
(defun my/vim!-p () (eq my//vim!-p t)) | |||||
(defun kbd! (str) | |||||
(defun vim! (str) | |||||
"Execute the key sequence defined by STR like a VIM macro." | "Execute the key sequence defined by STR like a VIM macro." | ||||
(let ((minibuffer-message-timeout 0)) | (let ((minibuffer-message-timeout 0)) | ||||
(setq my//kbd-p t) | |||||
(execute-kbd-macro (read-kbd-macro (my/kbd-replace str))) | |||||
(setq my//kbd-p nil))) | |||||
(when (not (my/vim!-p)) | |||||
(setq my//vim!-p t) | |||||
(execute-kbd-macro (read-kbd-macro (my/kbd-replace str))) | |||||
(setq my//vim!-p nil)))) | |||||
(defun my/buffer-local-set-key (key fn) | (defun my/buffer-local-set-key (key fn) | ||||
(let ((mode (intern (format "%s-local-mode" (buffer-name)))) | (let ((mode (intern (format "%s-local-mode" (buffer-name)))) | ||||
@@ -100,6 +100,62 @@ returned by `request`." | |||||
secret))))) | secret))))) | ||||
,@body)) | ,@body)) | ||||
(defun ts/proxy-on () | |||||
(interactive) | |||||
(setq url-proxy-services | |||||
'(("http" . "127.0.0.1:20001") | |||||
("https" . "127.0.0.1:20001") | |||||
("no_proxy" . "^.*twosigma\\.com")))) | |||||
(defun ts/proxy-off () | |||||
(interactive) | |||||
(setq url-proxy-services nil)) | |||||
(setq sourcegraph-url "https://sourcegraph.app.twosigma.com") | |||||
(defun ts/sourcegraph-search () | |||||
(interactive) | |||||
(call-interactively #'sourcegraph-search)) | |||||
(defun ts/sourcegraph-browse () | |||||
(interactive) | |||||
(call-interactively #'sourcegraph-open-in-browser)) | |||||
(setq ts/search-url "https://search.app.twosigma.com/?q=%s") | |||||
(defun ts/search (query) | |||||
(interactive "sQuery: ") | |||||
(browse-url (format ts/search-url query))) | |||||
(defun ts/repo/root (&optional dir) | |||||
(locate-dominating-file ($cwd dir) ".base_universe")) | |||||
(defun ts/repo/codebase (&optional dir) | |||||
(locate-dominating-file ($cwd dir) ".git")) | |||||
(defun ts/repo/p (&optional dir) | |||||
(when (ts/repo/root dir) t)) | |||||
(defun shell! (fmt &rest args) | |||||
(let* ((cmd (apply #'format (cons fmt args))) | |||||
(cmd (format "%s 2>/dev/null" cmd)) | |||||
(result (shell-command-to-string cmd)) | |||||
(result (replace-regexp-in-string | |||||
"\r?\n$" "" | |||||
result))) | |||||
(if (equal result "") | |||||
nil | |||||
result))) | |||||
(defun locate! (file &optional dir) | |||||
(locate-dominating-file ($cwd dir) file)) | |||||
(defun path! (&rest components) | |||||
(apply #'f-join components)) | |||||
(defun $file () buffer-file-name) | |||||
(defun $cwd (&optional dir) | |||||
(if dir | |||||
dir | |||||
(f-dirname ($file)))) | |||||
(setq doom-theme 'doom-catppuccin) | (setq doom-theme 'doom-catppuccin) | ||||
(setq doom-font (font-spec :family "monospace" :size 13) | (setq doom-font (font-spec :family "monospace" :size 13) | ||||
@@ -111,15 +167,28 @@ returned by `request`." | |||||
(setq evil-want-fine-undo t) | (setq evil-want-fine-undo t) | ||||
(defun my/scroll-up () | |||||
(interactive) | |||||
(evil-scroll-line-up 2)) | |||||
(defun my/scroll-down () | |||||
(interactive) | |||||
(evil-scroll-line-down 2)) | |||||
(defun my/scroll-up-bigly () | |||||
(interactive) | |||||
(evil-scroll-line-up 5)) | |||||
(defun my/scroll-down-bigly () | |||||
(interactive) | |||||
(evil-scroll-line-down 5)) | |||||
(defmacro my//center-cmd (name &rest body) | (defmacro my//center-cmd (name &rest body) | ||||
`(defun ,name () | `(defun ,name () | ||||
(interactive) | (interactive) | ||||
,@body | ,@body | ||||
(call-interactively #'evil-scroll-line-to-center))) | (call-interactively #'evil-scroll-line-to-center))) | ||||
(my//center-cmd my/scroll-up (evil-scroll-up evil-scroll-count)) | |||||
(my//center-cmd my/scroll-down (evil-scroll-down evil-scroll-count)) | |||||
(my//center-cmd my/jump-forward (better-jumper-jump-forward)) | (my//center-cmd my/jump-forward (better-jumper-jump-forward)) | ||||
(my//center-cmd my/jump-backward (better-jumper-jump-backward)) | (my//center-cmd my/jump-backward (better-jumper-jump-backward)) | ||||
@@ -136,7 +205,9 @@ returned by `request`." | |||||
(defun my/duplicate-and-comment-line () | (defun my/duplicate-and-comment-line () | ||||
(interactive) | (interactive) | ||||
(kbd! "yyp k gcc j")) | |||||
(vim! "yyp k gcc j")) | |||||
(setq search-invisible t) | |||||
(defun my/line-numbers-relative () | (defun my/line-numbers-relative () | ||||
(setq display-line-numbers 'relative)) | (setq display-line-numbers 'relative)) | ||||
@@ -166,7 +237,16 @@ returned by `request`." | |||||
(setq doom-scratch-initial-major-mode 'lisp-interaction-mode) | (setq doom-scratch-initial-major-mode 'lisp-interaction-mode) | ||||
(use-package abbrev-mode | |||||
:hook text-mode) | |||||
(setq +abbrev-file (concat doom-user-dir "abbrevs.el")) | |||||
(setq abbrev-file-name +abbrev-file) | |||||
(map! :leader | (map! :leader | ||||
":" nil | |||||
"b" nil | "b" nil | ||||
"f" nil | "f" nil | ||||
"h" nil | "h" nil | ||||
@@ -194,7 +274,7 @@ returned by `request`." | |||||
:desc "Apply code action" :ni "C-/" #'lsp-execute-code-action | :desc "Apply code action" :ni "C-/" #'lsp-execute-code-action | ||||
:desc "Show definitions" :ni "C-." #'+lookup/definition | :desc "Show definitions" :ni "C-." #'+lookup/definition | ||||
:desc "Show references" :ni "C->" #'my/lookup/references | |||||
:desc "Show references" :ni "C->" #'my/lsp/lookup-references | |||||
:desc "Jump backward" :ni "C-," #'better-jumper-jump-backward | :desc "Jump backward" :ni "C-," #'better-jumper-jump-backward | ||||
:desc "Jump backward" :ni "C-<" #'better-jumper-jump-forward) | :desc "Jump backward" :ni "C-<" #'better-jumper-jump-forward) | ||||
@@ -211,10 +291,10 @@ returned by `request`." | |||||
:desc "Save file" "C-s" #'save-buffer) | :desc "Save file" "C-s" #'save-buffer) | ||||
(map! | (map! | ||||
:desc "Scroll page up" :ni "C-S-k" #'my/scroll-up | |||||
:desc "Scroll page down" :ni "C-S-j" #'my/scroll-down | |||||
:desc "Scroll line up" :ni "C-k" #'evil-scroll-line-up | |||||
:desc "Scroll line down" :ni "C-j" #'evil-scroll-line-down | |||||
:desc "Scroll up" :ni "C-k" #'my/scroll-up | |||||
:desc "Scroll down" :ni "C-j" #'my/scroll-down | |||||
:desc "Scroll up bigly" :ni "C-S-k" #'my/scroll-up-bigly | |||||
:desc "Scroll down bigly" :ni "C-S-j" #'my/scroll-down-bigly | |||||
:desc "Jump forward" :n "C-o" #'my/jump-forward | :desc "Jump forward" :n "C-o" #'my/jump-forward | ||||
:desc "Jump backward" :n "C-o" #'my/jump-backward | :desc "Jump backward" :n "C-o" #'my/jump-backward | ||||
@@ -266,7 +346,29 @@ returned by `request`." | |||||
:desc "ibuffer" "i" #'ibuffer | :desc "ibuffer" "i" #'ibuffer | ||||
:desc "Kill buffer" "d" #'kill-current-buffer | :desc "Kill buffer" "d" #'kill-current-buffer | ||||
:desc "Kill all buffers" "D" #'doom/kill-all-buffers) | |||||
:desc "Kill all buffers" "D" #'doom/kill-all-buffers | |||||
:desc "Rename buffer" "r" #'my/rename-buffer) | |||||
(defun my/rename-buffer (name) | |||||
(interactive (list (read-string "Rename: " (buffer-name)))) | |||||
(rename-buffer name)) | |||||
(map! :leader | |||||
:prefix ("c" . "code") | |||||
:desc "Format region/buffer" "f" #'+format/region-or-buffer | |||||
:desc "Format imports" "F" #'lsp-organize-imports | |||||
:desc "Rename symbol" "r" #'lsp-rename | |||||
:desc "Show errors list" "x" #'+default/diagnostics | |||||
:desc "Show errors tree" "X" #'lsp-treemacs-errors-list | |||||
:desc "Show symbols tree" "s" #'lsp-treemacs-symbols | |||||
:desc "Visit lens" "l" #'lsp-avy-lens | |||||
:desc "Restart LSP" "q" #'lsp-restart-workspace) | |||||
(map! :leader | (map! :leader | ||||
:prefix ("f" . "files") | :prefix ("f" . "files") | ||||
@@ -289,26 +391,34 @@ returned by `request`." | |||||
:desc "Open scratch" "x" #'doom/open-scratch-buffer) | :desc "Open scratch" "x" #'doom/open-scratch-buffer) | ||||
(map! :leader | (map! :leader | ||||
:prefix ("f s" . "snippets") | |||||
:desc "Find snippet" "f" #'my/yas-find-snippet | |||||
:desc "New snippet" "n" #'yas/new-snippet | |||||
:desc "Edit snippet" "e" #'my/yas-edit-snippet | |||||
:prefix ("f a" . "abbrevs") | |||||
:desc "Edit abbrevs" "e" #'my/abbrev-edit | |||||
:desc "Reload abbrevs" "r" #'my/abbrev-reload | |||||
:desc "Describe snippets" "d" #'yas/describe-tables | |||||
:desc "Reload snippets" "r" #'yas/reload-all | |||||
:desc "Browse docs" "?" #'my/yas-browse-docs) | |||||
:desc "Add global abbrev" "a" #'my/abbrev-add-global | |||||
:desc "Add mode abbrev" "m" #'my/abbrev-add-mode) | |||||
(defun my/yas-browse-docs () | |||||
(defun my/abbrev-edit () | |||||
(interactive) | (interactive) | ||||
(browse-url "https://joaotavora.github.io/yasnippet")) | |||||
(find-file-other-window +abbrev-file)) | |||||
(defun my/yas-edit-snippet () | |||||
(defun my/abbrev-reload () | |||||
(interactive) | (interactive) | ||||
(call-interactively #'yas/visit-snippet-file)) | |||||
(read-abbrev-file +abbrev-file)) | |||||
(defun my/yas-find-snippet () | |||||
(defun my/abbrev-save () | |||||
(interactive) | (interactive) | ||||
(counsel-find-file nil +snippets-dir)) | |||||
(write-abbrev-file +abbrev-file)) | |||||
(defun my/abbrev-add-global () | |||||
(interactive) | |||||
(call-interactively #'inverse-add-global-abbrev) | |||||
(my/abbrev-save)) | |||||
(defun my/abbrev-add-mode () | |||||
(interactive) | |||||
(call-interactively #'inverse-add-mode-abbrev) | |||||
(my/abbrev-save)) | |||||
(map! :leader | (map! :leader | ||||
:prefix ("f e" . "emacs") | :prefix ("f e" . "emacs") | ||||
@@ -322,21 +432,43 @@ returned by `request`." | |||||
(defun my/edit-config () | (defun my/edit-config () | ||||
(interactive) | (interactive) | ||||
(find-file (concat doom-private-dir "config.org"))) | |||||
(find-file (concat doom-user-dir "config.org"))) | |||||
(defun my/edit-packages () | (defun my/edit-packages () | ||||
(interactive) | (interactive) | ||||
(find-file (concat doom-private-dir "packages.el"))) | |||||
(find-file (concat doom-user-dir "packages.el"))) | |||||
(defun my/edit-init () | (defun my/edit-init () | ||||
(interactive) | (interactive) | ||||
(find-file (concat doom-private-dir "init.el"))) | |||||
(find-file (concat doom-user-dir "init.el"))) | |||||
(defun my/edit-env () | (defun my/edit-env () | ||||
(interactive) | (interactive) | ||||
(find-file (concat doom-private-dir "env.el"))) | |||||
(find-file (concat doom-user-dir "env.el"))) | |||||
(define-derived-mode org-config-mode org-mode "Org config mode") | (define-derived-mode org-config-mode org-mode "Org config mode") | ||||
(add-to-list 'auto-mode-alist '("config\\.org" . org-config-mode)) | (add-to-list 'auto-mode-alist '("config\\.org" . org-config-mode)) | ||||
(map! :leader | (map! :leader | ||||
:prefix ("f s" . "snippets") | |||||
:desc "Find snippet" "f" #'my/yas-find-snippet | |||||
:desc "New snippet" "n" #'yas/new-snippet | |||||
:desc "Edit snippet" "e" #'my/yas-edit-snippet | |||||
:desc "Describe snippets" "d" #'yas/describe-tables | |||||
:desc "Reload snippets" "r" #'yas/reload-all | |||||
:desc "Browse docs" "?" #'my/yas-browse-docs) | |||||
(defun my/yas-browse-docs () | |||||
(interactive) | |||||
(browse-url "https://joaotavora.github.io/yasnippet")) | |||||
(defun my/yas-edit-snippet () | |||||
(interactive) | |||||
(call-interactively #'yas/visit-snippet-file)) | |||||
(defun my/yas-find-snippet () | |||||
(interactive) | |||||
(counsel-find-file nil +snippets-dir)) | |||||
(map! :leader | |||||
:prefix ("h" . "help") | :prefix ("h" . "help") | ||||
:desc "Apropos" "/" #'consult-apropos | :desc "Apropos" "/" #'consult-apropos | ||||
@@ -416,6 +548,14 @@ returned by `request`." | |||||
:desc "Doom sandbox" "x" #'doom/sandbox) | :desc "Doom sandbox" "x" #'doom/sandbox) | ||||
(map! :leader | (map! :leader | ||||
:prefix ("l" . "ligma") | |||||
:desc "Search" "s" #'ts/search | |||||
:desc "Sourcegraph search" "g" #'ts/sourcegraph-search | |||||
:desc "Sourcegraph browse" "G" #'ts/sourcegraph-browse) | |||||
(map! :leader | |||||
:prefix ("p" . "projects") | :prefix ("p" . "projects") | ||||
:desc "Switch project" "p" #'my/projectile-switch-project | :desc "Switch project" "p" #'my/projectile-switch-project | ||||
:desc "Add new project" "a" #'projectile-add-known-project | :desc "Add new project" "a" #'projectile-add-known-project | ||||
@@ -459,8 +599,10 @@ returned by `request`." | |||||
:desc "Go right" "l" #'evil-window-right | :desc "Go right" "l" #'evil-window-right | ||||
:desc "Go other" "o" #'other-window | :desc "Go other" "o" #'other-window | ||||
;; Layout | ;; Layout | ||||
:desc "Rotate up" "K" #'evil-window-rotate-upwards | |||||
:desc "Rotate down" "J" #'evil-window-rotate-downwards | |||||
:desc "Move left" "H" #'+evil/window-move-left | |||||
:desc "Move down" "J" #'+evil/window-move-down | |||||
:desc "Move up" "K" #'+evil/window-move-up | |||||
:desc "Move right" "L" #'+evil/window-move-right | |||||
;; Splits | ;; Splits | ||||
:desc "VSplit" "=" #'+evil/window-vsplit-and-follow | :desc "VSplit" "=" #'+evil/window-vsplit-and-follow | ||||
:desc "HSplit" "-" #'+evil/window-split-and-follow | :desc "HSplit" "-" #'+evil/window-split-and-follow | ||||
@@ -469,7 +611,8 @@ returned by `request`." | |||||
:desc "Undo" "u" #'winner-undo | :desc "Undo" "u" #'winner-undo | ||||
:desc "Redo" "U" #'winner-redo | :desc "Redo" "U" #'winner-redo | ||||
;; Misc | ;; Misc | ||||
:desc "Resize" "r" #'my/hydra-window-resize/body | |||||
:desc "Resize..." "r" #'my/hydra-window-resize/body | |||||
:desc "Rotate..." "R" #'my/hydra-window-rotate/body | |||||
:desc "Balance" "b" #'balance-windows | :desc "Balance" "b" #'balance-windows | ||||
;; Management | ;; Management | ||||
:desc "Kill window" "d" #'+workspace/close-window-or-workspace) | :desc "Kill window" "d" #'+workspace/close-window-or-workspace) | ||||
@@ -499,21 +642,16 @@ returned by `request`." | |||||
("l" my/window-increase-width "++Width") | ("l" my/window-increase-width "++Width") | ||||
("ESC" nil "Quit" :color blue)) | ("ESC" nil "Quit" :color blue)) | ||||
(map! :leader | |||||
:prefix ("c" . "code") | |||||
:desc "Format region/buffer" "f" #'+format/region-or-buffer | |||||
:desc "Format imports" "F" #'lsp-organize-imports | |||||
:desc "Rename symbol" "r" #'lsp-rename | |||||
:desc "Show errors list" "x" #'+default/diagnostics | |||||
:desc "Show errors tree" "X" #'lsp-treemacs-errors-list | |||||
:desc "Show symbols tree" "s" #'lsp-treemacs-symbols | |||||
:desc "Visit lens" "l" #'lsp-avy-lens | |||||
:desc "Restart LSP" "q" #'lsp-restart-workspace) | |||||
(defhydra my/hydra-window-rotate () | |||||
"Rotate window" | |||||
("h" +evil/window-move-left "Move left") | |||||
("j" +evil/window-move-down "Move down") | |||||
("k" +evil/window-move-up "Move up") | |||||
("l" +evil/window-move-right "Move right") | |||||
("H" evil-window-move-far-left "Move far left") | |||||
("J" evil-window-rotate-downwards "Rotate Down") | |||||
("K" evil-window-rotate-upwards "Rotate Up") | |||||
("L" evil-window-move-far-right "Move far right")) | |||||
(map! :map org-config-mode-map | (map! :map org-config-mode-map | ||||
:localleader | :localleader | ||||
@@ -525,38 +663,40 @@ returned by `request`." | |||||
(org-ctrl-c-ctrl-c) | (org-ctrl-c-ctrl-c) | ||||
(org-babel-remove-result)) | (org-babel-remove-result)) | ||||
(map! :map rustic-mode-map | |||||
:localleader | |||||
"b" nil | |||||
"t" nil) | |||||
;; (map! :map rustic-mode-map | |||||
;; :localleader | |||||
;; "b" nil | |||||
;; "t" nil) | |||||
(map! :map rustic-mode-map | |||||
:localleader | |||||
:desc "Edit Cargo.toml" "t" #'my/rust/edit-cargo-toml) | |||||
;; (map! :map rustic-mode-map | |||||
;; :localleader | |||||
;; :desc "Edit Cargo.toml" "t" #'my/rust/edit-cargo-toml) | |||||
(map! :map rustic-mode-map | |||||
:leader | |||||
:prefix ("c" . "code") | |||||
:desc "Expand macro" "m" #'lsp-rust-analyzer-expand-macro | |||||
:desc "Open docs" "h" #'lsp-rust-analyzer-open-external-docs) | |||||
;; (map! :map rustic-mode-map | |||||
;; :leader | |||||
;; :prefix ("c" . "code") | |||||
;; :desc "Expand macro" "m" #'lsp-rust-analyzer-expand-macro | |||||
;; :desc "Open docs" "h" #'lsp-rust-analyzer-open-external-docs) | |||||
(map! :map rustic-mode-map | |||||
:prefix ("cb" . "build") | |||||
;; (map! :map rustic-mode-map | |||||
;; :localleader | |||||
;; :prefix ("b" . "build") | |||||
:desc "Build" "b" #'rustic-cargo-check | |||||
:desc "Check" "c" #'rustic-cargo-check | |||||
;; :desc "Build" "b" #'rustic-cargo-check | |||||
;; :desc "Check" "c" #'rustic-cargo-check | |||||
:desc "Debug" "d" #'my/rust/dap-hydra/body | |||||
:desc "Run" "r" #'rustic-cargo-run | |||||
;; :desc "Debug" "d" #'my/rust/dap-hydra/body | |||||
;; :desc "Run" "r" #'rustic-cargo-run | |||||
:desc "Bench" "B" #'rustic-cargo-bench | |||||
:desc "Test current" "t" #'rustic-cargo-current-test | |||||
:desc "Test all" "T" #'rustic-cargo-test) | |||||
;; :desc "Bench" "B" #'rustic-cargo-bench | |||||
;; :desc "Test current" "t" #'rustic-cargo-current-test | |||||
;; :desc "Test all" "T" #'rustic-cargo-test) | |||||
(map! :map rustic-mode-map | (map! :map rustic-mode-map | ||||
:desc "Pluralize import" "," #'my/rust/import-pluralize | :desc "Pluralize import" "," #'my/rust/import-pluralize | ||||
:desc "Singularize import" "<backspace>" #'my/rust/import-singularize | :desc "Singularize import" "<backspace>" #'my/rust/import-singularize | ||||
:desc "Singularize import" "C-<backspace>" #'my/rust/import-c-singularize) | |||||
:desc "Singularize import" "C-<backspace>" #'my/rust/import-c-singularize | |||||
:desc "Singularize import" "C-<delete>" #'my/rust/import-rev-singularize) | |||||
(defhydra my/rust/dap-hydra (:color pink :hint nil :foreign-keys run) | (defhydra my/rust/dap-hydra (:color pink :hint nil :foreign-keys run) | ||||
" | " | ||||
@@ -634,42 +774,54 @@ _Q_: Disconnect _sd_: Down stack frame _bh_: Set hit count | |||||
(+ crate) | (+ crate) | ||||
(? ";") line-end)) | (? ";") line-end)) | ||||
(setq my//rust/import-plural-rx | (setq my//rust/import-plural-rx | ||||
;; use foo::bar::baz::{qux::quo, }; | |||||
;; use foo::bar::baz::{qux::quo, }; | |||||
(rx "use " | (rx "use " | ||||
(+ (+ crate) "::") | (+ (+ crate) "::") | ||||
"{" (* (+ crate) "::") (+ crate) "," (* whitespace) "}" | "{" (* (+ crate) "::") (+ crate) "," (* whitespace) "}" | ||||
(? ";") line-end)) | |||||
(setq my//rust/import-plural-rev-rx | |||||
;; use foo::bar::baz::{, qux::quo}; | |||||
(rx "use " | |||||
(+ (+ crate) "::") | |||||
"{," (* whitespace) (* (+ crate) "::") (+ crate) "}" | |||||
(? ";") line-end))) | (? ";") line-end))) | ||||
(defun my/rust/import-pluralize () | (defun my/rust/import-pluralize () | ||||
"Convert a singular import into a brace-wrapped plural import." | "Convert a singular import into a brace-wrapped plural import." | ||||
(interactive) | (interactive) | ||||
(if (and | (if (and | ||||
(not (my/kbd!-p)) | |||||
(my/insert-mode-p) | (my/insert-mode-p) | ||||
(my/line-match-p my//rust/import-singular-rx)) | (my/line-match-p my//rust/import-singular-rx)) | ||||
(kbd! "ESC vb S} f} i,") | |||||
(vim! "ESC vb S} f} i,") | |||||
(insert ","))) | (insert ","))) | ||||
(defun my/rust/import-singularize () | (defun my/rust/import-singularize () | ||||
"Convert a brace-wrapped plural import into a singular import." | "Convert a brace-wrapped plural import into a singular import." | ||||
(interactive) | (interactive) | ||||
(if (and | (if (and | ||||
(not (my/kbd!-p)) | |||||
(my/insert-mode-p) | (my/insert-mode-p) | ||||
(my/line-match-p my//rust/import-plural-rx)) | (my/line-match-p my//rust/import-plural-rx)) | ||||
(kbd! "ESC l dF, ds} $i") | |||||
(vim! "ESC l dF, ds} $i") | |||||
(evil-delete-backward-char-and-join 1))) | (evil-delete-backward-char-and-join 1))) | ||||
(defun my/rust/import-c-singularize () | (defun my/rust/import-c-singularize () | ||||
"Convert a brace-wrapped plural import into a singular import." | "Convert a brace-wrapped plural import into a singular import." | ||||
(interactive) | (interactive) | ||||
(if (and | (if (and | ||||
(not (my/kbd!-p)) | |||||
(my/insert-mode-p) | (my/insert-mode-p) | ||||
(my/line-match-p my//rust/import-plural-rx)) | (my/line-match-p my//rust/import-plural-rx)) | ||||
(kbd! "ESC l dF, ds} $i") | |||||
(vim! "ESC l dF, ds} $i") | |||||
(backward-kill-word 1))) | (backward-kill-word 1))) | ||||
(defun my/rust/import-rev-singularize () | |||||
"Convert a brace-wrapped plural import into a singular import." | |||||
(interactive) | |||||
(if (and | |||||
(my/insert-mode-p) | |||||
(my/line-match-p my//rust/import-plural-rev-rx)) | |||||
(vim! "ESC ds} dw $i") | |||||
(kill-word 1))) | |||||
(defun my/rust/debug-config (args) | (defun my/rust/debug-config (args) | ||||
(append | (append | ||||
`(:type "lldb-vscode" | `(:type "lldb-vscode" | ||||
@@ -752,7 +904,7 @@ _Q_: Disconnect _sd_: Down stack frame _bh_: Set hit count | |||||
(defun my/rust/edit-cargo-toml () | (defun my/rust/edit-cargo-toml () | ||||
(interactive) | (interactive) | ||||
(lsp-rust-analyzer-open-cargo-toml t)) | |||||
(lsp-rust-analyzer-open-cargo-toml)) | |||||
(defun my/rust/get-latest-crate-version (crate callback) | (defun my/rust/get-latest-crate-version (crate callback) | ||||
(request! (format "https://crates.io/api/v1/crates/%s/versions" crate) | (request! (format "https://crates.io/api/v1/crates/%s/versions" crate) | ||||
@@ -790,9 +942,27 @@ or the minor release if the major version is still 0." | |||||
(format "%s" major)))) | (format "%s" major)))) | ||||
(insert (format "%s = \"%s\"" crate semver)))))) | (insert (format "%s = \"%s\"" crate semver)))))) | ||||
(defun my/rust/cargo-toml (&optional dir) | |||||
(path! (locate! "Cargo.toml" dir) "Cargo.toml")) | |||||
(defun my/rust/workspace-root (&optional dir) | |||||
(shell! "%s | jq -r '.workspace_root'" | |||||
(cargo! "metadata --no-deps --format-version 1" dir))) | |||||
(defun cargo! (cmd &optional dir) | |||||
(format "cargo %s --manifest-path \"%s\"" | |||||
cmd | |||||
(my/rust/cargo-toml dir))) | |||||
;; (setq projectile-project-search-path | ;; (setq projectile-project-search-path | ||||
;; '("~/Code")) | ;; '("~/Code")) | ||||
(defun my/projectile-project-ignored-p (root) | |||||
(or (doom-project-ignored-p root) | |||||
(file-in-directory-p root "/opt/ts/fuse/artfs_mounts") | |||||
(file-in-directory-p root "/home/tsdist/vats_deployments"))) | |||||
(setq projectile-ignored-project-function #'my/projectile-project-ignored-p) | |||||
(defun my/projectile-switch-project () | (defun my/projectile-switch-project () | ||||
(interactive) | (interactive) | ||||
;; Prune projects which no longer exist | ;; Prune projects which no longer exist | ||||
@@ -807,6 +977,16 @@ or the minor release if the major version is still 0." | |||||
(setq lsp-headerline-breadcrumb-enable t) | (setq lsp-headerline-breadcrumb-enable t) | ||||
(setq lsp-headerline-breadcrumb-segments '(symbols)) | (setq lsp-headerline-breadcrumb-segments '(symbols)) | ||||
(defun my/lsp-root (lsp--calculate-root session file) | |||||
(or | |||||
(and (ts/repo/p file) | |||||
(pcase (f-ext file t) | |||||
(".rs" (my/rust/workspace-root file)) | |||||
(_ nil))) | |||||
(lsp--calculate-root session file))) | |||||
((advice-add 'lsp--calculate-root :around #'my/lsp-root) | |||||
(defun my/counsel-search () | (defun my/counsel-search () | ||||
(interactive) | (interactive) | ||||
(unless (boundp 'my/kagi-found) | (unless (boundp 'my/kagi-found) | ||||
@@ -847,6 +1027,10 @@ or the minor release if the major version is still 0." | |||||
ignore)) | ignore)) | ||||
(add-to-list 'keycast-substitute-alist `(,event nil)))) | (add-to-list 'keycast-substitute-alist `(,event nil)))) | ||||
(use-package sourcegraph | |||||
:hook (prog-mode . sourcegraph-mode)) | |||||
(setq sourcegraph-url "https://sourcegraph.app.twosigma.com") | |||||
(load! "lisp/emacs-everywhere.el") | (load! "lisp/emacs-everywhere.el") | ||||
(setq emacs-everywhere-paste-command '("xdotool" "key" "--clearmodifiers" "ctrl+v")) | (setq emacs-everywhere-paste-command '("xdotool" "key" "--clearmodifiers" "ctrl+v")) | ||||
(setq emacs-everywhere-frame-parameters | (setq emacs-everywhere-frame-parameters | ||||
@@ -1,10 +1,15 @@ | |||||
# -*- lexical-binding: t -*- | |||||
#+PROPERTY: header-args:emacs-lisp :lexical t | |||||
#+title: Config | #+title: Config | ||||
* Setup | * Setup | ||||
** Lexical Binding | |||||
#+BEGIN_SRC elisp | |||||
;;; -*- lexical-binding: t; -*- | |||||
#+END_SRC | |||||
** Environment Variables | ** Environment Variables | ||||
#+BEGIN_SRC elisp | #+BEGIN_SRC elisp | ||||
(doom-load-envvars-file (concat doom-private-dir "env.el")) | |||||
(doom-load-envvars-file (concat doom-user-dir "env.el")) | |||||
#+END_SRC | #+END_SRC | ||||
** Doom configuration | ** Doom configuration | ||||
#+BEGIN_SRC elisp | #+BEGIN_SRC elisp | ||||
@@ -12,12 +17,6 @@ | |||||
#+END_SRC | #+END_SRC | ||||
* Lisp | * Lisp | ||||
** Hacks | |||||
#+BEGIN_SRC elisp | |||||
(make-variable-buffer-local 'lexical-binding) | |||||
(setq lexical-binding t) | |||||
#+END_SRC | |||||
** Web | ** Web | ||||
#+BEGIN_SRC elisp | #+BEGIN_SRC elisp | ||||
(use-package request | (use-package request | ||||
@@ -78,15 +77,16 @@ returned by `request`." | |||||
("TAB" . "<tab>")))) | ("TAB" . "<tab>")))) | ||||
(my/replace-regexps-in-string str kbd-regex))) | (my/replace-regexps-in-string str kbd-regex))) | ||||
(setq my//kbd-p nil) | |||||
(defun my/kbd!-p () (eq my//kbd-p t)) | |||||
(setq my//vim!-p nil) | |||||
(defun my/vim!-p () (eq my//vim!-p t)) | |||||
(defun kbd! (str) | |||||
(defun vim! (str) | |||||
"Execute the key sequence defined by STR like a VIM macro." | "Execute the key sequence defined by STR like a VIM macro." | ||||
(let ((minibuffer-message-timeout 0)) | (let ((minibuffer-message-timeout 0)) | ||||
(setq my//kbd-p t) | |||||
(execute-kbd-macro (read-kbd-macro (my/kbd-replace str))) | |||||
(setq my//kbd-p nil))) | |||||
(when (not (my/vim!-p)) | |||||
(setq my//vim!-p t) | |||||
(execute-kbd-macro (read-kbd-macro (my/kbd-replace str))) | |||||
(setq my//vim!-p nil)))) | |||||
#+END_SRC | #+END_SRC | ||||
@@ -133,6 +133,81 @@ returned by `request`." | |||||
secret))))) | secret))))) | ||||
,@body)) | ,@body)) | ||||
#+END_SRC | #+END_SRC | ||||
** Two Sigma | |||||
#+BEGIN_SRC elisp | |||||
(defun ts/proxy-on () | |||||
(interactive) | |||||
(setq url-proxy-services | |||||
'(("http" . "127.0.0.1:20001") | |||||
("https" . "127.0.0.1:20001") | |||||
("no_proxy" . "^.*twosigma\\.com")))) | |||||
(defun ts/proxy-off () | |||||
(interactive) | |||||
(setq url-proxy-services nil)) | |||||
#+END_SRC | |||||
#+BEGIN_SRC elisp | |||||
(setq sourcegraph-url "https://sourcegraph.app.twosigma.com") | |||||
(defun ts/sourcegraph-search () | |||||
(interactive) | |||||
(call-interactively #'sourcegraph-search)) | |||||
(defun ts/sourcegraph-browse () | |||||
(interactive) | |||||
(call-interactively #'sourcegraph-open-in-browser)) | |||||
#+END_SRC | |||||
#+BEGIN_SRC elisp | |||||
(setq ts/search-url "https://search.app.twosigma.com/?q=%s") | |||||
(defun ts/search (query) | |||||
(interactive "sQuery: ") | |||||
(browse-url (format ts/search-url query))) | |||||
#+END_SRC | |||||
#+BEGIN_SRC elisp | |||||
(defun ts/repo/root (&optional dir) | |||||
(locate-dominating-file ($cwd dir) ".base_universe")) | |||||
(defun ts/repo/codebase (&optional dir) | |||||
(locate-dominating-file ($cwd dir) ".git")) | |||||
(defun ts/repo/p (&optional dir) | |||||
(when (ts/repo/root dir) t)) | |||||
#+END_SRC | |||||
** Magic functions | |||||
#+BEGIN_SRC elisp | |||||
(defun shell! (fmt &rest args) | |||||
(let* ((cmd (apply #'format (cons fmt args))) | |||||
(cmd (format "%s 2>/dev/null" cmd)) | |||||
(result (shell-command-to-string cmd)) | |||||
(result (replace-regexp-in-string | |||||
"\r?\n$" "" | |||||
result))) | |||||
(if (equal result "") | |||||
nil | |||||
result))) | |||||
#+END_SRC | |||||
#+BEGIN_SRC elisp | |||||
(defun locate! (file &optional dir) | |||||
(locate-dominating-file ($cwd dir) file)) | |||||
#+END_SRC | |||||
#+BEGIN_SRC elisp | |||||
(defun path! (&rest components) | |||||
(apply #'f-join components)) | |||||
#+END_SRC | |||||
** Magic Vars | |||||
#+BEGIN_SRC elisp | |||||
(defun $file () buffer-file-name) | |||||
(defun $cwd (&optional dir) | |||||
(if dir | |||||
dir | |||||
(f-dirname ($file)))) | |||||
#+END_SRC | |||||
* Appearance | * Appearance | ||||
Set a nice theme and font. | Set a nice theme and font. | ||||
#+BEGIN_SRC elisp | #+BEGIN_SRC elisp | ||||
@@ -156,6 +231,24 @@ frame parameter which just landed in the Emacs 29 development branch. | |||||
(setq evil-want-fine-undo t) | (setq evil-want-fine-undo t) | ||||
#+END_SRC | #+END_SRC | ||||
#+BEGIN_SRC elisp | |||||
(defun my/scroll-up () | |||||
(interactive) | |||||
(evil-scroll-line-up 2)) | |||||
(defun my/scroll-down () | |||||
(interactive) | |||||
(evil-scroll-line-down 2)) | |||||
(defun my/scroll-up-bigly () | |||||
(interactive) | |||||
(evil-scroll-line-up 5)) | |||||
(defun my/scroll-down-bigly () | |||||
(interactive) | |||||
(evil-scroll-line-down 5)) | |||||
#+END_SRC | |||||
Auto center the point after jumping. | Auto center the point after jumping. | ||||
#+BEGIN_SRC elisp | #+BEGIN_SRC elisp | ||||
(defmacro my//center-cmd (name &rest body) | (defmacro my//center-cmd (name &rest body) | ||||
@@ -164,9 +257,6 @@ Auto center the point after jumping. | |||||
,@body | ,@body | ||||
(call-interactively #'evil-scroll-line-to-center))) | (call-interactively #'evil-scroll-line-to-center))) | ||||
(my//center-cmd my/scroll-up (evil-scroll-up evil-scroll-count)) | |||||
(my//center-cmd my/scroll-down (evil-scroll-down evil-scroll-count)) | |||||
(my//center-cmd my/jump-forward (better-jumper-jump-forward)) | (my//center-cmd my/jump-forward (better-jumper-jump-forward)) | ||||
(my//center-cmd my/jump-backward (better-jumper-jump-backward)) | (my//center-cmd my/jump-backward (better-jumper-jump-backward)) | ||||
@@ -185,7 +275,11 @@ Auto center the point after jumping. | |||||
#+BEGIN_SRC elisp | #+BEGIN_SRC elisp | ||||
(defun my/duplicate-and-comment-line () | (defun my/duplicate-and-comment-line () | ||||
(interactive) | (interactive) | ||||
(kbd! "yyp k gcc j")) | |||||
(vim! "yyp k gcc j")) | |||||
#+END_SRC | |||||
#+BEGIN_SRC elisp | |||||
(setq search-invisible t) | |||||
#+END_SRC | #+END_SRC | ||||
*** Line Numbers | *** Line Numbers | ||||
@@ -230,11 +324,24 @@ Use =lisp-interaction-mode= by default for the scratch buffer. | |||||
#+BEGIN_SRC elisp | #+BEGIN_SRC elisp | ||||
(setq doom-scratch-initial-major-mode 'lisp-interaction-mode) | (setq doom-scratch-initial-major-mode 'lisp-interaction-mode) | ||||
#+END_SRC | #+END_SRC | ||||
** Abbreviations | |||||
#+BEGIN_SRC elisp | |||||
(use-package abbrev-mode | |||||
:hook text-mode) | |||||
(setq +abbrev-file (concat doom-user-dir "abbrevs.el")) | |||||
(setq abbrev-file-name +abbrev-file) | |||||
#+END_SRC | |||||
* Keybinds | * Keybinds | ||||
** Unmaps | ** Unmaps | ||||
Unmap a bunch of the default keybindings. | Unmap a bunch of the default keybindings. | ||||
#+BEGIN_SRC elisp | #+BEGIN_SRC elisp | ||||
#+END_SRC | |||||
#+BEGIN_SRC elisp | |||||
(map! :leader | (map! :leader | ||||
":" nil | |||||
"b" nil | "b" nil | ||||
"f" nil | "f" nil | ||||
"h" nil | "h" nil | ||||
@@ -272,7 +379,7 @@ Unmap a bunch of the default keybindings. | |||||
:desc "Apply code action" :ni "C-/" #'lsp-execute-code-action | :desc "Apply code action" :ni "C-/" #'lsp-execute-code-action | ||||
:desc "Show definitions" :ni "C-." #'+lookup/definition | :desc "Show definitions" :ni "C-." #'+lookup/definition | ||||
:desc "Show references" :ni "C->" #'my/lookup/references | |||||
:desc "Show references" :ni "C->" #'my/lsp/lookup-references | |||||
:desc "Jump backward" :ni "C-," #'better-jumper-jump-backward | :desc "Jump backward" :ni "C-," #'better-jumper-jump-backward | ||||
:desc "Jump backward" :ni "C-<" #'better-jumper-jump-forward) | :desc "Jump backward" :ni "C-<" #'better-jumper-jump-forward) | ||||
@@ -298,10 +405,10 @@ Unmap a bunch of the default keybindings. | |||||
*** Evil | *** Evil | ||||
#+BEGIN_SRC elisp | #+BEGIN_SRC elisp | ||||
(map! | (map! | ||||
:desc "Scroll page up" :ni "C-S-k" #'my/scroll-up | |||||
:desc "Scroll page down" :ni "C-S-j" #'my/scroll-down | |||||
:desc "Scroll line up" :ni "C-k" #'evil-scroll-line-up | |||||
:desc "Scroll line down" :ni "C-j" #'evil-scroll-line-down | |||||
:desc "Scroll up" :ni "C-k" #'my/scroll-up | |||||
:desc "Scroll down" :ni "C-j" #'my/scroll-down | |||||
:desc "Scroll up bigly" :ni "C-S-k" #'my/scroll-up-bigly | |||||
:desc "Scroll down bigly" :ni "C-S-j" #'my/scroll-down-bigly | |||||
:desc "Jump forward" :n "C-o" #'my/jump-forward | :desc "Jump forward" :n "C-o" #'my/jump-forward | ||||
:desc "Jump backward" :n "C-o" #'my/jump-backward | :desc "Jump backward" :n "C-o" #'my/jump-backward | ||||
@@ -373,9 +480,35 @@ Unmap a bunch of the default keybindings. | |||||
:desc "ibuffer" "i" #'ibuffer | :desc "ibuffer" "i" #'ibuffer | ||||
:desc "Kill buffer" "d" #'kill-current-buffer | :desc "Kill buffer" "d" #'kill-current-buffer | ||||
:desc "Kill all buffers" "D" #'doom/kill-all-buffers) | |||||
:desc "Kill all buffers" "D" #'doom/kill-all-buffers | |||||
:desc "Rename buffer" "r" #'my/rename-buffer) | |||||
#+END_SRC | |||||
#+BEGIN_SRC elisp | |||||
(defun my/rename-buffer (name) | |||||
(interactive (list (read-string "Rename: " (buffer-name)))) | |||||
(rename-buffer name)) | |||||
#+END_SRC | #+END_SRC | ||||
*** c: Code | |||||
#+BEGIN_SRC elisp | |||||
(map! :leader | |||||
:prefix ("c" . "code") | |||||
:desc "Format region/buffer" "f" #'+format/region-or-buffer | |||||
:desc "Format imports" "F" #'lsp-organize-imports | |||||
:desc "Rename symbol" "r" #'lsp-rename | |||||
:desc "Show errors list" "x" #'+default/diagnostics | |||||
:desc "Show errors tree" "X" #'lsp-treemacs-errors-list | |||||
:desc "Show symbols tree" "s" #'lsp-treemacs-symbols | |||||
:desc "Visit lens" "l" #'lsp-avy-lens | |||||
:desc "Restart LSP" "q" #'lsp-restart-workspace) | |||||
#+END_SRC | |||||
*** f: Files | *** f: Files | ||||
#+BEGIN_SRC elisp | #+BEGIN_SRC elisp | ||||
(map! :leader | (map! :leader | ||||
@@ -399,34 +532,39 @@ Unmap a bunch of the default keybindings. | |||||
:desc "Open scratch" "x" #'doom/open-scratch-buffer) | :desc "Open scratch" "x" #'doom/open-scratch-buffer) | ||||
#+END_SRC | #+END_SRC | ||||
**** s: Snippets | |||||
**** a: Abbrevs | |||||
#+BEGIN_SRC emacs-lisp | #+BEGIN_SRC emacs-lisp | ||||
(map! :leader | (map! :leader | ||||
:prefix ("f s" . "snippets") | |||||
:desc "Find snippet" "f" #'my/yas-find-snippet | |||||
:desc "New snippet" "n" #'yas/new-snippet | |||||
:desc "Edit snippet" "e" #'my/yas-edit-snippet | |||||
:prefix ("f a" . "abbrevs") | |||||
:desc "Edit abbrevs" "e" #'my/abbrev-edit | |||||
:desc "Reload abbrevs" "r" #'my/abbrev-reload | |||||
:desc "Describe snippets" "d" #'yas/describe-tables | |||||
:desc "Reload snippets" "r" #'yas/reload-all | |||||
:desc "Browse docs" "?" #'my/yas-browse-docs) | |||||
:desc "Add global abbrev" "a" #'my/abbrev-add-global | |||||
:desc "Add mode abbrev" "m" #'my/abbrev-add-mode) | |||||
#+END_SRC | #+END_SRC | ||||
Add a command to open the YASnippet docs. | |||||
#+BEGIN_SRC elisp | #+BEGIN_SRC elisp | ||||
(defun my/yas-browse-docs () | |||||
(defun my/abbrev-edit () | |||||
(interactive) | (interactive) | ||||
(browse-url "https://joaotavora.github.io/yasnippet")) | |||||
#+END_SRC | |||||
(find-file-other-window +abbrev-file)) | |||||
#+BEGIN_SRC elisp | |||||
(defun my/yas-edit-snippet () | |||||
(defun my/abbrev-reload () | |||||
(interactive) | (interactive) | ||||
(call-interactively #'yas/visit-snippet-file)) | |||||
(read-abbrev-file +abbrev-file)) | |||||
(defun my/yas-find-snippet () | |||||
(defun my/abbrev-save () | |||||
(interactive) | (interactive) | ||||
(counsel-find-file nil +snippets-dir)) | |||||
(write-abbrev-file +abbrev-file)) | |||||
(defun my/abbrev-add-global () | |||||
(interactive) | |||||
(call-interactively #'inverse-add-global-abbrev) | |||||
(my/abbrev-save)) | |||||
(defun my/abbrev-add-mode () | |||||
(interactive) | |||||
(call-interactively #'inverse-add-mode-abbrev) | |||||
(my/abbrev-save)) | |||||
#+END_SRC | #+END_SRC | ||||
**** e: Emacs Files | **** e: Emacs Files | ||||
@@ -445,16 +583,16 @@ Add a command to open the YASnippet docs. | |||||
#+BEGIN_SRC elisp | #+BEGIN_SRC elisp | ||||
(defun my/edit-config () | (defun my/edit-config () | ||||
(interactive) | (interactive) | ||||
(find-file (concat doom-private-dir "config.org"))) | |||||
(find-file (concat doom-user-dir "config.org"))) | |||||
(defun my/edit-packages () | (defun my/edit-packages () | ||||
(interactive) | (interactive) | ||||
(find-file (concat doom-private-dir "packages.el"))) | |||||
(find-file (concat doom-user-dir "packages.el"))) | |||||
(defun my/edit-init () | (defun my/edit-init () | ||||
(interactive) | (interactive) | ||||
(find-file (concat doom-private-dir "init.el"))) | |||||
(find-file (concat doom-user-dir "init.el"))) | |||||
(defun my/edit-env () | (defun my/edit-env () | ||||
(interactive) | (interactive) | ||||
(find-file (concat doom-private-dir "env.el"))) | |||||
(find-file (concat doom-user-dir "env.el"))) | |||||
#+END_SRC | #+END_SRC | ||||
Define a derived mode for editing the literate config so we can specify some | Define a derived mode for editing the literate config so we can specify some | ||||
@@ -464,6 +602,36 @@ keybindings specific to =config.org=. | |||||
(add-to-list 'auto-mode-alist '("config\\.org" . org-config-mode)) | (add-to-list 'auto-mode-alist '("config\\.org" . org-config-mode)) | ||||
#+END_SRC | #+END_SRC | ||||
**** s: Snippets | |||||
#+BEGIN_SRC emacs-lisp | |||||
(map! :leader | |||||
:prefix ("f s" . "snippets") | |||||
:desc "Find snippet" "f" #'my/yas-find-snippet | |||||
:desc "New snippet" "n" #'yas/new-snippet | |||||
:desc "Edit snippet" "e" #'my/yas-edit-snippet | |||||
:desc "Describe snippets" "d" #'yas/describe-tables | |||||
:desc "Reload snippets" "r" #'yas/reload-all | |||||
:desc "Browse docs" "?" #'my/yas-browse-docs) | |||||
#+END_SRC | |||||
Add a command to open the YASnippet docs. | |||||
#+BEGIN_SRC elisp | |||||
(defun my/yas-browse-docs () | |||||
(interactive) | |||||
(browse-url "https://joaotavora.github.io/yasnippet")) | |||||
#+END_SRC | |||||
#+BEGIN_SRC elisp | |||||
(defun my/yas-edit-snippet () | |||||
(interactive) | |||||
(call-interactively #'yas/visit-snippet-file)) | |||||
(defun my/yas-find-snippet () | |||||
(interactive) | |||||
(counsel-find-file nil +snippets-dir)) | |||||
#+END_SRC | |||||
*** h: Help | *** h: Help | ||||
#+BEGIN_SRC elisp | #+BEGIN_SRC elisp | ||||
(map! :leader | (map! :leader | ||||
@@ -551,7 +719,18 @@ keybindings specific to =config.org=. | |||||
:desc "Doom package configuration" "p" #'doom/help-package-config | :desc "Doom package configuration" "p" #'doom/help-package-config | ||||
:desc "Doom sandbox" "x" #'doom/sandbox) | :desc "Doom sandbox" "x" #'doom/sandbox) | ||||
#+END_SRC | #+END_SRC | ||||
*** l: Ligma | |||||
#+BEGIN_SRC elisp | |||||
(map! :leader | |||||
:prefix ("l" . "ligma") | |||||
:desc "Search" "s" #'ts/search | |||||
:desc "Sourcegraph search" "g" #'ts/sourcegraph-search | |||||
:desc "Sourcegraph browse" "G" #'ts/sourcegraph-browse) | |||||
#+END_SRC | |||||
*** TODO o: Open | |||||
*** p: Projects | *** p: Projects | ||||
#+BEGIN_SRC elisp | #+BEGIN_SRC elisp | ||||
(map! :leader | (map! :leader | ||||
@@ -605,8 +784,10 @@ keybindings specific to =config.org=. | |||||
:desc "Go right" "l" #'evil-window-right | :desc "Go right" "l" #'evil-window-right | ||||
:desc "Go other" "o" #'other-window | :desc "Go other" "o" #'other-window | ||||
;; Layout | ;; Layout | ||||
:desc "Rotate up" "K" #'evil-window-rotate-upwards | |||||
:desc "Rotate down" "J" #'evil-window-rotate-downwards | |||||
:desc "Move left" "H" #'+evil/window-move-left | |||||
:desc "Move down" "J" #'+evil/window-move-down | |||||
:desc "Move up" "K" #'+evil/window-move-up | |||||
:desc "Move right" "L" #'+evil/window-move-right | |||||
;; Splits | ;; Splits | ||||
:desc "VSplit" "=" #'+evil/window-vsplit-and-follow | :desc "VSplit" "=" #'+evil/window-vsplit-and-follow | ||||
:desc "HSplit" "-" #'+evil/window-split-and-follow | :desc "HSplit" "-" #'+evil/window-split-and-follow | ||||
@@ -615,7 +796,8 @@ keybindings specific to =config.org=. | |||||
:desc "Undo" "u" #'winner-undo | :desc "Undo" "u" #'winner-undo | ||||
:desc "Redo" "U" #'winner-redo | :desc "Redo" "U" #'winner-redo | ||||
;; Misc | ;; Misc | ||||
:desc "Resize" "r" #'my/hydra-window-resize/body | |||||
:desc "Resize..." "r" #'my/hydra-window-resize/body | |||||
:desc "Rotate..." "R" #'my/hydra-window-rotate/body | |||||
:desc "Balance" "b" #'balance-windows | :desc "Balance" "b" #'balance-windows | ||||
;; Management | ;; Management | ||||
:desc "Kill window" "d" #'+workspace/close-window-or-workspace) | :desc "Kill window" "d" #'+workspace/close-window-or-workspace) | ||||
@@ -647,23 +829,18 @@ keybindings specific to =config.org=. | |||||
("l" my/window-increase-width "++Width") | ("l" my/window-increase-width "++Width") | ||||
("ESC" nil "Quit" :color blue)) | ("ESC" nil "Quit" :color blue)) | ||||
#+END_SRC | #+END_SRC | ||||
*** c: Code | |||||
#+BEGIN_SRC elisp | |||||
(map! :leader | |||||
:prefix ("c" . "code") | |||||
:desc "Format region/buffer" "f" #'+format/region-or-buffer | |||||
:desc "Format imports" "F" #'lsp-organize-imports | |||||
:desc "Rename symbol" "r" #'lsp-rename | |||||
:desc "Show errors list" "x" #'+default/diagnostics | |||||
:desc "Show errors tree" "X" #'lsp-treemacs-errors-list | |||||
:desc "Show symbols tree" "s" #'lsp-treemacs-symbols | |||||
:desc "Visit lens" "l" #'lsp-avy-lens | |||||
:desc "Restart LSP" "q" #'lsp-restart-workspace) | |||||
#+BEGIN_SRC elisp | |||||
(defhydra my/hydra-window-rotate () | |||||
"Rotate window" | |||||
("h" +evil/window-move-left "Move left") | |||||
("j" +evil/window-move-down "Move down") | |||||
("k" +evil/window-move-up "Move up") | |||||
("l" +evil/window-move-right "Move right") | |||||
("H" evil-window-move-far-left "Move far left") | |||||
("J" evil-window-rotate-downwards "Rotate Down") | |||||
("K" evil-window-rotate-upwards "Rotate Up") | |||||
("L" evil-window-move-far-right "Move far right")) | |||||
#+END_SRC | #+END_SRC | ||||
** Local Leader | ** Local Leader | ||||
@@ -681,38 +858,40 @@ keybindings specific to =config.org=. | |||||
#+END_SRC | #+END_SRC | ||||
*** Rust | *** Rust | ||||
#+BEGIN_SRC elisp | #+BEGIN_SRC elisp | ||||
(map! :map rustic-mode-map | |||||
:localleader | |||||
"b" nil | |||||
"t" nil) | |||||
;; (map! :map rustic-mode-map | |||||
;; :localleader | |||||
;; "b" nil | |||||
;; "t" nil) | |||||
(map! :map rustic-mode-map | |||||
:localleader | |||||
:desc "Edit Cargo.toml" "t" #'my/rust/edit-cargo-toml) | |||||
;; (map! :map rustic-mode-map | |||||
;; :localleader | |||||
;; :desc "Edit Cargo.toml" "t" #'my/rust/edit-cargo-toml) | |||||
(map! :map rustic-mode-map | |||||
:leader | |||||
:prefix ("c" . "code") | |||||
:desc "Expand macro" "m" #'lsp-rust-analyzer-expand-macro | |||||
:desc "Open docs" "h" #'lsp-rust-analyzer-open-external-docs) | |||||
;; (map! :map rustic-mode-map | |||||
;; :leader | |||||
;; :prefix ("c" . "code") | |||||
;; :desc "Expand macro" "m" #'lsp-rust-analyzer-expand-macro | |||||
;; :desc "Open docs" "h" #'lsp-rust-analyzer-open-external-docs) | |||||
(map! :map rustic-mode-map | |||||
:prefix ("cb" . "build") | |||||
;; (map! :map rustic-mode-map | |||||
;; :localleader | |||||
;; :prefix ("b" . "build") | |||||
:desc "Build" "b" #'rustic-cargo-check | |||||
:desc "Check" "c" #'rustic-cargo-check | |||||
;; :desc "Build" "b" #'rustic-cargo-check | |||||
;; :desc "Check" "c" #'rustic-cargo-check | |||||
:desc "Debug" "d" #'my/rust/dap-hydra/body | |||||
:desc "Run" "r" #'rustic-cargo-run | |||||
;; :desc "Debug" "d" #'my/rust/dap-hydra/body | |||||
;; :desc "Run" "r" #'rustic-cargo-run | |||||
:desc "Bench" "B" #'rustic-cargo-bench | |||||
:desc "Test current" "t" #'rustic-cargo-current-test | |||||
:desc "Test all" "T" #'rustic-cargo-test) | |||||
;; :desc "Bench" "B" #'rustic-cargo-bench | |||||
;; :desc "Test current" "t" #'rustic-cargo-current-test | |||||
;; :desc "Test all" "T" #'rustic-cargo-test) | |||||
(map! :map rustic-mode-map | (map! :map rustic-mode-map | ||||
:desc "Pluralize import" "," #'my/rust/import-pluralize | :desc "Pluralize import" "," #'my/rust/import-pluralize | ||||
:desc "Singularize import" "<backspace>" #'my/rust/import-singularize | :desc "Singularize import" "<backspace>" #'my/rust/import-singularize | ||||
:desc "Singularize import" "C-<backspace>" #'my/rust/import-c-singularize) | |||||
:desc "Singularize import" "C-<backspace>" #'my/rust/import-c-singularize | |||||
:desc "Singularize import" "C-<delete>" #'my/rust/import-rev-singularize) | |||||
#+END_SRC | #+END_SRC | ||||
**** Debugging | **** Debugging | ||||
@@ -805,6 +984,8 @@ _Q_: Disconnect _sd_: Down stack frame _bh_: Set hit count | |||||
#+END_SRC | #+END_SRC | ||||
*** Editing | *** Editing | ||||
When editing a list of "use" imports, automatically add and remove braces when typing or removing commas | |||||
#+BEGIN_SRC elisp | #+BEGIN_SRC elisp | ||||
(rx-let ((crate (or alphanumeric "_" "*"))) | (rx-let ((crate (or alphanumeric "_" "*"))) | ||||
(setq my//rust/import-singular-rx | (setq my//rust/import-singular-rx | ||||
@@ -814,41 +995,53 @@ _Q_: Disconnect _sd_: Down stack frame _bh_: Set hit count | |||||
(+ crate) | (+ crate) | ||||
(? ";") line-end)) | (? ";") line-end)) | ||||
(setq my//rust/import-plural-rx | (setq my//rust/import-plural-rx | ||||
;; use foo::bar::baz::{qux::quo, }; | |||||
;; use foo::bar::baz::{qux::quo, }; | |||||
(rx "use " | (rx "use " | ||||
(+ (+ crate) "::") | (+ (+ crate) "::") | ||||
"{" (* (+ crate) "::") (+ crate) "," (* whitespace) "}" | "{" (* (+ crate) "::") (+ crate) "," (* whitespace) "}" | ||||
(? ";") line-end)) | |||||
(setq my//rust/import-plural-rev-rx | |||||
;; use foo::bar::baz::{, qux::quo}; | |||||
(rx "use " | |||||
(+ (+ crate) "::") | |||||
"{," (* whitespace) (* (+ crate) "::") (+ crate) "}" | |||||
(? ";") line-end))) | (? ";") line-end))) | ||||
(defun my/rust/import-pluralize () | (defun my/rust/import-pluralize () | ||||
"Convert a singular import into a brace-wrapped plural import." | "Convert a singular import into a brace-wrapped plural import." | ||||
(interactive) | (interactive) | ||||
(if (and | (if (and | ||||
(not (my/kbd!-p)) | |||||
(my/insert-mode-p) | (my/insert-mode-p) | ||||
(my/line-match-p my//rust/import-singular-rx)) | (my/line-match-p my//rust/import-singular-rx)) | ||||
(kbd! "ESC vb S} f} i,") | |||||
(vim! "ESC vb S} f} i,") | |||||
(insert ","))) | (insert ","))) | ||||
(defun my/rust/import-singularize () | (defun my/rust/import-singularize () | ||||
"Convert a brace-wrapped plural import into a singular import." | "Convert a brace-wrapped plural import into a singular import." | ||||
(interactive) | (interactive) | ||||
(if (and | (if (and | ||||
(not (my/kbd!-p)) | |||||
(my/insert-mode-p) | (my/insert-mode-p) | ||||
(my/line-match-p my//rust/import-plural-rx)) | (my/line-match-p my//rust/import-plural-rx)) | ||||
(kbd! "ESC l dF, ds} $i") | |||||
(vim! "ESC l dF, ds} $i") | |||||
(evil-delete-backward-char-and-join 1))) | (evil-delete-backward-char-and-join 1))) | ||||
(defun my/rust/import-c-singularize () | (defun my/rust/import-c-singularize () | ||||
"Convert a brace-wrapped plural import into a singular import." | "Convert a brace-wrapped plural import into a singular import." | ||||
(interactive) | (interactive) | ||||
(if (and | (if (and | ||||
(not (my/kbd!-p)) | |||||
(my/insert-mode-p) | (my/insert-mode-p) | ||||
(my/line-match-p my//rust/import-plural-rx)) | (my/line-match-p my//rust/import-plural-rx)) | ||||
(kbd! "ESC l dF, ds} $i") | |||||
(vim! "ESC l dF, ds} $i") | |||||
(backward-kill-word 1))) | (backward-kill-word 1))) | ||||
(defun my/rust/import-rev-singularize () | |||||
"Convert a brace-wrapped plural import into a singular import." | |||||
(interactive) | |||||
(if (and | |||||
(my/insert-mode-p) | |||||
(my/line-match-p my//rust/import-plural-rev-rx)) | |||||
(vim! "ESC ds} dw $i") | |||||
(kill-word 1))) | |||||
#+END_SRC | #+END_SRC | ||||
*** Debugging | *** Debugging | ||||
@@ -942,11 +1135,11 @@ Define a wrapper function for visiting the closest Cargo.toml in a new window. | |||||
#+BEGIN_SRC elisp | #+BEGIN_SRC elisp | ||||
(defun my/rust/edit-cargo-toml () | (defun my/rust/edit-cargo-toml () | ||||
(interactive) | (interactive) | ||||
(lsp-rust-analyzer-open-cargo-toml t)) | |||||
(lsp-rust-analyzer-open-cargo-toml)) | |||||
#+END_SRC | #+END_SRC | ||||
Define a helper for pulling the latest versions of crates from crates.io | Define a helper for pulling the latest versions of crates from crates.io | ||||
#+BEGIN_SRC elisp | |||||
#+BEGIN_SRC elisp :lexical t | |||||
(defun my/rust/get-latest-crate-version (crate callback) | (defun my/rust/get-latest-crate-version (crate callback) | ||||
(request! (format "https://crates.io/api/v1/crates/%s/versions" crate) | (request! (format "https://crates.io/api/v1/crates/%s/versions" crate) | ||||
(:type "GET" :parser 'json-read) | (:type "GET" :parser 'json-read) | ||||
@@ -983,16 +1176,37 @@ or the minor release if the major version is still 0." | |||||
(format "%s" major)))) | (format "%s" major)))) | ||||
(insert (format "%s = \"%s\"" crate semver)))))) | (insert (format "%s = \"%s\"" crate semver)))))) | ||||
#+END_SRC | #+END_SRC | ||||
*** Lisp | |||||
#+BEGIN_SRC elisp | |||||
(defun my/rust/cargo-toml (&optional dir) | |||||
(path! (locate! "Cargo.toml" dir) "Cargo.toml")) | |||||
(defun my/rust/workspace-root (&optional dir) | |||||
(shell! "%s | jq -r '.workspace_root'" | |||||
(cargo! "metadata --no-deps --format-version 1" dir))) | |||||
(defun cargo! (cmd &optional dir) | |||||
(format "cargo %s --manifest-path \"%s\"" | |||||
cmd | |||||
(my/rust/cargo-toml dir))) | |||||
#+END_SRC | |||||
** Go | ** Go | ||||
*** Debugging | *** Debugging | ||||
Setup: run =M-x dap-go-setup= | Setup: run =M-x dap-go-setup= | ||||
* Tools | * Tools | ||||
** Org | |||||
** Projectile | ** Projectile | ||||
#+BEGIN_SRC elisp | #+BEGIN_SRC elisp | ||||
;; (setq projectile-project-search-path | ;; (setq projectile-project-search-path | ||||
;; '("~/Code")) | ;; '("~/Code")) | ||||
(defun my/projectile-project-ignored-p (root) | |||||
(or (doom-project-ignored-p root) | |||||
(file-in-directory-p root "/opt/ts/fuse/artfs_mounts") | |||||
(file-in-directory-p root "/home/tsdist/vats_deployments"))) | |||||
(setq projectile-ignored-project-function #'my/projectile-project-ignored-p) | |||||
(defun my/projectile-switch-project () | (defun my/projectile-switch-project () | ||||
(interactive) | (interactive) | ||||
;; Prune projects which no longer exist | ;; Prune projects which no longer exist | ||||
@@ -1011,6 +1225,18 @@ Setup: run =M-x dap-go-setup= | |||||
(setq lsp-headerline-breadcrumb-segments '(symbols)) | (setq lsp-headerline-breadcrumb-segments '(symbols)) | ||||
#+END_SRC | #+END_SRC | ||||
#+BEGIN_SRC elisp | |||||
(defun my/lsp-root (lsp--calculate-root session file) | |||||
(or | |||||
(and (ts/repo/p file) | |||||
(pcase (f-ext file t) | |||||
(".rs" (my/rust/workspace-root file)) | |||||
(_ nil))) | |||||
(lsp--calculate-root session file))) | |||||
((advice-add 'lsp--calculate-root :around #'my/lsp-root) | |||||
#+END_SRC | |||||
** Counsel Search | ** Counsel Search | ||||
#+BEGIN_SRC elisp | #+BEGIN_SRC elisp | ||||
(defun my/counsel-search () | (defun my/counsel-search () | ||||
@@ -1056,6 +1282,13 @@ Setup: run =M-x dap-go-setup= | |||||
ignore)) | ignore)) | ||||
(add-to-list 'keycast-substitute-alist `(,event nil)))) | (add-to-list 'keycast-substitute-alist `(,event nil)))) | ||||
#+END_SRC | #+END_SRC | ||||
** SourceGraph | |||||
#+BEGIN_SRC elisp | |||||
(use-package sourcegraph | |||||
:hook (prog-mode . sourcegraph-mode)) | |||||
(setq sourcegraph-url "https://sourcegraph.app.twosigma.com") | |||||
#+END_SRC | |||||
** Rmsbolt | |||||
* Apps | * Apps | ||||
** Emacs Everywhere | ** Emacs Everywhere | ||||
@@ -59,7 +59,15 @@ | |||||
;; Mode for showing which keys are being pressed on the modeline | ;; Mode for showing which keys are being pressed on the modeline | ||||
(package! keycast) | (package! keycast) | ||||
;; GitHub Copilot for Emacs | |||||
;; GitHub Copilot for emacs | |||||
(package! copilot | (package! copilot | ||||
:recipe (:host github :repo "zerolfx/copilot.el" | :recipe (:host github :repo "zerolfx/copilot.el" | ||||
:files ("dist" "copilot.el"))) | :files ("dist" "copilot.el"))) | ||||
;; SourceGraph integration | |||||
(package! sourcegraph | |||||
:recipe (:host github :repo "danielmartin/emacs-sourcegraph" | |||||
:files ("sourcegraph.el"))) | |||||
;; Like godbolt for emacs | |||||
(package! rmsbolt) |