Add :ui pretty-code & set-pretty-symbols! autodef

Along with defaults for C/C++, elm, elisp, js, typescript, web-mode, and
org-mode. Thanks to @ar1a for inspiration.
This commit is contained in:
Henrik Lissner 2018-06-16 19:32:25 +02:00
parent b991af552c
commit ec8ae0bedc
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
9 changed files with 183 additions and 5 deletions

View file

@ -0,0 +1,86 @@
;;; ui/pretty-code/autoload.el -*- lexical-binding: t; -*-
;;;###autoload
(defvar +pretty-code-enabled-modes
'(c++-mode-hook
c-mode-hook
elm-mode
emacs-lisp-mode
js2-mode
org-mode
python-mode
typescript-mode
web-mode)
"List of major modes in which `prettify-symbols-mode' should be enabled.")
;;;###autoload
(defvar +pretty-code-symbols
'(;; org
:name "»"
:src_block "»"
:src_block_end " "
;; Functional
:lambda "λ"
:def "ƒ"
:composition ""
;; Types
:null ""
:true "𝕋"
:false "𝔽"
:int ""
:float ""
:str "𝕊"
:bool "𝔹"
;; Flow
:not ""
:in ""
:not-in ""
:and ""
:or ""
:for ""
:some ""
:return ""
:yield ""
;; Other
:tuple ""
:pipe "")
"Options plist for `pretty-code-get-pairs'.")
;; When you get to the right edge, it goes back to how it normally prints
;;;###autoload
(setq prettify-symbols-unprettify-at-point 'right-edge)
;;;###autodef
(defun set-pretty-symbols! (modes &rest plist)
"Associates string patterns with icons in certain major-modes.
MODES is a major mode symbol or a list of them.
PLIST is a property list whose keys must match keys in `+pretty-code-symbols',
and whose values are strings representing the text to be replaced with that
symbol.
For example, the rule for emacs-lisp-mode is very simple:
(set-pretty-symbols! 'emacs-lisp-mode
:lambda \"lambda\")
This will replace any instances of \"lambda\" in emacs-lisp-mode with the symbol
assicated with :lambda in `+pretty-code-symbols'."
(declare (indent 1))
(dolist (mode (doom-enlist modes))
(let ((fn (intern (format "+pretty-code|init-%s" mode))))
(fset fn
(lambda ()
(when (and (eq major-mode mode)
(memq major-mode +pretty-code-enabled-modes))
(let (results prop icon)
(while plist
(let ((prop (pop plist))
(sym (pop plist)))
(when-let* ((icon (plist-get +pretty-code-symbols prop)))
(push (cons sym (prettify-utils-string icon))
results))))
(setq prettify-symbols-alist results))
(prettify-symbols-mode -1)
(prettify-symbols-mode +1))))
(add-hook (intern (format "%s-hook" mode)) fn))))