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
:commands (gptel-request)
:autoload (gptel--strip-mode-suffix)
:init
;; Annoyingly, gptel fails to require gptel-context, so we have to do it manually
(autoload 'gptel-context-add "gptel-context")
@ -42,7 +43,11 @@
:stream t
:models '("llama3.1: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
gptel-model "gpt-4o")
(defun gptel-select-backend (backend)
@ -81,6 +86,27 @@
(when options-plist
(plist-put prompts-plist :options options-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 '(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
"m" #'gptel-menu
"b" #'gptel-chat-with-buffer
"f" #'gptel-format
"B" #'gptel-select-backend
"a" #'gptel-context-add
"f" #'gptel-context-add-file
"F" #'gptel-context-add-file
"k" #'gptel-abort))
(use-package gptel-quick

View File

@ -1,14 +1,6 @@
;; -*- lexical-binding: t; -*-
(use-package astro-ts-mode
:mode "\\.astro\\'"
: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"))))
(define-derived-mode astro-mode web-mode "astro")
(add-to-list 'auto-mode-alist '("\\.astro\\'" . astro-mode))
(provide 'init-astro)

View File

@ -192,7 +192,8 @@ targets."
([remap imenu] #'consult-imenu)
([remap projectile-ripgrep] #'consult-ripgrep)
([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
: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-dispatch
magit-name-local-branch)
:autoload (magit-git-lines
magit-toplevel)
:init
(leader-def-key "g" '(nil :which-key "git"))
:config
@ -56,6 +58,7 @@
(use-package forge
:after (magit sqlite3)
:demand t
:autoload (forge-get-repository)
:config
(setq forge-add-default-bindings nil)
(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)
(source forge--buffer-head-branch))
(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)
(advice-add 'forge--submit-create-pullreq :after #'forge--submit-create-pullreq-after-advice)
:custom
(forge-owned-accounts '((jdormit . (remote-name "jdormit"))))
:general

View File

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

View File

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

View File

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

View File

@ -12,41 +12,60 @@
("Guardfile\\'" . ruby-mode)
("Capfile\\'" . ruby-mode)
("Vagrantfile\\'" . ruby-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))
:hook (ruby-mode . highlight-indent-guides-mode))
(use-package inf-ruby
:commands (inf-ruby inf-ruby-console-auto)
: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
:hook (after-init . global-rbenv-mode)
:custom
(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)

View File

@ -39,9 +39,17 @@
(advice-add 'run-command :around #'run-command-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)
(interactive (list (completing-read "Runner: "
'(run-command-runner-compile
run-command-runner-compile-comint
run-command-runner-vterm
run-command-runner-term
run-command-runner-eat)

View File

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

View File

@ -30,6 +30,10 @@
(use-package hide-mode-line
: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
(defun set-font (font)
"Set the frame font to `font'"

View File

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

View File

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

View File

@ -8,9 +8,13 @@
<array>
<string>sh</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>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/tmp/witchcraft.log</string>
<key>StandardErrorPath</key>
<string>/tmp/witchcraft.log</string>
</dict>
</plist>

View File

@ -94,6 +94,7 @@ fi
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git direnv pipenv npm nvm rbenv pass aws)
zstyle ':omz:plugins:nvm' autoload true
source $ZSH/oh-my-zsh.sh
@ -272,3 +273,7 @@ PROMPT=$PROMPT'%{$(vterm_prompt_end)%}'
type navi > /dev/null && eval "$(navi widget 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