Commit 01d6507c1082

Vincent Demeester <vincent@sbr.pm>
2025-02-18 09:38:14
tools/emacs: add copilot-chat integration and custom prompts
This commit introduces the integration of copilot-chat into the Emacs configuration. It includes custom prompts and key bindings for various copilot-chat actions. Additionally, it defines functions for copying source blocks and displaying a transient menu for copilot-chat actions. *Generated by copilot ๐Ÿ™ƒ* Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent 956031c
Changed files (1)
tools
tools/emacs/config/programming-config.el
@@ -189,6 +189,101 @@
   (copilot-max-char -1)
   (copile-indent-offset-warning-disable t))
 
+(setq copilot-chat-commit-prompt "Here is the result of running `git diff
+--cached`. Based on this, suggest a **Conventional Commit message**. Ensure the
+message includes both a clear title describing the change and make sure a body
+explaining the change, do not invent anything new just try to comprehend the
+diff and explain it.
+
+- Do not add extra markdown formatting.
+- Always make sure the commit message is in markdown format.
+- Do not include any additional text outside the commit message
+- Make sure the title is a max of 50 character long and not more. 
+- The summaries needs to be wrapped to 80 character long and not more (or break
+  the line).
+
+# Conventional Commits 1.0.0
+
+## Summary
+
+Conventional Commits is a specification for commit messages that follows
+these rules to ensure clarity and consistency:
+
+### Format
+<type>[optional scope]: <description>
+
+[body]
+
+### Types
+1. **fix:** A bug fix correlating to a PATCH version.
+2. **feat:** A new feature correlating to a MINOR version.
+
+Other types include:  
+- **build:** Changes to build systems or dependencies.  
+- **chore:** Maintenance tasks (e.g., dependency updates).  
+- **ci:** Changes to CI configuration.  
+- **refactor:** Code changes not adding features or fixing bugs.  
+- **test:** Changes to or addition of tests.  
+
+Here is the result of `git diff --cached`:")
+
+(use-package copilot-chat
+  :bind
+  (:map copilot-chat-prompt-mode-map
+        ("C-M-w" . my-copilot-chat-copy-source-block)
+        ("C-q" . delete-window))
+  :config
+  (setq copilot-chat-prompts copilot-chat-markdown-prompt)
+  (defun my-copilot-chat-copy-source-block ()
+    "Copy the source block at point to kill ring."
+    (interactive)
+    (let* ((temp-buffer-name "*copilot-kr-temp*"))
+      (with-current-buffer (get-buffer-create temp-buffer-name)
+        (erase-buffer)
+        (copilot-chat-yank)
+        (kill-ring-save (point-min) (point-max))
+        (kill-buffer))
+      (message "Source block copied to kill ring")))
+
+  (defun copilot-chat-prompt-transient-menu ()
+    "Show a transient menu for Copilot Chat actions."
+    (interactive)
+    (unless (use-region-p)
+      (mark-defun))
+    (transient-define-prefix copilot-chat-prompt-menu ()
+      "Copilot Chat Menu"
+      ["Copilot Chat Actions"
+       ["Actions"
+        ("c" "Commit" copilot-chat-insert-commit-message)
+        ("o" "Optimize" copilot-chat-optimize)
+        ("r" "Review" copilot-chat-review)
+        ("f" "Fix" copilot-chat-fix)
+        ("e" "Explain" copilot-chat-explain)
+        ("d" "Doc" copilot-chat-doc)]
+       ["Commands"
+        ("d" "Display chat" copilot-chat-display)
+        ("h" "Hide chat" copilot-chat-hide)
+        ("R" "Reset & reopen" (lambda ()
+                                (interactive)
+                                (copilot-chat-reset)
+                                (copilot-chat-display)))
+        ("x" "Reset" copilot-chat-reset)
+        ("g" "Go to buffer" copilot-chat-switch-to-buffer)
+        ("M" "Set model" copilot-chat-set-model)
+        ("q" "Quit" transient-quit-one)]
+       ["Actions"
+        ("p" "Custom prompt" copilot-chat-custom-prompt-selection)
+        ("i" "Ask and insert" copilot-chat-ask-and-insert)
+        ("m" "Insert commit message" copilot-chat-insert-commit-message)
+        ("b" "Buffers" copilot-chat-transient-buffers)]
+       ["Data"
+        ("y" "Yank last code block" copilot-chat-yank)
+        ("s" "Send code to buffer" copilot-chat-send-to-buffer)]])
+    (copilot-chat-prompt-menu))
+  :after copilot
+  :commands
+  (copilot-chat-mode))
+
 
 (provide 'programming-config)
 ;;; programming-config.el ends here