Created
March 14, 2026 09:27
-
-
Save dvorka/98fe2addba2302213230fb5293f9f807 to your computer and use it in GitHub Desktop.
Conventional Commits for Emacs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; conventional-commits.el --- Commit with style and emojis | |
| (defvar ddd/commit-types | |
| '(("feat" . "π") | |
| ("fix" . "π") | |
| ("docs" . "π") | |
| ("style" . "π ") | |
| ("refactor" . "β»οΈ") | |
| ("test" . "π§ͺ") | |
| ("chore" . "π§Ή") | |
| ("build" . "ποΈ") | |
| ("ci" . "π€") | |
| ("perf" . "β‘") | |
| ("revert" . "βͺ")) | |
| "List of conventional commit types and their emojis.") | |
| (defun ddd/conventional-commit-insert () | |
| "Propts for commit details and inserts a conventional commit message at point." | |
| (interactive) | |
| (let* ((choices (mapcar (lambda (x) | |
| (format "%-10s %s" (car x) (cdr x))) | |
| ddd/commit-types)) | |
| (selection (completing-read "Select commit type: " choices nil t)) | |
| ;; Extract the type and emoji from the selection string | |
| (type (car (split-string selection))) | |
| (emoji (cadr (split-string selection))) | |
| ;; BREAK: (is-breaking (y-or-n-p "Is this a breaking change? ")) | |
| (scope (read-string "Scope (optional): ")) | |
| (subject (read-string "Subject: ")) | |
| (body (read-string "Body (optional): ")) | |
| ;; Logic for the "!" in breaking changes | |
| ;; BREAK: (breaking-mark (if is-breaking "!" "")) | |
| (breaking-mark "") | |
| (formatted-scope (if (string-empty-p scope) "" (format "(%s)" scope))) | |
| ;; Construct the header line | |
| (header (format "%s%s%s: %s %s" type formatted-scope breaking-mark emoji subject)) | |
| (full-msg header)) | |
| ;; BREAK: Add body or breaking change footer if needed | |
| ;;(when (or (not (string-empty-p body)) is-breaking) | |
| ;; (setq full-msg (concat full-msg "\n\n" body)) | |
| ;; (when is-breaking | |
| ;; (let ((break-desc (read-string "Breaking change description: "))) | |
| ;; (setq full-msg (concat full-msg "\n\nBREAKING CHANGE: " break-desc))))) | |
| ;; The "Magic" part: Insert at cursor | |
| (insert full-msg) | |
| (message "Commit message inserted!"))) | |
| ;; Bind it to C-c C-c | |
| (global-set-key (kbd "C-c C-c") 'ddd/conventional-commit-insert) | |
| (provide 'conventional-commits) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment