Compare commits
No commits in common. "e2f027df579eb314e39e24adcd9766bf63a10a1f" and "6898a3e8e5d92d4757e01feed15ee147093d218a" have entirely different histories.
e2f027df57
...
6898a3e8e5
@ -5,34 +5,7 @@
|
|||||||
|
|
||||||
(use-package gptel
|
(use-package gptel
|
||||||
:commands (gptel-request)
|
:commands (gptel-request)
|
||||||
:init
|
|
||||||
;; Annoyingly, gptel fails to require gptel-context, so we have to do it manually
|
|
||||||
(autoload 'gptel-context-add "gptel-context")
|
|
||||||
(autoload 'gptel-context-add-file "gptel-context")
|
|
||||||
:config
|
:config
|
||||||
;; Default to creating a new buffer when invoking gptel
|
|
||||||
(defun gptel-before-advice (name &optional _ initial interactivep)
|
|
||||||
(interactive
|
|
||||||
(let* ((backend (default-value 'gptel-backend))
|
|
||||||
(backend-name
|
|
||||||
(generate-new-buffer-name (format "*%s*" (gptel-backend-name backend)))))
|
|
||||||
(list (read-buffer "Create or choose gptel buffer: "
|
|
||||||
backend-name nil ; DEFAULT and REQUIRE-MATCH
|
|
||||||
(lambda (b) ; PREDICATE
|
|
||||||
(buffer-local-value 'gptel-mode
|
|
||||||
(get-buffer (or (car-safe b) b)))))
|
|
||||||
(condition-case nil
|
|
||||||
(gptel--get-api-key
|
|
||||||
(gptel-backend-key backend))
|
|
||||||
((error user-error)
|
|
||||||
(setq gptel-api-key
|
|
||||||
(read-passwd
|
|
||||||
(format "%s API key: " backend-name)))))
|
|
||||||
(and (use-region-p)
|
|
||||||
(buffer-substring (region-beginning)
|
|
||||||
(region-end)))
|
|
||||||
t))))
|
|
||||||
(advice-add 'gptel :before #'gptel-before-advice)
|
|
||||||
(defvar gptel-backend-openai (gptel-make-openai "ChatGPT"
|
(defvar gptel-backend-openai (gptel-make-openai "ChatGPT"
|
||||||
:key #'gptel-api-key-from-auth-source
|
:key #'gptel-api-key-from-auth-source
|
||||||
:stream t
|
:stream t
|
||||||
|
@ -282,52 +282,10 @@
|
|||||||
;; Code formatting library
|
;; Code formatting library
|
||||||
(use-package apheleia
|
(use-package apheleia
|
||||||
:straight (apheleia :host github :repo "raxod502/apheleia")
|
:straight (apheleia :host github :repo "raxod502/apheleia")
|
||||||
:commands apheleia-format-buffer
|
|
||||||
:autoload apheleia--get-formatters
|
|
||||||
:config
|
:config
|
||||||
(add-to-list 'apheleia-mode-alist '(ruby-mode . (rubocop)))
|
(add-to-list 'apheleia-mode-alist '(ruby-mode . (rubocop)))
|
||||||
(add-to-list 'apheleia-mode-alist '(ruby-ts-mode . (rubocop))))
|
:general
|
||||||
|
(prog-mode-map "C-c f" #'apheleia-format-buffer))
|
||||||
(defun apheleia ()
|
|
||||||
"Format the region or current buffer using Apheleia."
|
|
||||||
(interactive)
|
|
||||||
(let* ((buf (current-buffer))
|
|
||||||
(name (buffer-file-name))
|
|
||||||
(temp-file (make-temp-file "apheleia" nil (format ".%s" (file-name-extension name))))
|
|
||||||
(temp-buffer (find-file-noselect temp-file))
|
|
||||||
(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)))
|
|
||||||
(with-current-buffer temp-buffer
|
|
||||||
(erase-buffer)
|
|
||||||
(insert-buffer-substring buf start end)
|
|
||||||
(write-file temp-file)
|
|
||||||
(apheleia-format-buffer formatters
|
|
||||||
(lambda ()
|
|
||||||
(with-current-buffer buf
|
|
||||||
(delete-region start end)
|
|
||||||
(insert-buffer-substring temp-buffer)
|
|
||||||
(goto-char (point-min))
|
|
||||||
(forward-line (1- line))
|
|
||||||
(move-to-column col)
|
|
||||||
(delete-file temp-file)
|
|
||||||
(when (get-buffer temp-buffer)
|
|
||||||
(kill-buffer temp-buffer))))
|
|
||||||
:callback (lambda (&rest args)
|
|
||||||
(when-let ((error (plist-get args :error)))
|
|
||||||
(delete-file temp-file)
|
|
||||||
(when (get-buffer temp-buffer)
|
|
||||||
(kill-buffer temp-buffer))
|
|
||||||
(error "Formatting failed: %s" error)))))))
|
|
||||||
|
|
||||||
(keymap-set prog-mode-map "C-c f" #'apheleia)
|
|
||||||
|
|
||||||
;; AI assistance
|
;; AI assistance
|
||||||
(use-package copilot
|
(use-package copilot
|
||||||
|
Loading…
Reference in New Issue
Block a user