Compare commits

...

26 Commits

Author SHA1 Message Date
ddc20b88e2 Merge branch 'master' of git.jeremydormitzer.com:jdormit/dotfiles 2024-10-02 11:18:57 -04:00
ebab6d32b9 Use icons in dired 2024-10-02 11:17:37 -04:00
f132f9fa7b Set up nvm 2024-10-02 11:17:31 -04:00
6352fbb697 Use web-mode for astro 2024-09-19 10:39:40 -04:00
73227abcbe Merge branch 'master' of github.com:jdormit/dotfiles 2024-09-17 09:44:45 -04:00
09bbe297aa Add log to witchcraft server 2024-09-17 09:44:22 -04:00
b04ecc05d1 Add cargo mode 2024-09-16 20:08:00 -04:00
63f8fb86c9 Add tinyllama 2024-09-16 19:54:07 -04:00
3f43f47bac Merge branch 'master' of github.com:jdormit/dotfiles 2024-09-16 17:05:10 -04:00
91a2df3e08 Fix witchcraft server launch daemon 2024-09-16 17:04:52 -04:00
e8aec0ade3 Add charles and wireshark 2024-09-12 20:19:12 -04:00
0ccb10c8e2 Add CSV mode 2024-09-12 20:19:12 -04:00
ef5b7f03d6 Add commmand to run rspec on files changed from the main branch 2024-09-12 20:17:14 -04:00
fd961c9416 Add some autoloads 2024-09-12 20:17:08 -04:00
2f4d415cba Add anthropic gptel backend 2024-09-09 11:57:42 -04:00
5f11045ae0 Add ability to edit rspec command before running 2024-09-06 19:29:18 -06:00
e1be78e05f Enable rspec-dired-mode in dired buffers 2024-09-06 19:29:05 -06:00
d3a2bcd6f5 Add run-command comint runner 2024-09-05 06:18:59 -06:00
ad1ba5f7fa Use rspec-mode to run Ruby tests 2024-09-05 06:18:36 -06:00
1823e4bcf6 Fontify markdown source blocks 2024-09-05 06:18:27 -06:00
4af3063f30 Close diff when PR is submitted 2024-09-05 06:18:19 -06:00
47727d73f9 Call apheleia-format-buffer normally when there's no region 2024-08-29 13:25:24 -04:00
d5030f749f Bind consult-history in minibuffer 2024-08-28 09:42:12 -04:00
9a1f0aea68 Trim output before inserting 2024-08-28 09:41:54 -04:00
59ab43f820 Add command to format code with gptel 2024-08-22 16:02:54 -04:00
af5e7ab1e0 Add custom apheleia function for formatting regions
Implemented a custom `apheleia` function to format selected regions or entire buffer using Apheleia, handling temp files and regions. Updated keybinding for `C-c f` to use this new function.
2024-08-22 13:01:48 -04:00
16 changed files with 169 additions and 91 deletions

View File

@ -5,6 +5,7 @@
(use-package gptel (use-package gptel
:commands (gptel-request) :commands (gptel-request)
:autoload (gptel--strip-mode-suffix)
:init :init
;; Annoyingly, gptel fails to require gptel-context, so we have to do it manually ;; Annoyingly, gptel fails to require gptel-context, so we have to do it manually
(autoload 'gptel-context-add "gptel-context") (autoload 'gptel-context-add "gptel-context")
@ -42,7 +43,11 @@
:stream t :stream t
:models '("llama3.1:latest" :models '("llama3.1:latest"
"mistral-nemo:latest" "mistral-nemo:latest"
"gemma2:2b"))) "gemma2:2b"
"tinyllama:latest")))
(defvar gptel-backend-anthropic (gptel-make-anthropic "Claude"
:stream t
:key (password-store-get "anthropic-api-key")))
(setq gptel-backend gptel-backend-openai (setq gptel-backend gptel-backend-openai
gptel-model "gpt-4o") gptel-model "gpt-4o")
(defun gptel-select-backend (backend) (defun gptel-select-backend (backend)
@ -81,6 +86,27 @@
(when options-plist (when options-plist
(plist-put prompts-plist :options options-plist)) (plist-put prompts-plist :options options-plist))
prompts-plist)) prompts-plist))
(defun gptel-format ()
"Format the current region or buffer with gptel."
(interactive)
(let* ((subject (if (derived-mode-p 'prog-mode)
(format "%s code" (gptel--strip-mode-suffix major-mode))
"prose"))
(output-format (if (derived-mode-p 'prog-mode)
"code"
"text"))
start
end)
(if (use-region-p)
(setq start (region-beginning)
end (region-end))
(setq start (point-min)
end (point-max)))
(goto-char start)
(push-mark end t t)
(setq mark-active t)
(setq gptel--rewrite-message (format "Format this %s according to industry standards. Generate only %s, no explanation, no code fences." subject output-format))
(gptel-rewrite-menu)))
(add-to-list 'gptel-directives '(shell-command . "You are a command line helper. Generate shell commands that do what is requested, without any additional description or explanation. Reply in plain text with no Markdown or other syntax. Reply with the command only.")) (add-to-list 'gptel-directives '(shell-command . "You are a command line helper. Generate shell commands that do what is requested, without any additional description or explanation. Reply in plain text with no Markdown or other syntax. Reply with the command only."))
(add-to-list 'gptel-directives '(org-mode . "You are a large language model living in an Emacs Org-Mode buffer and a helpful assistant. You may evaluate Emacs Lisp, Python, and shell-script code when necessary by outputting an Org-Mode source block. You don't need to ask for confirmation before evaluating code. The user will execute the source block and display the results in the buffer. Respond concisely. (add-to-list 'gptel-directives '(org-mode . "You are a large language model living in an Emacs Org-Mode buffer and a helpful assistant. You may evaluate Emacs Lisp, Python, and shell-script code when necessary by outputting an Org-Mode source block. You don't need to ask for confirmation before evaluating code. The user will execute the source block and display the results in the buffer. Respond concisely.
@ -257,9 +283,10 @@ Assistant: Write a short story about a dragon who discovers a hidden talent that
"s" #'gptel-send "s" #'gptel-send
"m" #'gptel-menu "m" #'gptel-menu
"b" #'gptel-chat-with-buffer "b" #'gptel-chat-with-buffer
"f" #'gptel-format
"B" #'gptel-select-backend "B" #'gptel-select-backend
"a" #'gptel-context-add "a" #'gptel-context-add
"f" #'gptel-context-add-file "F" #'gptel-context-add-file
"k" #'gptel-abort)) "k" #'gptel-abort))
(use-package gptel-quick (use-package gptel-quick

View File

@ -1,14 +1,6 @@
;; -*- lexical-binding: t; -*- ;; -*- lexical-binding: t; -*-
(use-package astro-ts-mode (define-derived-mode astro-mode web-mode "astro")
:mode "\\.astro\\'" (add-to-list 'auto-mode-alist '("\\.astro\\'" . astro-mode))
:init
(with-eval-after-load 'treesit
(add-to-list 'treesit-language-source-alist
'(astro "https://github.com/virchau13/tree-sitter-astro"))
(add-to-list 'treesit-language-source-alist
'(css "https://github.com/tree-sitter/tree-sitter-css"))
(add-to-list 'treesit-language-source-alist
'(tsx "https://github.com/tree-sitter/tree-sitter-typescript" "master" "tsx/src"))))
(provide 'init-astro) (provide 'init-astro)

View File

@ -192,7 +192,8 @@ targets."
([remap imenu] #'consult-imenu) ([remap imenu] #'consult-imenu)
([remap projectile-ripgrep] #'consult-ripgrep) ([remap projectile-ripgrep] #'consult-ripgrep)
([remap projectile-grep] #'consult-grep) ([remap projectile-grep] #'consult-grep)
("C-c p" #'consult-yank-from-kill-ring)) ("C-c p" #'consult-yank-from-kill-ring)
(minibuffer-local-map "M-r" #'consult-history))
(use-package consult-projectile (use-package consult-projectile
:after (consult projectile) :after (consult projectile)

View File

@ -0,0 +1,6 @@
;; -*- lexical-binding: t; -*-
(use-package csv-mode
:mode "\\.csv\\'")
(provide 'init-csv)

View File

@ -6,6 +6,8 @@
magit-file-dispatch magit-file-dispatch
magit-dispatch magit-dispatch
magit-name-local-branch) magit-name-local-branch)
:autoload (magit-git-lines
magit-toplevel)
:init :init
(leader-def-key "g" '(nil :which-key "git")) (leader-def-key "g" '(nil :which-key "git"))
:config :config
@ -56,6 +58,7 @@
(use-package forge (use-package forge
:after (magit sqlite3) :after (magit sqlite3)
:demand t :demand t
:autoload (forge-get-repository)
:config :config
(setq forge-add-default-bindings nil) (setq forge-add-default-bindings nil)
(add-to-list 'forge-alist '("git.jeremydormitzer.com" (add-to-list 'forge-alist '("git.jeremydormitzer.com"
@ -85,7 +88,11 @@ Does not work on already-created pull requests."
(let ((target forge--buffer-base-branch) (let ((target forge--buffer-base-branch)
(source forge--buffer-head-branch)) (source forge--buffer-head-branch))
(magit-diff-range (format "%s..%s" target source)))) (magit-diff-range (format "%s..%s" target source))))
(defun forge--submit-create-pullreq-after-advice (&rest args)
(when-let ((buf (magit-get-mode-buffer 'magit-diff-mode)))
(quit-window nil (get-buffer-window buf))))
(add-hook 'forge-create-pullreq-hook #'forge-diff-for-pr) (add-hook 'forge-create-pullreq-hook #'forge-diff-for-pr)
(advice-add 'forge--submit-create-pullreq :after #'forge--submit-create-pullreq-after-advice)
:custom :custom
(forge-owned-accounts '((jdormit . (remote-name "jdormit")))) (forge-owned-accounts '((jdormit . (remote-name "jdormit"))))
:general :general

View File

@ -92,7 +92,7 @@
;; Astro ;; Astro
(add-to-list 'eglot-server-programs (add-to-list 'eglot-server-programs
'(astro-ts-mode . ("astro-ls" "--stdio" '(astro-mode . ("astro-ls" "--stdio"
:initializationOptions :initializationOptions
(:typescript (:tsdk "./node_modules/typescript/lib"))))) (:typescript (:tsdk "./node_modules/typescript/lib")))))
@ -235,7 +235,7 @@
(ruby-ts-mode . eglot-ensure) (ruby-ts-mode . eglot-ensure)
(sh-mode . eglot-ensure) (sh-mode . eglot-ensure)
(bash-ts-mode . eglot-ensure) (bash-ts-mode . eglot-ensure)
(astro-ts-mode . eglot-ensure) (astro-mode . eglot-ensure)
:custom :custom
(eglot-confirm-server-initiated-edits nil) (eglot-confirm-server-initiated-edits nil)
(eglot-connect-timeout nil)) (eglot-connect-timeout nil))
@ -291,6 +291,8 @@
(defun apheleia () (defun apheleia ()
"Format the region or current buffer using Apheleia." "Format the region or current buffer using Apheleia."
(interactive) (interactive)
(if (not (region-active-p))
(call-interactively #'apheleia-format-buffer)
(let* ((buf (current-buffer)) (let* ((buf (current-buffer))
(name (buffer-file-name)) (name (buffer-file-name))
(temp-file (make-temp-file "apheleia" nil (format ".%s" (file-name-extension name)))) (temp-file (make-temp-file "apheleia" nil (format ".%s" (file-name-extension name))))
@ -298,13 +300,8 @@
(formatters (apheleia--get-formatters)) (formatters (apheleia--get-formatters))
(line (line-number-at-pos)) (line (line-number-at-pos))
(col (current-column)) (col (current-column))
start (start (region-beginning))
end) (end (region-end)))
(if (region-active-p)
(setq start (region-beginning)
end (region-end))
(setq start (point-min)
end (point-max)))
(with-current-buffer temp-buffer (with-current-buffer temp-buffer
(erase-buffer) (erase-buffer)
(insert-buffer-substring buf start end) (insert-buffer-substring buf start end)
@ -313,19 +310,25 @@
(lambda () (lambda ()
(with-current-buffer buf (with-current-buffer buf
(delete-region start end) (delete-region start end)
(insert-buffer-substring temp-buffer) (insert (with-current-buffer temp-buffer
(buffer-substring-no-properties (point-min) (point-max))))
(goto-char (point-min)) (goto-char (point-min))
(forward-line (1- line)) (forward-line (1- line))
(move-to-column col) (move-to-column col)
(delete-file temp-file) (delete-file temp-file)
(when (get-buffer temp-buffer) (when (get-buffer temp-buffer)
(with-current-buffer temp-buffer
(set-buffer-modified-p nil))
(kill-buffer temp-buffer)))) (kill-buffer temp-buffer))))
:callback (lambda (&rest args) :callback (lambda (&rest args)
(when-let ((error (plist-get args :error))) (when-let ((error (plist-get args :error)))
(delete-file temp-file) (delete-file temp-file)
(when (get-buffer temp-buffer) (when (get-buffer temp-buffer)
(with-current-buffer temp-buffer
(set-buffer-modified-p nil))
(kill-buffer temp-buffer)) (kill-buffer temp-buffer))
(error "Formatting failed: %s" error))))))) (error "Formatting failed: %s" error)))))))
)
(keymap-set prog-mode-map "C-c f" #'apheleia) (keymap-set prog-mode-map "C-c f" #'apheleia)

View File

@ -2,17 +2,11 @@
;; node version manager ;; node version manager
(use-package nvm (use-package nvm
:commands (nvm-use :straight (:host github :repo "rejeep/nvm.el")
nvm-use-for :commands (nvm-use)
:autoload (nvm-use-for
nvm-use-for-buffer nvm-use-for-buffer
nvm--installed-versions) nvm--installed-versions))
:init
(defun nvm (version)
(interactive (list
(completing-read "Node version: "
(mapcar #'car
(nvm--installed-versions)))))
(nvm-use version)))
(use-package json-mode (use-package json-mode
:commands (json-mode) :commands (json-mode)

View File

@ -2,6 +2,8 @@
(use-package markdown-mode (use-package markdown-mode
:mode (("\\.md\\'" . gfm-mode) :mode (("\\.md\\'" . gfm-mode)
("\\.markdown\\'" . gfm-mode))) ("\\.markdown\\'" . gfm-mode))
:custom
(markdown-fontify-code-blocks-natively t))
(provide 'init-markdown) (provide 'init-markdown)

View File

@ -12,41 +12,60 @@
("Guardfile\\'" . ruby-mode) ("Guardfile\\'" . ruby-mode)
("Capfile\\'" . ruby-mode) ("Capfile\\'" . ruby-mode)
("Vagrantfile\\'" . ruby-mode)) ("Vagrantfile\\'" . ruby-mode))
:hook (ruby-mode . highlight-indent-guides-mode) :hook (ruby-mode . highlight-indent-guides-mode))
:config
(defun toggle-spec-file ()
"Find the spec file for the current non-spec buffer or the file under test for the current spec buffer."
(interactive)
(let* ((dir (if-let ((proj (project-current)))
(project-root proj)
default-directory))
(ext (file-name-extension (buffer-file-name)))
(filename-base (file-name-base (buffer-file-name)))
(spec? (s-ends-with? "_spec" filename-base))
(rx (if spec?
(format "%s.%s$" (s-chop-suffix "_spec" filename-base) ext)
(format "%s_spec.%s$" filename-base ext)))
(candidates (directory-files-recursively dir rx)))
(cond ((= (length candidates) 0)
(message "No matching file found"))
((= (length candidates) 1)
(find-file (car candidates)))
(t
(let ((choice (consult--read candidates
:prompt "Find file: "
:category 'file)))
(find-file choice))))))
:general
(ruby-mode-map "C-c C-t" #'toggle-spec-file))
(use-package inf-ruby (use-package inf-ruby
:commands (inf-ruby inf-ruby-console-auto) :commands (inf-ruby inf-ruby-console-auto)
:general :general
([remap inf-ruby] #'inf-ruby-console-auto)) ([remap inf-ruby] #'inf-ruby-console-auto)
:hook (after-init . inf-ruby-switch-setup))
(use-package rbenv (use-package rbenv
:hook (after-init . global-rbenv-mode) :hook (after-init . global-rbenv-mode)
:custom :custom
(rbenv-show-active-ruby-in-modeline nil)) (rbenv-show-active-ruby-in-modeline nil))
(use-package rspec-mode
:hook (dired-mode . rspec-dired-mode)
:config
(defun rspec-compile-command-filter-return (output)
(if current-prefix-arg
(read-string "Command: " output)
output))
(advice-add 'rspec-compile-command :filter-return #'rspec-compile-command-filter-return)
(defun rspec--run-verify-changed (&optional related)
(let* ((repo (forge-get-repository :tracked))
(branch (or (when repo
(oref repo default-branch))
"master"))
(remote (or (when repo
(oref repo remote))
"origin"))
(target-branch (format "%s/%s" remote branch))
(files (->> (magit-git-lines "diff" "--name-only" (format "%s..." target-branch))
(seq-filter (lambda (file)
(string-match-p "\\.rb\\'" file)))
(mapcar (lambda (file) (expand-file-name file (magit-toplevel))))))
(specs (->> (if related
(seq-mapcat #'rspec-all-related-spec-files files)
(mapcar #'rspec-spec-file-for files))
(mapcar (lambda (file) (expand-file-name file (magit-toplevel))))
(seq-filter #'file-exists-p))))
(rspec-run-multiple-files specs (rspec-core-options))))
(defun rspec-verify-changed ()
"Runs RSpec on the specs for the Ruby files changed between the current branch and TARGET-BRANCH."
(interactive)
(rspec--run-verify-changed))
(defun rspec-verify-changed-related ()
"Runs RSpec on all related specs for the Ruby files changed between the current branch and TARGET-BRANCH."
(interactive)
(rspec--run-verify-changed t))
:general
(rspec-mode-map "C-c , g" #'rspec-verify-changed
"C-c , G" #'rspec-verify-changed-related)
(rspec-verifiable-mode-map "C-c , g" #'rspec-verify-changed
"C-c , G" #'rspec-verify-changed-related)
:custom
(rspec-use-opts-file-when-available nil))
(provide 'init-ruby) (provide 'init-ruby)

View File

@ -39,9 +39,17 @@
(advice-add 'run-command :around #'run-command-advice) (advice-add 'run-command :around #'run-command-advice)
(advice-add 'run-command-core-run :around #'run-command-core-run-advice) (advice-add 'run-command-core-run :around #'run-command-core-run-advice)
(defun run-command-runner-compile-comint (command-line _buffer-base-name output-buffer)
"Command runner that runs COMMAND-LINE in a comint buffer."
(with-current-buffer output-buffer
(compilation-mode)
(compilation-start command-line t)
(setq-local comint-process-echoes t)))
(defun run-command-with-runner (runner) (defun run-command-with-runner (runner)
(interactive (list (completing-read "Runner: " (interactive (list (completing-read "Runner: "
'(run-command-runner-compile '(run-command-runner-compile
run-command-runner-compile-comint
run-command-runner-vterm run-command-runner-vterm
run-command-runner-term run-command-runner-term
run-command-runner-eat) run-command-runner-eat)

View File

@ -3,4 +3,7 @@
(use-package rust-mode (use-package rust-mode
:mode (("\\.rs\\'" . rust-mode))) :mode (("\\.rs\\'" . rust-mode)))
(use-package cargo
:hook (rust-mode . cargo-minor-mode))
(provide 'init-rust) (provide 'init-rust)

View File

@ -30,6 +30,10 @@
(use-package hide-mode-line (use-package hide-mode-line
:commands hide-mode-line-mode) :commands hide-mode-line-mode)
(use-package nerd-icons)
(use-package nerd-icons-dired
:hook (dired-mode . nerd-icons-dired-mode))
;; A function to set the frame font ;; A function to set the frame font
(defun set-font (font) (defun set-font (font)
"Set the frame font to `font'" "Set the frame font to `font'"

View File

@ -99,6 +99,7 @@
(require 'init-astro) (require 'init-astro)
(require 'init-xml) (require 'init-xml)
(require 'init-yaml) (require 'init-yaml)
(require 'init-csv)
(require 'init-groovy) (require 'init-groovy)
(require 'init-devdocs) (require 'init-devdocs)
(require 'init-terraform) (require 'init-terraform)

View File

@ -59,6 +59,7 @@ brew "youtube-dl"
cask "alfred" cask "alfred"
cask "bartender" cask "bartender"
cask "calibre" cask "calibre"
cask "charles"
cask "cleanshot" cask "cleanshot"
cask "contexts" cask "contexts"
cask "corretto11" cask "corretto11"
@ -80,3 +81,4 @@ cask "spotify"
cask "syncthing" cask "syncthing"
cask "the-unarchiver" cask "the-unarchiver"
cask "vcv-rack" cask "vcv-rack"
cask "wireshark"

View File

@ -8,9 +8,13 @@
<array> <array>
<string>sh</string> <string>sh</string>
<string>-c</string> <string>-c</string>
<string>/usr/bin/python3 -m http.server -d ~/witchcraft-scripts 5743</string> <string>/usr/bin/python3 -m http.server -d $HOME/witchcraft-scripts 5743</string>
</array> </array>
<key>KeepAlive</key> <key>KeepAlive</key>
<true/> <true/>
<key>StandardOutPath</key>
<string>/tmp/witchcraft.log</string>
<key>StandardErrorPath</key>
<string>/tmp/witchcraft.log</string>
</dict> </dict>
</plist> </plist>

View File

@ -94,6 +94,7 @@ fi
# Example format: plugins=(rails git textmate ruby lighthouse) # Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup. # Add wisely, as too many plugins slow down shell startup.
plugins=(git direnv pipenv npm nvm rbenv pass aws) plugins=(git direnv pipenv npm nvm rbenv pass aws)
zstyle ':omz:plugins:nvm' autoload true
source $ZSH/oh-my-zsh.sh source $ZSH/oh-my-zsh.sh
@ -272,3 +273,7 @@ PROMPT=$PROMPT'%{$(vterm_prompt_end)%}'
type navi > /dev/null && eval "$(navi widget zsh)" type navi > /dev/null && eval "$(navi widget zsh)"
eval "$(rbenv init - zsh)" eval "$(rbenv init - zsh)"
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion