Skip to content

Instantly share code, notes, and snippets.

@simmsb
Last active May 29, 2018 16:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simmsb/ed3a2265e9fabf39c46767ba0c65a85a to your computer and use it in GitHub Desktop.
Save simmsb/ed3a2265e9fabf39c46767ba0c65a85a to your computer and use it in GitHub Desktop.
;;; pretty-magit.el --- hip up your emacs
;; Author: I dont know
;; Version: 20180122
(require 'dash)
(require 'ivy) ; for leader-prompts only
(require 'evil) ; Remove evil-insert at end if not using evil
;;; Pretty-magit
(setq pretty-magit-alist nil)
(setq pretty-magit-prompt nil)
;;;###autoload
(defmacro pretty-magit (WORD ICON PROPS &optional NO-PROMPT?)
"Replace sanitized WORD with ICON, PROPS and by default add to prompts."
`(progn
(add-to-list 'pretty-magit-alist
(list (rx bow (group ,WORD (eval (if ,NO-PROMPT? "" ":"))))
,ICON ',PROPS))
(unless ,NO-PROMPT?
(add-to-list 'pretty-magit-prompt (concat ,WORD ": ")))))
;;;###autoload
(defun add-magit-faces ()
"Add face properties and compose symbols for buffer from pretty-magit."
(interactive)
(with-silent-modifications
(--each pretty-magit-alist
(-let (((rgx icon props) it))
(save-excursion
(goto-char (point-min))
(while (search-forward-regexp rgx nil t)
(compose-region
(match-beginning 1) (match-end 1) icon)
(when props
(add-face-text-property
(match-beginning 1) (match-end 1) props))))))))
;;; Leader Prompts
(setq use-magit-commit-prompt-p nil)
(defun use-magit-commit-prompt (&rest args)
(setq use-magit-commit-prompt-p t))
;;;###autoload
(defun magit-commit-prompt ()
"Magit prompt and insert commit header with faces."
(interactive)
(when use-magit-commit-prompt-p
(setq use-magit-commit-prompt-p nil)
(insert (ivy-read "Commit Type " pretty-magit-prompt
:require-match t :sort t :preselect "Add: "))
(add-magit-faces)
(evil-insert 1)))
;;; Hooks
(remove-hook 'git-commit-setup-hook 'with-editor-usage-message)
(add-hook 'git-commit-setup-hook 'magit-commit-prompt)
(advice-add 'magit-status :after 'add-magit-faces)
(advice-add 'magit-refresh-buffer :after 'add-magit-faces)
(advice-add 'magit-commit :after 'use-magit-commit-prompt)
(provide 'pretty-magit)
;;; pretty-magit.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment