Linux install and configuration management utilities
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

config.org 39KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  1. #+PROPERTY: header-args:emacs-lisp :lexical t
  2. #+title: Config
  3. * Setup
  4. ** Lexical Binding
  5. #+BEGIN_SRC elisp
  6. ;;; -*- lexical-binding: t; -*-
  7. #+END_SRC
  8. ** Environment Variables
  9. #+BEGIN_SRC elisp
  10. (doom-load-envvars-file (concat doom-user-dir "env.el"))
  11. #+END_SRC
  12. ** Doom configuration
  13. #+BEGIN_SRC elisp
  14. (setq doom-modeline-major-mode-icon t)
  15. #+END_SRC
  16. * Lisp
  17. ** Web
  18. #+BEGIN_SRC elisp
  19. (use-package request
  20. :commands request)
  21. #+END_SRC
  22. #+BEGIN_SRC elisp
  23. (defmacro request! (url plist success &optional error)
  24. "Makes an HTTP request with `request`, running SUCCESS on success, and
  25. ERROR on error if specified.
  26. Any arguments of LAMBDA are bound to the corresponding plist keys
  27. returned by `request`."
  28. (let ((handler (lambda (fn)
  29. ;; Wraps a lambda in `cl-function`,
  30. ;; and converts args (foo) into (&key foo &allow-other-keys)
  31. `(cl-function
  32. (lambda
  33. ,(append
  34. (mapcan (lambda (arg) `(&key ,arg))
  35. (cadr fn))
  36. '(&allow-other-keys))
  37. ,@(cddr fn))))))
  38. `(request ,url
  39. ,@plist
  40. :success ,(funcall handler success)
  41. ,@(if error `(:error ,(funcall handler error))))))
  42. #+END_SRC
  43. ** Editing
  44. #+BEGIN_SRC elisp
  45. (defun my/line ()
  46. (buffer-substring-no-properties
  47. (line-beginning-position)
  48. (line-end-position)))
  49. (defun my/line-match-p (regexp)
  50. (string-match-p regexp (my/line)))
  51. #+END_SRC
  52. #+BEGIN_SRC elisp
  53. (defun my/insert-mode-p ()
  54. (eq evil-state 'insert))
  55. (defun my/normal-mode-p ()
  56. (eq evil-state 'normal))
  57. #+END_SRC
  58. ** Keybindings
  59. #+BEGIN_SRC elisp
  60. (defun my/kbd-replace (str)
  61. "Convert STR into a keyboard macro string by replacing terminal key sequences with GUI keycodes."
  62. (let ((kbd-regex '(("ESC" . "<escape>")
  63. ("DEL" . "<delete>" )
  64. ("BS" . "<backspace>")
  65. ("RET" . "<return>")
  66. ("SPC" . "<SPC>")
  67. ("TAB" . "<tab>"))))
  68. (my/replace-regexps-in-string str kbd-regex)))
  69. (setq my//vim!-p nil)
  70. (defun my/vim!-p () (eq my//vim!-p t))
  71. (defun vim! (str)
  72. "Execute the key sequence defined by STR like a VIM macro."
  73. (let ((minibuffer-message-timeout 0))
  74. (when (not (my/vim!-p))
  75. (setq my//vim!-p t)
  76. (execute-kbd-macro (read-kbd-macro (my/kbd-replace str)))
  77. (setq my//vim!-p nil))))
  78. #+END_SRC
  79. #+BEGIN_SRC elisp
  80. (defun my/buffer-local-set-key (key fn)
  81. (let ((mode (intern (format "%s-local-mode" (buffer-name))))
  82. (map (intern (format "%s-local-mode-map" (buffer-name)))))
  83. (unless (boundp map)
  84. (set map (make-sparse-keymap))
  85. (evil-make-overriding-map map 'normal))
  86. (eval
  87. `(define-minor-mode ,mode
  88. "A minor mode for buffer-local keybinds."
  89. :keymap ,map))
  90. (eval
  91. `(define-key ,map ,key #',fn))
  92. (funcall mode t)))
  93. #+END_SRC
  94. ** Regex
  95. #+BEGIN_SRC elisp
  96. (defun my/replace-regexps-in-string (str regexps)
  97. "Replace all pairs of (regex . replacement) defined by REGEXPS in STR."
  98. (if (null regexps)
  99. str
  100. (my/replace-regexps-in-string
  101. (replace-regexp-in-string (caar regexps) (cdar regexps) str t)
  102. (cdr regexps))))
  103. #+END_SRC
  104. ** Auth
  105. #+BEGIN_SRC elisp
  106. (setq auth-sources '("~/.authinfo.gpg"))
  107. (use-package auth-source :commands auth-source-search)
  108. (defmacro my/with-credential (query name &rest body)
  109. "Evaluates BODY with NAME bound as the secret from AUTH-SOURCES matching criteria QUERY."
  110. `
  111. (let* ((entry (nth 0 (auth-source-search ,@query)))
  112. (,name (when entry
  113. (let ((secret (plist-get entry :secret)))
  114. (if (functionp secret)
  115. (funcall secret)
  116. secret)))))
  117. ,@body))
  118. #+END_SRC
  119. ** Two Sigma
  120. #+BEGIN_SRC elisp
  121. (defun ts/proxy-on ()
  122. (interactive)
  123. (setq url-proxy-services
  124. '(("http" . "127.0.0.1:20001")
  125. ("https" . "127.0.0.1:20001")
  126. ("no_proxy" . "^.*twosigma\\.com"))))
  127. (defun ts/proxy-off ()
  128. (interactive)
  129. (setq url-proxy-services nil))
  130. #+END_SRC
  131. #+BEGIN_SRC elisp
  132. (setq sourcegraph-url "https://sourcegraph.app.twosigma.com")
  133. (defun ts/sourcegraph-search ()
  134. (interactive)
  135. (call-interactively #'sourcegraph-search))
  136. (defun ts/sourcegraph-browse ()
  137. (interactive)
  138. (call-interactively #'sourcegraph-open-in-browser))
  139. #+END_SRC
  140. #+BEGIN_SRC elisp
  141. (setq ts/search-url "https://search.app.twosigma.com/?q=%s")
  142. (defun ts/search (query)
  143. (interactive "sQuery: ")
  144. (browse-url (format ts/search-url query)))
  145. #+END_SRC
  146. #+BEGIN_SRC elisp
  147. (defun ts/repo/root (&optional dir)
  148. (locate-dominating-file ($cwd dir) ".base_universe"))
  149. (defun ts/repo/codebase (&optional dir)
  150. (locate-dominating-file ($cwd dir) ".git"))
  151. (defun ts/repo/p (&optional dir)
  152. (when (ts/repo/root dir) t))
  153. #+END_SRC
  154. ** Magic functions
  155. #+BEGIN_SRC elisp
  156. (defun shell! (fmt &rest args)
  157. (let* ((cmd (apply #'format (cons fmt args)))
  158. (cmd (format "%s 2>/dev/null" cmd))
  159. (result (shell-command-to-string cmd))
  160. (result (replace-regexp-in-string
  161. "\r?\n$" ""
  162. result)))
  163. (if (equal result "")
  164. nil
  165. result)))
  166. #+END_SRC
  167. #+BEGIN_SRC elisp
  168. (defun locate! (file &optional dir)
  169. (locate-dominating-file ($cwd dir) file))
  170. #+END_SRC
  171. #+BEGIN_SRC elisp
  172. (defun path! (&rest components)
  173. (apply #'f-join components))
  174. #+END_SRC
  175. ** Magic Vars
  176. #+BEGIN_SRC elisp
  177. (defun $file () buffer-file-name)
  178. (defun $cwd (&optional dir)
  179. (if dir
  180. dir
  181. (f-dirname ($file))))
  182. #+END_SRC
  183. * Appearance
  184. Set a nice theme and font.
  185. #+BEGIN_SRC elisp
  186. (setq doom-theme 'doom-catppuccin)
  187. (setq doom-font (font-spec :family "monospace" :size 13)
  188. doom-big-font (font-spec :family "monospace" :size 13)
  189. doom-variable-pitch-font (font-spec :family "sans-serif" :size 13))
  190. #+END_SRC
  191. Sprinkle in a little background transparency. Instead of making the entire frame
  192. transparent (including the text) with =alpha=, we use the =alpha-background=
  193. frame parameter which just landed in the Emacs 29 development branch.
  194. #+BEGIN_SRC elisp
  195. (set-frame-parameter (selected-frame) 'alpha-background 85)
  196. (add-to-list 'default-frame-alist '(alpha-background . 85))
  197. #+END_SRC
  198. * Editing
  199. ** Evil
  200. #+BEGIN_SRC elisp
  201. (setq evil-want-fine-undo t)
  202. #+END_SRC
  203. #+BEGIN_SRC elisp
  204. (defun my/scroll-up ()
  205. (interactive)
  206. (evil-scroll-line-up 2))
  207. (defun my/scroll-down ()
  208. (interactive)
  209. (evil-scroll-line-down 2))
  210. (defun my/scroll-up-bigly ()
  211. (interactive)
  212. (evil-scroll-line-up 5))
  213. (defun my/scroll-down-bigly ()
  214. (interactive)
  215. (evil-scroll-line-down 5))
  216. #+END_SRC
  217. Auto center the point after jumping.
  218. #+BEGIN_SRC elisp
  219. (defmacro my//center-cmd (name &rest body)
  220. `(defun ,name ()
  221. (interactive)
  222. ,@body
  223. (call-interactively #'evil-scroll-line-to-center)))
  224. (my//center-cmd my/jump-forward (better-jumper-jump-forward))
  225. (my//center-cmd my/jump-backward (better-jumper-jump-backward))
  226. (my//center-cmd my/search-next (evil-ex-search-next))
  227. (my//center-cmd my/search-prev (evil-ex-search-previous))
  228. (my//center-cmd my/forward-paragraph (evil-forward-paragraph))
  229. (my//center-cmd my/backward-paragraph (evil-backward-paragraph))
  230. (my//center-cmd my/forward-section-begin (evil-forward-section-begin))
  231. (my//center-cmd my/forward-section-end (evil-forward-section-end))
  232. (my//center-cmd my/backward-section-begin (evil-backward-section-begin))
  233. (my//center-cmd my/backward-section-end (evil-backward-section-end))
  234. #+END_SRC
  235. #+BEGIN_SRC elisp
  236. (defun my/duplicate-and-comment-line ()
  237. (interactive)
  238. (vim! "yyp k gcc j"))
  239. #+END_SRC
  240. #+BEGIN_SRC elisp
  241. (setq search-invisible t)
  242. #+END_SRC
  243. *** Line Numbers
  244. Use relative line numbers in normal mode, and absolute line numbers in insert
  245. mode.
  246. #+BEGIN_SRC emacs-lisp
  247. (defun my/line-numbers-relative ()
  248. (setq display-line-numbers 'relative))
  249. (defun my/line-numbers-absolute ()
  250. (setq display-line-numbers 'absolute))
  251. (add-hook 'evil-insert-state-entry-hook #'my/line-numbers-absolute)
  252. (add-hook 'evil-insert-state-exit-hook #'my/line-numbers-relative)
  253. #+END_SRC
  254. *** Undo Tree
  255. #+BEGIN_SRC elisp
  256. (global-undo-tree-mode)
  257. (add-hook 'evil-local-mode-hook 'turn-on-undo-tree-mode)
  258. #+END_SRC
  259. ** Copilot
  260. Add support for GitHub Copilot ([[*Copilot][keybinds]]).
  261. #+BEGIN_SRC elisp
  262. (use-package copilot
  263. :commands (copilot-complete))
  264. (defun my/copilot-complete ()
  265. (interactive)
  266. (copilot-complete)
  267. (my/hydra-copilot/body)
  268. (copilot-clear-overlay))
  269. (defhydra my/hydra-copilot ()
  270. "Copilot"
  271. ("<return>" copilot-accept-completion "Accept" :color blue )
  272. ("<tab>" copilot-next-completion "Next" )
  273. ("<backtab>" copilot-previous-completion "Prev")
  274. ("<escape>" copilot-clear-overlay "Cancel" :color blue))
  275. #+END_SRC
  276. ** Scratch
  277. Use =lisp-interaction-mode= by default for the scratch buffer.
  278. #+BEGIN_SRC elisp
  279. (setq doom-scratch-initial-major-mode 'lisp-interaction-mode)
  280. #+END_SRC
  281. ** Abbreviations
  282. #+BEGIN_SRC elisp
  283. (use-package abbrev-mode
  284. :hook text-mode)
  285. (setq +abbrev-file (concat doom-user-dir "abbrevs.el"))
  286. (setq abbrev-file-name +abbrev-file)
  287. #+END_SRC
  288. * Keybinds
  289. ** Unmaps
  290. Unmap a bunch of the default keybindings.
  291. #+BEGIN_SRC elisp
  292. #+END_SRC
  293. #+BEGIN_SRC elisp
  294. (map! :leader
  295. ":" nil
  296. "b" nil
  297. "f" nil
  298. "h" nil
  299. "p" nil
  300. "t" nil
  301. "w" nil
  302. "c" nil)
  303. (map! :map evil-org-mode-map
  304. :n "zc" nil)
  305. #+END_SRC
  306. ** Global
  307. *** Font Size
  308. #+BEGIN_SRC elisp
  309. (map!
  310. :desc "Increase font size" :ni "C-=" #'text-scale-increase
  311. :desc "Decrease font size" :ni "C--" #'text-scale-decrease
  312. :desc "Reset font size" :ni "C-+" #'my/text-scale-reset)
  313. (defun my/text-scale-reset ()
  314. (interactive)
  315. (text-scale-set 0))
  316. #+END_SRC
  317. *** Copilot
  318. #+BEGIN_SRC elisp
  319. (map!
  320. :desc "Copilot" :i "C-?" #'my/copilot-complete)
  321. #+END_SRC
  322. *** LSP
  323. #+BEGIN_SRC elisp
  324. (map! :map lsp-mode-map
  325. :desc "Apply code action" :ni "C-/" #'lsp-execute-code-action
  326. :desc "Show definitions" :ni "C-." #'+lookup/definition
  327. :desc "Show references" :ni "C->" #'my/lsp/lookup-references
  328. :desc "Jump backward" :ni "C-," #'better-jumper-jump-backward
  329. :desc "Jump backward" :ni "C-<" #'better-jumper-jump-forward)
  330. (defun my/lsp/lookup-references ()
  331. (interactive)
  332. (lsp-treemacs-references t))
  333. #+END_SRC
  334. *** Minibuffer
  335. #+BEGIN_SRC elisp
  336. (map! :map minibuffer-mode-map
  337. :desc "Next history" "C-j" #'next-history-element
  338. :desc "Prev history" "C-k" #'previous-history-element)
  339. #+END_SRC
  340. *** Files
  341. #+BEGIN_SRC elisp
  342. (map!
  343. :desc "Save file" "C-s" #'save-buffer)
  344. #+END_SRC
  345. *** Evil
  346. #+BEGIN_SRC elisp
  347. (map!
  348. :desc "Scroll up" :ni "C-k" #'my/scroll-up
  349. :desc "Scroll down" :ni "C-j" #'my/scroll-down
  350. :desc "Scroll up bigly" :ni "C-S-k" #'my/scroll-up-bigly
  351. :desc "Scroll down bigly" :ni "C-S-j" #'my/scroll-down-bigly
  352. :desc "Jump forward" :n "C-o" #'my/jump-forward
  353. :desc "Jump backward" :n "C-o" #'my/jump-backward
  354. :desc "Search next" :n "n" #'my/search-next
  355. :desc "Search prev" :n "N" #'my/search-prev
  356. :desc "Forward paragraph" :n "}" #'my/forward-paragraph
  357. :desc "Backward paragraph" :n "{" #'my/backward-paragraph
  358. :desc "Forward section begin" :n "]]" #'my/forward-section-begin
  359. :desc "Forward section end" :n "][" #'my/forward-section-end
  360. :desc "Backward section begin" :n "[]" #'my/backward-section-begin
  361. :desc "Backward section end" :n "[[" #'my/backward-section-end)
  362. #+END_SRC
  363. #+BEGIN_SRC elisp
  364. (map!
  365. :desc "Undo tree visualizer" :n "U" #'undo-tree-visualize)
  366. #+END_SRC
  367. #+BEGIN_SRC elisp
  368. (map!
  369. :desc "Duplicate and comment line" :n "gC" #'my/duplicate-and-comment-line)
  370. #+END_SRC
  371. ** Leader
  372. *** Root
  373. **** Eval
  374. #+BEGIN_SRC elisp
  375. (map! :leader
  376. :desc "M-x" "x" #'counsel-M-x
  377. :desc "M-:" ";" #'pp-eval-expression)
  378. #+END_SRC
  379. **** Files
  380. #+BEGIN_SRC elisp
  381. (map! :leader
  382. :desc "Find file" "." #'counsel-find-file
  383. :desc "Find dir" ">" #'+default/dired
  384. :desc "Find in project" "SPC" #'+ivy/projectile-find-file
  385. :desc "Find in project uncached" "C-SPC" #'my/projectile-find-file-nocache)
  386. (defun my/projectile-find-file-nocache ()
  387. (interactive)
  388. (projectile-invalidate-cache nil)
  389. (+ivy/projectile-find-file))
  390. #+END_SRC
  391. **** Buffers
  392. #+BEGIN_SRC elisp
  393. (map! :leader
  394. :desc "Switch buffer" "," #'+vertico/switch-workspace-buffer
  395. :desc "Switch all buffers" "<" #'consult-buffer)
  396. #+END_SRC
  397. **** Search
  398. #+BEGIN_SRC elisp
  399. (map! :leader
  400. :desc "Search online" "/" #'my/counsel-search)
  401. #+END_SRC
  402. *** b: Buffers
  403. #+BEGIN_SRC elisp
  404. (map! :leader
  405. :prefix ("b" . "buffers")
  406. :desc "Switch buffer" "b" #'consult-buffer
  407. :desc "ibuffer" "i" #'ibuffer
  408. :desc "Kill buffer" "d" #'kill-current-buffer
  409. :desc "Kill all buffers" "D" #'doom/kill-all-buffers
  410. :desc "Rename buffer" "r" #'my/rename-buffer)
  411. #+END_SRC
  412. #+BEGIN_SRC elisp
  413. (defun my/rename-buffer (name)
  414. (interactive (list (read-string "Rename: " (buffer-name))))
  415. (rename-buffer name))
  416. #+END_SRC
  417. *** c: Code
  418. #+BEGIN_SRC elisp
  419. (map! :leader
  420. :prefix ("c" . "code")
  421. :desc "Format region/buffer" "f" #'+format/region-or-buffer
  422. :desc "Format imports" "F" #'lsp-organize-imports
  423. :desc "Rename symbol" "r" #'lsp-rename
  424. :desc "Show errors list" "x" #'+default/diagnostics
  425. :desc "Show errors tree" "X" #'lsp-treemacs-errors-list
  426. :desc "Show symbols tree" "s" #'lsp-treemacs-symbols
  427. :desc "Visit lens" "l" #'lsp-avy-lens
  428. :desc "Restart LSP" "q" #'lsp-restart-workspace)
  429. #+END_SRC
  430. *** f: Files
  431. #+BEGIN_SRC elisp
  432. (map! :leader
  433. :prefix ("f" . "files")
  434. :desc "Recent files" "r" #'consult-recent-file
  435. :desc "Find file" "f" #'counsel-find-file
  436. :desc "Find file as root" "u" #'doom/sudo-find-file
  437. :desc "Find package" "p" #'counsel-find-library
  438. :desc "Copy this file" "c" #'doom/copy-this-file
  439. :desc "Delete this file" "d" #'doom/delete-this-file
  440. :desc "Delete file" "D" #'delete-file
  441. :desc "Move this file" "m" #'doom/move-this-file
  442. :desc "Revert this file" "l" #'revert-buffer
  443. :desc "Copy file path" "y" #'+default/yank-buffer-path
  444. :desc "Copy project file path" "Y" #'+default/yank-buffer-path-relative-to-project
  445. :desc "Open scratch" "x" #'doom/open-scratch-buffer)
  446. #+END_SRC
  447. **** a: Abbrevs
  448. #+BEGIN_SRC emacs-lisp
  449. (map! :leader
  450. :prefix ("f a" . "abbrevs")
  451. :desc "Edit abbrevs" "e" #'my/abbrev-edit
  452. :desc "Reload abbrevs" "r" #'my/abbrev-reload
  453. :desc "Add global abbrev" "a" #'my/abbrev-add-global
  454. :desc "Add mode abbrev" "m" #'my/abbrev-add-mode)
  455. #+END_SRC
  456. #+BEGIN_SRC elisp
  457. (defun my/abbrev-edit ()
  458. (interactive)
  459. (find-file-other-window +abbrev-file))
  460. (defun my/abbrev-reload ()
  461. (interactive)
  462. (read-abbrev-file +abbrev-file))
  463. (defun my/abbrev-save ()
  464. (interactive)
  465. (write-abbrev-file +abbrev-file))
  466. (defun my/abbrev-add-global ()
  467. (interactive)
  468. (call-interactively #'inverse-add-global-abbrev)
  469. (my/abbrev-save))
  470. (defun my/abbrev-add-mode ()
  471. (interactive)
  472. (call-interactively #'inverse-add-mode-abbrev)
  473. (my/abbrev-save))
  474. #+END_SRC
  475. **** e: Emacs Files
  476. #+BEGIN_SRC elisp
  477. (map! :leader
  478. :prefix ("f e" . "emacs")
  479. :desc "Find in config" "f" #'doom/find-file-in-private-config
  480. :desc "Reload config" "r" #'doom/reload
  481. :desc "Edit config" "c" #'my/edit-config
  482. :desc "Edit packages" "p" #'my/edit-packages
  483. :desc "Edit env" "e" #'my/edit-env
  484. :desc "Edit init" "i" #'my/edit-init)
  485. #+END_SRC
  486. #+BEGIN_SRC elisp
  487. (defun my/edit-config ()
  488. (interactive)
  489. (find-file (concat doom-user-dir "config.org")))
  490. (defun my/edit-packages ()
  491. (interactive)
  492. (find-file (concat doom-user-dir "packages.el")))
  493. (defun my/edit-init ()
  494. (interactive)
  495. (find-file (concat doom-user-dir "init.el")))
  496. (defun my/edit-env ()
  497. (interactive)
  498. (find-file (concat doom-user-dir "env.el")))
  499. #+END_SRC
  500. Define a derived mode for editing the literate config so we can specify some
  501. keybindings specific to =config.org=.
  502. #+BEGIN_SRC elisp
  503. (define-derived-mode org-config-mode org-mode "Org config mode")
  504. (add-to-list 'auto-mode-alist '("config\\.org" . org-config-mode))
  505. #+END_SRC
  506. **** s: Snippets
  507. #+BEGIN_SRC emacs-lisp
  508. (map! :leader
  509. :prefix ("f s" . "snippets")
  510. :desc "Find snippet" "f" #'my/yas-find-snippet
  511. :desc "New snippet" "n" #'yas/new-snippet
  512. :desc "Edit snippet" "e" #'my/yas-edit-snippet
  513. :desc "Describe snippets" "d" #'yas/describe-tables
  514. :desc "Reload snippets" "r" #'yas/reload-all
  515. :desc "Browse docs" "?" #'my/yas-browse-docs)
  516. #+END_SRC
  517. Add a command to open the YASnippet docs.
  518. #+BEGIN_SRC elisp
  519. (defun my/yas-browse-docs ()
  520. (interactive)
  521. (browse-url "https://joaotavora.github.io/yasnippet"))
  522. #+END_SRC
  523. #+BEGIN_SRC elisp
  524. (defun my/yas-edit-snippet ()
  525. (interactive)
  526. (call-interactively #'yas/visit-snippet-file))
  527. (defun my/yas-find-snippet ()
  528. (interactive)
  529. (counsel-find-file nil +snippets-dir))
  530. #+END_SRC
  531. *** h: Help
  532. #+BEGIN_SRC elisp
  533. (map! :leader
  534. :prefix ("h" . "help")
  535. :desc "Apropos" "/" #'consult-apropos
  536. :desc "Apropos docs" "?" #'apropos-documentation
  537. :desc "Help at point" "p" #'helpful-at-point
  538. :desc "Help info" "h" #'info
  539. :desc "Help for help" "H" #'help-for-help
  540. :desc "Describe mode" "m" #'describe-mode
  541. :desc "Describe minor modes" "M" #'doom/describe-active-minor-mode
  542. :desc "Describe function" "f" #'counsel-describe-function
  543. :desc "Describe function key" "F" #'where-is
  544. :desc "Describe variable" "v" #'counsel-describe-variable
  545. :desc "Describe custom variable" "V" #'doom/help-custom-variable
  546. :desc "Describe command" "x" #'helpful-command
  547. :desc "Describe key" "k" #'describe-key-briefly
  548. :desc "Describe key fully" "K" #'describe-key
  549. :desc "Describe char" "'" #'describe-char
  550. :desc "Describe coding system" "\"" #'describe-coding-system
  551. :desc "Describe input method" "i" #'describe-input-method
  552. :desc "Emacs manual" "e" #'info-emacs-manual
  553. :desc "ASCII table" "a" #'my/ascii-table
  554. :desc "View messages" "e" #'view-echo-area-messages
  555. :desc "View keystrokes" "l" #'view-lossage)
  556. #+END_SRC
  557. **** a: Ascii Table
  558. #+BEGIN_SRC elisp
  559. (defface my/ascii-table-highlight-face
  560. '((t (:foreground "pink")))
  561. "Face for highlighting ASCII chars.")
  562. (defun my/ascii-table ()
  563. "Display basic ASCII table (0 thru 128)."
  564. (interactive)
  565. (pop-to-buffer "*ASCII*")
  566. (erase-buffer)
  567. (setq buffer-read-only nil)
  568. (my/buffer-local-set-key "q" #'+popup/quit-window)
  569. (setq lower32 '("nul" "soh" "stx" "etx" "eot" "enq" "ack" "bel"
  570. "bs" "ht" "nl" "vt" "np" "cr" "so" "si"
  571. "dle" "dc1" "dc2" "dc3" "dc4" "nak" "syn" "etb"
  572. "can" "em" "sub" "esc" "fs" "gs" "rs" "us"))
  573. (save-excursion (let ((i -1))
  574. (insert " Hex Dec Char | Hex Dec Char | Hex Dec Char | Hex Dec Char\n")
  575. (insert " ---------------+-----------------+-----------------+----------------\n")
  576. (while (< i 31)
  577. (insert (format "%4x %4d %4s | %4x %4d %4s | %4x %4d %4s | %4x %4d %4s\n"
  578. (setq i (+ 1 i)) i (elt lower32 i)
  579. (setq i (+ 32 i)) i (single-key-description i)
  580. (setq i (+ 32 i)) i (single-key-description i)
  581. (setq i (+ 32 i)) i (single-key-description i)))
  582. (overlay-put (make-overlay (- (point) 4) (- (point) 1)) 'face 'my/ascii-table-highlight-face)
  583. (overlay-put (make-overlay (- (point) 22) (- (point) 19)) 'face 'my/ascii-table-highlight-face)
  584. (overlay-put (make-overlay (- (point) 40) (- (point) 37)) 'face 'my/ascii-table-highlight-face)
  585. (overlay-put (make-overlay (- (point) 58) (- (point) 55)) 'face 'my/ascii-table-highlight-face)
  586. (setq i (- i 96))
  587. ))))
  588. (set-popup-rule! "^\\*ASCII"
  589. :side 'right
  590. :select t
  591. :width 70)
  592. #+END_SRC
  593. **** d: Doom
  594. #+BEGIN_SRC elisp
  595. (map! :leader
  596. :prefix ("h d" . "doom")
  597. :desc "Doom manual" "d" #'doom/help
  598. :desc "Doom FAQ" "f" #'doom/help-faq
  599. :desc "Doom modules" "m" #'doom/help-modules
  600. :desc "Doom news" "n" #'doom/help-news
  601. :desc "Doom help search" "/" #'doom/help-search-headings
  602. :desc "Doom version" "v" #'doom/version
  603. :desc "Doom package configuration" "p" #'doom/help-package-config
  604. :desc "Doom sandbox" "x" #'doom/sandbox)
  605. #+END_SRC
  606. *** l: Ligma
  607. #+BEGIN_SRC elisp
  608. (map! :leader
  609. :prefix ("l" . "ligma")
  610. :desc "Search" "s" #'ts/search
  611. :desc "Sourcegraph search" "g" #'ts/sourcegraph-search
  612. :desc "Sourcegraph browse" "G" #'ts/sourcegraph-browse)
  613. #+END_SRC
  614. *** TODO o: Open
  615. *** p: Projects
  616. #+BEGIN_SRC elisp
  617. (map! :leader
  618. :prefix ("p" . "projects")
  619. :desc "Switch project" "p" #'my/projectile-switch-project
  620. :desc "Add new project" "a" #'projectile-add-known-project
  621. :desc "Remove project" "d" #'projectile-remove-known-project
  622. :desc "Find in project root" "." #'counsel-projectile-find-file
  623. :desc "Search in project" "/" #'+default/search-project
  624. :desc "Invalidate project cache" "i" #'projectile-invalidate-cache
  625. :desc "Run cmd in project root" "!" #'projectile-run-shell-command-in-root
  626. :desc "Run async cmd in project root" "&" #'projectile-run-async-shell-command-in-root)
  627. (defun my/projectile-find-in-root ()
  628. (interactive)
  629. (counsel-find-file nil projectile-project-root))
  630. #+END_SRC
  631. *** t: Toggle
  632. #+BEGIN_SRC elisp
  633. (map! :leader
  634. :prefix ("t" . "toggle")
  635. ;; Wrap
  636. :desc "Auto Wrap" "a" #'auto-fill-mode
  637. :desc "Wrap Indicator" "c" #'global-display-fill-column-indicator-mode
  638. :desc "Wrap Column" "C" #'set-fill-column
  639. :desc "Line Wrap" "w" #'visual-line-mode
  640. ;; Modes
  641. :desc "Flycheck" "f" #'flycheck-mode
  642. :desc "Keycast" "k" #'keycast-mode
  643. ;; Files
  644. :desc "Read-only" "r" #'read-only-mode)
  645. #+END_SRC
  646. #+BEGIN_SRC elisp
  647. (defun my/auto-fill-mode (cols)
  648. (interactive))
  649. #+END_SRC
  650. *** w: Window
  651. #+BEGIN_SRC elisp
  652. (map! :leader
  653. :prefix-map ("w" . "window")
  654. ;; Navigation
  655. :desc "Go..." "w" #'ace-window
  656. :desc "Go left" "h" #'evil-window-left
  657. :desc "Go down" "j" #'evil-window-down
  658. :desc "Go up" "k" #'evil-window-up
  659. :desc "Go right" "l" #'evil-window-right
  660. :desc "Go other" "o" #'other-window
  661. ;; Layout
  662. :desc "Move left" "H" #'+evil/window-move-left
  663. :desc "Move down" "J" #'+evil/window-move-down
  664. :desc "Move up" "K" #'+evil/window-move-up
  665. :desc "Move right" "L" #'+evil/window-move-right
  666. ;; Splits
  667. :desc "VSplit" "=" #'+evil/window-vsplit-and-follow
  668. :desc "HSplit" "-" #'+evil/window-split-and-follow
  669. :desc "Tear off" "t" #'tear-off-window
  670. ;; History
  671. :desc "Undo" "u" #'winner-undo
  672. :desc "Redo" "U" #'winner-redo
  673. ;; Misc
  674. :desc "Resize..." "r" #'my/hydra-window-resize/body
  675. :desc "Rotate..." "R" #'my/hydra-window-rotate/body
  676. :desc "Balance" "b" #'balance-windows
  677. ;; Management
  678. :desc "Kill window" "d" #'+workspace/close-window-or-workspace)
  679. ;; TODO: Maybe check out:
  680. ;; evil-window-mru
  681. #+END_SRC
  682. #+BEGIN_SRC elisp
  683. (setq my/window-resize-step 3)
  684. (defun my/window-increase-height ()
  685. (interactive)
  686. (evil-window-increase-height my/window-resize-step))
  687. (defun my/window-decrease-height ()
  688. (interactive)
  689. (evil-window-decrease-height my/window-resize-step))
  690. (defun my/window-increase-width ()
  691. (interactive)
  692. (evil-window-increase-width my/window-resize-step))
  693. (defun my/window-decrease-width ()
  694. (interactive)
  695. (evil-window-decrease-width my/window-resize-step))
  696. (defhydra my/hydra-window-resize ()
  697. "Resize window"
  698. ("k" my/window-increase-height "++Height")
  699. ("j" my/window-decrease-height "--Height")
  700. ("h" my/window-decrease-width "--Width")
  701. ("l" my/window-increase-width "++Width")
  702. ("ESC" nil "Quit" :color blue))
  703. #+END_SRC
  704. #+BEGIN_SRC elisp
  705. (defhydra my/hydra-window-rotate ()
  706. "Rotate window"
  707. ("h" +evil/window-move-left "Move left")
  708. ("j" +evil/window-move-down "Move down")
  709. ("k" +evil/window-move-up "Move up")
  710. ("l" +evil/window-move-right "Move right")
  711. ("H" evil-window-move-far-left "Move far left")
  712. ("J" evil-window-rotate-downwards "Rotate Down")
  713. ("K" evil-window-rotate-upwards "Rotate Up")
  714. ("L" evil-window-move-far-right "Move far right"))
  715. #+END_SRC
  716. ** Local Leader
  717. *** Org Config
  718. #+BEGIN_SRC elisp
  719. (map! :map org-config-mode-map
  720. :localleader
  721. :v :desc "Eval Region" "e" #'eval-region
  722. :n :desc "Eval Source" "e" #'my/org-config-eval-source)
  723. (defun my/org-config-eval-source ()
  724. (interactive)
  725. (org-ctrl-c-ctrl-c)
  726. (org-babel-remove-result))
  727. #+END_SRC
  728. *** Rust
  729. #+BEGIN_SRC elisp
  730. ;; (map! :map rustic-mode-map
  731. ;; :localleader
  732. ;; "b" nil
  733. ;; "t" nil)
  734. ;; (map! :map rustic-mode-map
  735. ;; :localleader
  736. ;; :desc "Edit Cargo.toml" "t" #'my/rust/edit-cargo-toml)
  737. ;; (map! :map rustic-mode-map
  738. ;; :leader
  739. ;; :prefix ("c" . "code")
  740. ;; :desc "Expand macro" "m" #'lsp-rust-analyzer-expand-macro
  741. ;; :desc "Open docs" "h" #'lsp-rust-analyzer-open-external-docs)
  742. ;; (map! :map rustic-mode-map
  743. ;; :localleader
  744. ;; :prefix ("b" . "build")
  745. ;; :desc "Build" "b" #'rustic-cargo-check
  746. ;; :desc "Check" "c" #'rustic-cargo-check
  747. ;; :desc "Debug" "d" #'my/rust/dap-hydra/body
  748. ;; :desc "Run" "r" #'rustic-cargo-run
  749. ;; :desc "Bench" "B" #'rustic-cargo-bench
  750. ;; :desc "Test current" "t" #'rustic-cargo-current-test
  751. ;; :desc "Test all" "T" #'rustic-cargo-test)
  752. (map! :map rustic-mode-map
  753. :desc "Pluralize import" "," #'my/rust/import-pluralize
  754. :desc "Singularize import" "<backspace>" #'my/rust/import-singularize
  755. :desc "Singularize import" "C-<backspace>" #'my/rust/import-c-singularize
  756. :desc "Singularize import" "C-<delete>" #'my/rust/import-rev-singularize)
  757. #+END_SRC
  758. **** Debugging
  759. #+BEGIN_SRC elisp
  760. (defhydra my/rust/dap-hydra (:color pink :hint nil :foreign-keys run)
  761. "
  762. ^Stepping^ ^Switch^ ^Breakpoints^ ^Debug^ ^Eval
  763. ^^^^^^^^----------------------------------------------------------------------------------------------------------------
  764. _n_: Next _ss_: Session _bb_: Toggle _dd_: Debug binary _ee_: Eval
  765. _i_: Step in _st_: Thread _bd_: Delete _dr_: Restart debugging _es_: Eval thing at point
  766. _o_: Step out _sf_: Stack frame _ba_: Add _ea_: Add expression
  767. _c_: Continue _su_: Up stack frame _bc_: Set condition
  768. _Q_: Disconnect _sd_: Down stack frame _bh_: Set hit count
  769. _sl_: List locals _bl_: Set log message
  770. _sb_: List breakpoints
  771. _sS_: List sessions
  772. "
  773. ("n" dap-next)
  774. ("i" dap-step-in)
  775. ("o" dap-step-out)
  776. ("c" dap-continue)
  777. ("r" dap-restart-frame)
  778. ("ss" dap-switch-session)
  779. ("st" dap-switch-thread)
  780. ("sf" dap-switch-stack-frame)
  781. ("su" dap-up-stack-frame)
  782. ("sd" dap-down-stack-frame)
  783. ("sl" dap-ui-locals)
  784. ("sb" dap-ui-breakpoints)
  785. ("sS" dap-ui-sessions)
  786. ("bb" dap-breakpoint-toggle)
  787. ("ba" dap-breakpoint-add)
  788. ("bd" dap-breakpoint-delete)
  789. ("bc" dap-breakpoint-condition)
  790. ("bh" dap-breakpoint-hit-condition)
  791. ("bl" dap-breakpoint-log-message)
  792. ("dd" my/rust/debug-binary)
  793. ("dr" dap-debug-restart)
  794. ("ee" dap-eval)
  795. ("ea" dap-ui-expressions-add)
  796. ("es" dap-eval-thing-at-point)
  797. ("q" nil "quit" :color blue)
  798. ("Q" dap-disconnect :color red))
  799. #+END_SRC
  800. **** Cargo.toml
  801. #+BEGIN_SRC elisp
  802. (map! :map cargo-toml-mode-map
  803. :localleader
  804. :desc "Add crate (semver)" "a" #'my/rust/cargo-toml-add-crate-semver
  805. :desc "Add crate (exact)" "A" #'my/rust/cargo-toml-add-crate)
  806. #+END_SRC
  807. ** Modes
  808. *** Evil
  809. **** z
  810. #+BEGIN_SRC elisp
  811. (map! :prefix "z"
  812. :desc "Kill buffer" :n "x" #'kill-current-buffer
  813. :desc "Kill window" :n "c" #'+workspace/close-window-or-workspace)
  814. #+END_SRC
  815. **** g
  816. **** [
  817. #+BEGIN_SRC elisp
  818. (map! :prefix "["
  819. :desc "Start of fn" :n "f" #'beginning-of-defun)
  820. (map! :prefix "]"
  821. :desc "End of fn" :n "f" #'end-of-defun)
  822. #+END_SRC
  823. *** Dap
  824. #+BEGIN_SRC elisp
  825. #+END_SRC
  826. * Languages
  827. ** Rust
  828. *** General
  829. #+BEGIN_SRC elisp
  830. (add-to-list 'projectile-globally-ignored-files "Cargo.lock")
  831. #+END_SRC
  832. #+BEGIN_SRC elisp
  833. (setq lsp-rust-analyzer-inlay-hints-mode t)
  834. (setq lsp-rust-analyzer-server-display-inlay-hints t)
  835. (setq lsp-rust-analyzer-display-closure-return-type-hints t)
  836. (setq lsp-rust-analyzer-display-lifetime-elision-hints-enable "skip_trivial")
  837. (setq lsp-rust-analyzer-display-lifetime-elision-hints-use-parameter-names nil)
  838. (setq lsp-rust-analyzer-display-chaining-hints t)
  839. (setq lsp-rust-analyzer-display-reborrow-hints t)
  840. #+END_SRC
  841. *** Editing
  842. When editing a list of "use" imports, automatically add and remove braces when typing or removing commas
  843. #+BEGIN_SRC elisp
  844. (rx-let ((crate (or alphanumeric "_" "*")))
  845. (setq my//rust/import-singular-rx
  846. ;; use foo::bar::baz;
  847. (rx "use "
  848. (+ (+ crate) "::")
  849. (+ crate)
  850. (? ";") line-end))
  851. (setq my//rust/import-plural-rx
  852. ;; use foo::bar::baz::{qux::quo, };
  853. (rx "use "
  854. (+ (+ crate) "::")
  855. "{" (* (+ crate) "::") (+ crate) "," (* whitespace) "}"
  856. (? ";") line-end))
  857. (setq my//rust/import-plural-rev-rx
  858. ;; use foo::bar::baz::{, qux::quo};
  859. (rx "use "
  860. (+ (+ crate) "::")
  861. "{," (* whitespace) (* (+ crate) "::") (+ crate) "}"
  862. (? ";") line-end)))
  863. (defun my/rust/import-pluralize ()
  864. "Convert a singular import into a brace-wrapped plural import."
  865. (interactive)
  866. (if (and
  867. (my/insert-mode-p)
  868. (my/line-match-p my//rust/import-singular-rx))
  869. (vim! "ESC vb S} f} i,")
  870. (insert ",")))
  871. (defun my/rust/import-singularize ()
  872. "Convert a brace-wrapped plural import into a singular import."
  873. (interactive)
  874. (if (and
  875. (my/insert-mode-p)
  876. (my/line-match-p my//rust/import-plural-rx))
  877. (vim! "ESC l dF, ds} $i")
  878. (evil-delete-backward-char-and-join 1)))
  879. (defun my/rust/import-c-singularize ()
  880. "Convert a brace-wrapped plural import into a singular import."
  881. (interactive)
  882. (if (and
  883. (my/insert-mode-p)
  884. (my/line-match-p my//rust/import-plural-rx))
  885. (vim! "ESC l dF, ds} $i")
  886. (backward-kill-word 1)))
  887. (defun my/rust/import-rev-singularize ()
  888. "Convert a brace-wrapped plural import into a singular import."
  889. (interactive)
  890. (if (and
  891. (my/insert-mode-p)
  892. (my/line-match-p my//rust/import-plural-rev-rx))
  893. (vim! "ESC ds} dw $i")
  894. (kill-word 1)))
  895. #+END_SRC
  896. *** Debugging
  897. #+BEGIN_SRC elisp
  898. (defun my/rust/debug-config (args)
  899. (append
  900. `(:type "lldb-vscode"
  901. ;; `(:type "lldb"
  902. :request "launch"
  903. :dap-server-path ,(list (executable-find "lldb-vscode"))
  904. ;; :dap-server-path ,(list (executable-find "rust-lldb"))
  905. ,@args)))
  906. ;; use a::TestThin
  907. ;; (:MIMode "gdb"
  908. ;; :miDebuggerPath "gdb"
  909. ;; :stopAtEntry t
  910. ;; :externalConsole
  911. ;; :json-false
  912. ;; :type "cppdbg"
  913. ;; :request "launch"
  914. ;; :name "test test2"
  915. ;; :args ["test2" "--exact" "--nocapture"]
  916. ;; :cwd "/home/lain/Code/test/rust/debug"
  917. ;; :sourceLanguages ["rust"]
  918. ;; :program "/home/lain/Code/test/rust/debug/target/debug/deps/...")
  919. ;; (require 'dap-cpptools)
  920. (defun my/rust/debug-binary (args)
  921. (interactive "sArgs: ")
  922. (let* ((root (projectile-project-root))
  923. (name (projectile-project-name))
  924. (target (concat root "target/debug/" name)))
  925. ;; (rustic-cargo-build)
  926. (dap-debug
  927. (my/rust/debug-config
  928. `(:program ,target
  929. :cwd ,root
  930. :args ,(apply #'vector (split-string-and-unquote args)))))))
  931. (defun my/rust/debug-lsp-runnable (runnable)
  932. "Select and debug a RUNNABLE action."
  933. (interactive (list (lsp-rust-analyzer--select-runnable)))
  934. (-let (((&rust-analyzer:Runnable
  935. :args (&rust-analyzer:RunnableArgs :cargo-args :workspace-root? :executable-args)
  936. :label) runnable))
  937. (pcase (aref cargo-args 0)
  938. ("run" (aset cargo-args 0 "build"))
  939. ("test" (when (-contains? (append cargo-args ()) "--no-run")
  940. (cl-callf append cargo-args (list "--no-run")))))
  941. (->> (append (list (executable-find "cargo"))
  942. cargo-args
  943. (list "--message-format=json"))
  944. (s-join " ")
  945. (shell-command-to-string)
  946. (s-lines)
  947. (-keep (lambda (s)
  948. (condition-case nil
  949. (-let* ((json-object-type 'plist)
  950. ((msg &as &plist :reason :executable) (json-read-from-string s)))
  951. (when (and executable (string= "compiler-artifact" reason))
  952. executable))
  953. (error))))
  954. (funcall
  955. (lambda (artifact-spec)
  956. (pcase artifact-spec
  957. (`() (user-error "No compilation artifacts or obtaining the runnable artifacts failed"))
  958. (`(,spec) spec)
  959. (_ (user-error "Multiple compilation artifacts are not supported")))))
  960. (list :name label
  961. :args executable-args
  962. :cwd workspace-root?
  963. ;; :sourceLanguages ["rust"]
  964. :stopAtEntry t
  965. :stopAtEntry :json-true
  966. :externalConsole :json-false
  967. :program)
  968. (my/rust/debug-config)
  969. (dap-debug))))
  970. (advice-add #'lsp-rust-analyzer-debug :override #'my/rust/debug-lsp-runnable)
  971. #+END_SRC
  972. *** Cargo.toml
  973. Define a derived mode for =conf-toml-mode= so we can specify some
  974. keybindings specific to =Cargo.toml= files.
  975. #+BEGIN_SRC elisp
  976. (define-derived-mode cargo-toml-mode conf-toml-mode "Cargo.toml mode")
  977. (add-to-list 'auto-mode-alist '("Cargo\\.toml" . cargo-toml-mode))
  978. #+END_SRC
  979. Define a wrapper function for visiting the closest Cargo.toml in a new window.
  980. #+BEGIN_SRC elisp
  981. (defun my/rust/edit-cargo-toml ()
  982. (interactive)
  983. (lsp-rust-analyzer-open-cargo-toml))
  984. #+END_SRC
  985. Define a helper for pulling the latest versions of crates from crates.io
  986. #+BEGIN_SRC elisp :lexical t
  987. (defun my/rust/get-latest-crate-version (crate callback)
  988. (request! (format "https://crates.io/api/v1/crates/%s/versions" crate)
  989. (:type "GET" :parser 'json-read)
  990. (lambda (data)
  991. (let* ((versions (alist-get 'versions data))
  992. (target (elt versions 0))
  993. (num (alist-get 'num target)))
  994. (funcall callback num)))
  995. (lambda ()
  996. (message "Crate not found: %s" crate))))
  997. (defun my/rust/cargo-toml-add-crate (crate)
  998. "Insert `crate = version` with the latest available version of a crate."
  999. (interactive "sCrate: ")
  1000. (my/rust/get-latest-crate-version
  1001. crate
  1002. (lambda (version)
  1003. (insert (format "%s = \"%s\"" crate version)))))
  1004. (defun my/rust/cargo-toml-add-crate-semver (crate)
  1005. "Insert `crate = version` with the latest available version of a crate.
  1006. Use any semver compatible version with either the current major release,
  1007. or the minor release if the major version is still 0."
  1008. (interactive "sCrate: ")
  1009. (my/rust/get-latest-crate-version
  1010. crate
  1011. (lambda (version)
  1012. (let* ((parts (split-string version "\\."))
  1013. (major (nth 0 parts))
  1014. (minor (nth 1 parts))
  1015. (patch (nth 2 parts))
  1016. (semver (if (equal major "0")
  1017. (format "%s.%s" major minor)
  1018. (format "%s" major))))
  1019. (insert (format "%s = \"%s\"" crate semver))))))
  1020. #+END_SRC
  1021. *** Lisp
  1022. #+BEGIN_SRC elisp
  1023. (defun my/rust/cargo-toml (&optional dir)
  1024. (path! (locate! "Cargo.toml" dir) "Cargo.toml"))
  1025. (defun my/rust/workspace-root (&optional dir)
  1026. (shell! "%s | jq -r '.workspace_root'"
  1027. (cargo! "metadata --no-deps --format-version 1" dir)))
  1028. (defun cargo! (cmd &optional dir)
  1029. (format "cargo %s --manifest-path \"%s\""
  1030. cmd
  1031. (my/rust/cargo-toml dir)))
  1032. #+END_SRC
  1033. ** Go
  1034. *** Debugging
  1035. Setup: run =M-x dap-go-setup=
  1036. * Tools
  1037. ** Org
  1038. ** Projectile
  1039. #+BEGIN_SRC elisp
  1040. ;; (setq projectile-project-search-path
  1041. ;; '("~/Code"))
  1042. (defun my/projectile-project-ignored-p (root)
  1043. (or (doom-project-ignored-p root)
  1044. (file-in-directory-p root "/opt/ts/fuse/artfs_mounts")
  1045. (file-in-directory-p root "/home/tsdist/vats_deployments")))
  1046. (setq projectile-ignored-project-function #'my/projectile-project-ignored-p)
  1047. (defun my/projectile-switch-project ()
  1048. (interactive)
  1049. ;; Prune projects which no longer exist
  1050. (when (boundp 'projectile-known-projects)
  1051. (dolist (project projectile-known-projects)
  1052. (unless (file-directory-p project)
  1053. (projectile-remove-known-project project))))
  1054. (call-interactively #'counsel-projectile-switch-project))
  1055. #+END_SRC
  1056. ** LSP
  1057. #+BEGIN_SRC elisp
  1058. (setq lsp-ui-doc-show-with-mouse t)
  1059. (setq lsp-headerline-breadcrumb-enable t)
  1060. (setq lsp-headerline-breadcrumb-segments '(symbols))
  1061. #+END_SRC
  1062. #+BEGIN_SRC elisp
  1063. (defun my/lsp-root (lsp--calculate-root session file)
  1064. (or
  1065. (and (ts/repo/p file)
  1066. (pcase (f-ext file t)
  1067. (".rs" (my/rust/workspace-root file))
  1068. (_ nil)))
  1069. (lsp--calculate-root session file)))
  1070. ((advice-add 'lsp--calculate-root :around #'my/lsp-root)
  1071. #+END_SRC
  1072. ** Counsel Search
  1073. #+BEGIN_SRC elisp
  1074. (defun my/counsel-search ()
  1075. (interactive)
  1076. (unless (boundp 'my/kagi-found)
  1077. (my/with-credential
  1078. (:host "kagi.com") token
  1079. (if token
  1080. (progn
  1081. (setq my/kagi-found (if token t nil))
  1082. (setq counsel-search-engines-alist
  1083. `((kagi
  1084. "https://duckduckgo.com/ac/"
  1085. ,(format "https://kagi.com/search?token=%s&q=" token)
  1086. counsel--search-request-data-ddg)))
  1087. (setq counsel-search-engine 'kagi))
  1088. (warn "Token for kagi.com not found in authinfo. Falling back to default search engine."))))
  1089. (call-interactively #'counsel-search))
  1090. #+END_SRC
  1091. ** Keycast
  1092. #+BEGIN_SRC elisp
  1093. (after! keycast
  1094. (define-minor-mode keycast-mode
  1095. "Show current command and its key binding in the mode line."
  1096. :global t
  1097. (if keycast-mode
  1098. (progn
  1099. (add-to-list 'global-mode-string '("" keycast-mode-line))
  1100. (add-hook 'pre-command-hook 'keycast--update t))
  1101. (progn
  1102. (setq global-mode-string (delete '("" keycast-mode-line) global-mode-string))
  1103. (remove-hook 'pre-command-hook 'keycast--update))))
  1104. (dolist (input '(self-insert-command
  1105. org-self-insert-command))
  1106. (add-to-list 'keycast-substitute-alist `(,input nil)))
  1107. (dolist (event '(mouse-event-p
  1108. mouse-movement-p
  1109. mwheel-scroll
  1110. lsp-ui-doc--handle-mouse-movement
  1111. ignore))
  1112. (add-to-list 'keycast-substitute-alist `(,event nil))))
  1113. #+END_SRC
  1114. ** SourceGraph
  1115. #+BEGIN_SRC elisp
  1116. (use-package sourcegraph
  1117. :hook (prog-mode . sourcegraph-mode))
  1118. (setq sourcegraph-url "https://sourcegraph.app.twosigma.com")
  1119. #+END_SRC
  1120. ** Rmsbolt
  1121. * Apps
  1122. ** Emacs Everywhere
  1123. #+BEGIN_SRC elisp
  1124. (load! "lisp/emacs-everywhere.el")
  1125. (setq emacs-everywhere-paste-command '("xdotool" "key" "--clearmodifiers" "ctrl+v"))
  1126. (setq emacs-everywhere-frame-parameters
  1127. '((title . "Emacs Everywhere")
  1128. (width . 120)
  1129. (height . 36)))
  1130. #+END_SRC