diff --git a/emacs/.emacs.d/config/init-ai.el b/emacs/.emacs.d/config/init-ai.el index c706c1a..0b62d61 100644 --- a/emacs/.emacs.d/config/init-ai.el +++ b/emacs/.emacs.d/config/init-ai.el @@ -21,6 +21,26 @@ (embark-general-map "?" #'gptel-quick)) +(defun gptel-commit-message () + "Generate a commit message via gptel." + (interactive) + (unless git-commit-mode + (user-error "Not in a git commit buffer!")) + (let* ((diff-buf (magit-get-mode-buffer 'magit-diff-mode)) + (diff (with-current-buffer diff-buf + (buffer-substring-no-properties + (point-min) + ;; Skip the last line, which is just the [back] button + (save-excursion + (goto-char (point-max)) + (forward-line -1) + (point))))) + (prompt (format "%s\n\nWrite a clear, concise commit message for this diff. The first line should succinctly summarize the changes made and should be no more than 50 characters. If additional context is needed, include it in an additional paragraph separate by a blank line from the first line." diff))) + (message "Generating commit message...") + (gptel-request prompt + :stream t + :system "You are an experienced software engineer writing a commit message."))) + (use-package llama :straight `(:local-repo ,(expand-file-name "packages/llama" user-emacs-directory) :type nil) :load-path "packages/llama"