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:
parent
b991af552c
commit
ec8ae0bedc
9 changed files with 183 additions and 5 deletions
|
@ -39,6 +39,7 @@
|
||||||
(popup ; tame sudden yet inevitable temporary windows
|
(popup ; tame sudden yet inevitable temporary windows
|
||||||
+all ; catch all popups that start with an asterix
|
+all ; catch all popups that start with an asterix
|
||||||
+defaults) ; default popup rules
|
+defaults) ; default popup rules
|
||||||
|
;pretty-code ; replace bits of code with pretty symbols
|
||||||
;tabbar ; FIXME an (incomplete) tab bar for Emacs
|
;tabbar ; FIXME an (incomplete) tab bar for Emacs
|
||||||
;unicode ; extended unicode support for various languages
|
;unicode ; extended unicode support for various languages
|
||||||
vi-tilde-fringe ; fringe tildes to mark beyond EOB
|
vi-tilde-fringe ; fringe tildes to mark beyond EOB
|
||||||
|
|
|
@ -60,6 +60,22 @@ compilation database is present in the project.")
|
||||||
:config
|
:config
|
||||||
(set-electric! '(c-mode c++-mode objc-mode java-mode) :chars '(?\n ?\}))
|
(set-electric! '(c-mode c++-mode objc-mode java-mode) :chars '(?\n ?\}))
|
||||||
|
|
||||||
|
(set-pretty-symbols! '(c-mode-hook c++-mode-hook)
|
||||||
|
;; Functional
|
||||||
|
;; :def "void "
|
||||||
|
;; Types
|
||||||
|
:null "nullptr"
|
||||||
|
:true "true" :false "false"
|
||||||
|
:int "int" :float "float"
|
||||||
|
:str "std::string"
|
||||||
|
:bool "bool"
|
||||||
|
;; Flow
|
||||||
|
:not "!"
|
||||||
|
:and "&&" :or "||"
|
||||||
|
:for "for"
|
||||||
|
:return "return"
|
||||||
|
:yield "#require")
|
||||||
|
|
||||||
;;; Better fontification (also see `modern-cpp-font-lock')
|
;;; Better fontification (also see `modern-cpp-font-lock')
|
||||||
(add-hook 'c-mode-common-hook #'rainbow-delimiters-mode)
|
(add-hook 'c-mode-common-hook #'rainbow-delimiters-mode)
|
||||||
(add-hook! '(c-mode-hook c++-mode-hook)
|
(add-hook! '(c-mode-hook c++-mode-hook)
|
||||||
|
|
|
@ -6,7 +6,16 @@
|
||||||
(after! elm-mode
|
(after! elm-mode
|
||||||
(add-hook 'elm-mode-hook #'rainbow-delimiters-mode)
|
(add-hook 'elm-mode-hook #'rainbow-delimiters-mode)
|
||||||
(set-company-backend! 'elm-mode 'company-elm)
|
(set-company-backend! 'elm-mode 'company-elm)
|
||||||
(set-repl-handler! 'elm-mode #'run-elm-interactive))
|
(set-repl-handler! 'elm-mode #'run-elm-interactive)
|
||||||
|
(set-pretty-symbols! 'elm-mode
|
||||||
|
:null "null"
|
||||||
|
:true "true" :false "false"
|
||||||
|
:int "Int" :str "String"
|
||||||
|
:float "Float"
|
||||||
|
:bool "Bool"
|
||||||
|
|
||||||
|
:not "not"
|
||||||
|
:and "&&" :or "||"))
|
||||||
|
|
||||||
|
|
||||||
(def-package! flycheck-elm
|
(def-package! flycheck-elm
|
||||||
|
|
|
@ -8,6 +8,9 @@
|
||||||
(set-lookup-handlers! 'emacs-lisp-mode :documentation 'info-lookup-symbol)
|
(set-lookup-handlers! 'emacs-lisp-mode :documentation 'info-lookup-symbol)
|
||||||
(set-docset! '(lisp-mode emacs-lisp-mode) "Emacs Lisp")
|
(set-docset! '(lisp-mode emacs-lisp-mode) "Emacs Lisp")
|
||||||
|
|
||||||
|
(set-pretty-symbols! 'emacs-lisp-mode
|
||||||
|
:lambda "lambda")
|
||||||
|
|
||||||
(set-rotate-patterns! 'emacs-lisp-mode
|
(set-rotate-patterns! 'emacs-lisp-mode
|
||||||
:symbols '(("t" "nil")
|
:symbols '(("t" "nil")
|
||||||
("let" "let*")
|
("let" "let*")
|
||||||
|
@ -31,8 +34,6 @@
|
||||||
(font-lock-add-keywords
|
(font-lock-add-keywords
|
||||||
nil `(;; Highlight custom Doom cookies
|
nil `(;; Highlight custom Doom cookies
|
||||||
("^;;;###\\(autodef\\|if\\)[ \n]" (1 font-lock-warning-face t))
|
("^;;;###\\(autodef\\|if\\)[ \n]" (1 font-lock-warning-face t))
|
||||||
;; Display "lambda" as λ
|
|
||||||
("(\\(lambda\\)" (1 (ignore (compose-region (match-beginning 1) (match-end 1) ?λ #'decompose-region))))
|
|
||||||
;; Highlight doom/module functions
|
;; Highlight doom/module functions
|
||||||
("\\(^\\|\\s-\\|,\\)(\\(\\(doom\\|\\+\\)[^) ]+\\|[^) ]+!\\)[) \n]" (2 font-lock-keyword-face)))))
|
("\\(^\\|\\s-\\|,\\)(\\(\\(doom\\|\\+\\)[^) ]+\\|[^) ]+!\\)[) \n]" (2 font-lock-keyword-face)))))
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,23 @@
|
||||||
;;; lang/javascript/config.el -*- lexical-binding: t; -*-
|
;;; lang/javascript/config.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
|
(after! (:any js2-mode web-mode)
|
||||||
|
(set-pretty-symbols! '(js2-mode web-mode)
|
||||||
|
'(;; Functional
|
||||||
|
:def "function"
|
||||||
|
:lambda "() =>"
|
||||||
|
:composition "compose"
|
||||||
|
;; Types
|
||||||
|
:null "null"
|
||||||
|
:true "true" :false "false"
|
||||||
|
;; Flow
|
||||||
|
:not "!"
|
||||||
|
:and "&&" :or "||"
|
||||||
|
:for "for"
|
||||||
|
:return "return"
|
||||||
|
;; Other
|
||||||
|
:yield "import")))
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; Major modes
|
;; Major modes
|
||||||
;;
|
;;
|
||||||
|
@ -66,7 +84,23 @@
|
||||||
(after! typescript-mode
|
(after! typescript-mode
|
||||||
(add-hook! 'typescript-mode-hook #'(flycheck-mode rainbow-delimiters-mode))
|
(add-hook! 'typescript-mode-hook #'(flycheck-mode rainbow-delimiters-mode))
|
||||||
(set-electric! 'typescript-mode
|
(set-electric! 'typescript-mode
|
||||||
:chars '(?\} ?\)) :words '("||" "&&")))
|
:chars '(?\} ?\)) :words '("||" "&&"))
|
||||||
|
(set-pretty-symbols! 'typescript-mode
|
||||||
|
;; Functional
|
||||||
|
:def "function"
|
||||||
|
:lambda "() =>"
|
||||||
|
:composition "compose"
|
||||||
|
;; Types
|
||||||
|
:null "null"
|
||||||
|
:true "true" :false "false"
|
||||||
|
:int "number"
|
||||||
|
:str "string"
|
||||||
|
:bool "boolean"
|
||||||
|
;; Flow
|
||||||
|
:not "!"
|
||||||
|
:and "&&" :or "||"
|
||||||
|
:for "for"
|
||||||
|
:return "return" :yield "import"))
|
||||||
|
|
||||||
|
|
||||||
;; `coffee-mode'
|
;; `coffee-mode'
|
||||||
|
|
|
@ -48,7 +48,8 @@
|
||||||
+org|setup-popups-rules
|
+org|setup-popups-rules
|
||||||
+org|setup-agenda
|
+org|setup-agenda
|
||||||
+org|setup-keybinds
|
+org|setup-keybinds
|
||||||
+org|setup-hacks))
|
+org|setup-hacks
|
||||||
|
+org|setup-pretty-code))
|
||||||
|
|
||||||
(add-hook! 'org-mode-hook
|
(add-hook! 'org-mode-hook
|
||||||
#'(doom|disable-line-numbers ; org doesn't really need em
|
#'(doom|disable-line-numbers ; org doesn't really need em
|
||||||
|
@ -151,6 +152,13 @@ unfold to point on startup."
|
||||||
((size . 0.2))
|
((size . 0.2))
|
||||||
((quit) (select . t))))))
|
((quit) (select . t))))))
|
||||||
|
|
||||||
|
(defun +org|setup-pretty-code ()
|
||||||
|
"Setup the default pretty symbols for"
|
||||||
|
(set-pretty-symbols! 'org-mode
|
||||||
|
:name "#+NAME:"
|
||||||
|
:src_block "#+BEGIN_SRC"
|
||||||
|
:src_block_end "#+END_SRC"))
|
||||||
|
|
||||||
(defun +org|setup-ui ()
|
(defun +org|setup-ui ()
|
||||||
"Configures the UI for `org-mode'."
|
"Configures the UI for `org-mode'."
|
||||||
(setq-default
|
(setq-default
|
||||||
|
|
|
@ -28,6 +28,24 @@ is loaded.")
|
||||||
(set-electric! 'python-mode :chars '(?:))
|
(set-electric! 'python-mode :chars '(?:))
|
||||||
(set-repl-handler! 'python-mode #'+python/repl)
|
(set-repl-handler! 'python-mode #'+python/repl)
|
||||||
|
|
||||||
|
(set-pretty-symbols! 'python-mode
|
||||||
|
;; Functional
|
||||||
|
:def "def"
|
||||||
|
:lambda "lambda"
|
||||||
|
;; Types
|
||||||
|
:null "None"
|
||||||
|
:true "True" :false "False"
|
||||||
|
:int "int" :str "str"
|
||||||
|
:float "float"
|
||||||
|
:bool "bool"
|
||||||
|
:tuple "tuple"
|
||||||
|
;; Flow
|
||||||
|
:not "not"
|
||||||
|
:in "in" :not-in "not in"
|
||||||
|
:and "and" :or "or"
|
||||||
|
:for "for"
|
||||||
|
:return "return" :yield "yield")
|
||||||
|
|
||||||
(when (executable-find "ipython")
|
(when (executable-find "ipython")
|
||||||
(setq python-shell-interpreter "ipython"
|
(setq python-shell-interpreter "ipython"
|
||||||
python-shell-interpreter-args "-i --simple-prompt --no-color-info"
|
python-shell-interpreter-args "-i --simple-prompt --no-color-info"
|
||||||
|
|
86
modules/ui/pretty-code/autoload.el
Normal file
86
modules/ui/pretty-code/autoload.el
Normal 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))))
|
5
modules/ui/pretty-code/packages.el
Normal file
5
modules/ui/pretty-code/packages.el
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
;; -*- no-byte-compile: t; -*-
|
||||||
|
;;; ui/pretty-code/packages.el
|
||||||
|
|
||||||
|
(package! prettify-utils
|
||||||
|
:recipe (:fetcher github :repo "Ilazki/prettify-utils.el"))
|
Loading…
Add table
Add a link
Reference in a new issue