Skip to content

Instantly share code, notes, and snippets.

@dvorka
Created March 14, 2026 09:27
Show Gist options
  • Select an option

  • Save dvorka/98fe2addba2302213230fb5293f9f807 to your computer and use it in GitHub Desktop.

Select an option

Save dvorka/98fe2addba2302213230fb5293f9f807 to your computer and use it in GitHub Desktop.
Conventional Commits for Emacs
;; 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