about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2021-01-02 22:51:31 -0600
committerCase Duckworth2021-01-02 22:51:31 -0600
commit17a116cd6c7d7a9bbe4394dc1f0965ca0fdfffff (patch)
tree4418d6856f0c0013ce1664cc788b66e56466afa0
parentEnable whitespace-mode (diff)
downloademacs-17a116cd6c7d7a9bbe4394dc1f0965ca0fdfffff.tar.gz
emacs-17a116cd6c7d7a9bbe4394dc1f0965ca0fdfffff.zip
Prettify symbols
-rw-r--r--config.org97
1 files changed, 97 insertions, 0 deletions
diff --git a/config.org b/config.org index c346ade..e0eed32 100644 --- a/config.org +++ b/config.org
@@ -1020,6 +1020,103 @@ For right now, I’m /just/ using Anzu – I don’t like parts of =isearch= but
1020 1020
1021* Programming 1021* Programming
1022 1022
1023** Prettify symbols
1024
1025*** A bit from Rasmus
1026
1027 from [[https://pank.eu/blog/pretty-babel-src-blocks.html#coderef-symbol][Rasmus Roulund]], via [[https://alhassy.github.io/emacs.d/index.html#Making-Block-Delimiters-Less-Intrusive][Musa Al-hassy]].
1028
1029 #+begin_src emacs-lisp
1030 (defvar-local rasmus/org-at-src-begin -1
1031 "Variable that holds whether last position was a ")
1032
1033 (defvar rasmus/ob-header-symbol ?☰
1034 "Symbol used for babel headers")
1035
1036 (defun rasmus/org-prettify-src--update ()
1037 (let ((case-fold-search t)
1038 (re "^[ \t]*#\\+begin_src[ \t]+[^ \f\t\n\r\v]+[ \t]*")
1039 found)
1040 (save-excursion
1041 (goto-char (point-min))
1042 (while (re-search-forward re nil t)
1043 (goto-char (match-end 0))
1044 (let ((args (org-trim
1045 (buffer-substring-no-properties (point)
1046 (line-end-position)))))
1047 (when (org-string-nw-p args)
1048 (let ((new-cell (cons args rasmus/ob-header-symbol)))
1049 (cl-pushnew new-cell prettify-symbols-alist :test #'equal)
1050 (cl-pushnew new-cell found :test #'equal)))))
1051 (setq prettify-symbols-alist
1052 (cl-set-difference prettify-symbols-alist
1053 (cl-set-difference
1054 (cl-remove-if-not
1055 (lambda (elm)
1056 (eq (cdr elm) rasmus/ob-header-symbol))
1057 prettify-symbols-alist)
1058 found :test #'equal)))
1059 ;; Clean up old font-lock-keywords.
1060 (font-lock-remove-keywords nil prettify-symbols--keywords)
1061 (setq prettify-symbols--keywords (prettify-symbols--make-keywords))
1062 (font-lock-add-keywords nil prettify-symbols--keywords)
1063 (while (re-search-forward re nil t)
1064 (font-lock-flush (line-beginning-position) (line-end-position))))))
1065
1066 (defun rasmus/org-prettify-src ()
1067 "Hide src options via `prettify-symbols-mode'.
1068
1069 `prettify-symbols-mode' is used because it has uncollpasing. It's
1070 may not be efficient."
1071 (let* ((case-fold-search t)
1072 (at-src-block (save-excursion
1073 (beginning-of-line)
1074 (looking-at "^[ \t]*#\\+begin_src[ \t]+[^ \f\t\n\r\v]+[ \t]*"))))
1075 ;; Test if we moved out of a block.
1076 (when (or (and rasmus/org-at-src-begin
1077 (not at-src-block))
1078 ;; File was just opened.
1079 (eq rasmus/org-at-src-begin -1))
1080 (rasmus/org-prettify-src--update))
1081 ;; Remove composition if at line; doesn't work properly.
1082 ;; (when at-src-block
1083 ;; (with-silent-modifications
1084 ;; (remove-text-properties (match-end 0)
1085 ;; (1+ (line-end-position))
1086 ;; '(composition))))
1087 (setq rasmus/org-at-src-begin at-src-block)))
1088
1089 (defun rasmus/org-prettify-symbols ()
1090 (mapc (apply-partially 'add-to-list 'prettify-symbols-alist)
1091 (cl-reduce 'append
1092 (mapcar (lambda (x) (list x (cons (upcase (car x)) (cdr x))))
1093 `(("#+begin_src" . ?✎) ;; ➤ 🖝 ➟ ➤ ✎
1094 ("#+end_src" . ?⏹) ;; □
1095 ("#+header:" . ,rasmus/ob-header-symbol)
1096 ("#+begin_quote" . ?»)
1097 ("#+end_quote" . ?«)))))
1098 (turn-on-prettify-symbols-mode)
1099 (add-hook 'post-command-hook 'rasmus/org-prettify-src t t))
1100 #+end_src
1101
1102*** Regular prettify-symbols-mode
1103
1104#+begin_src emacs-lisp
1105 (cuss prettify-symbols-unprettify-at-point 'right-edge
1106 "Unprettify a symbol when inside it or next to it.")
1107
1108 (defun acdw/org-mode-prettify ()
1109 "Prettify `org-mode'."
1110 (append '(("[ ]" . ?□) ("[X]" . ?☑) ("[-]" . ?◐)
1111 ("#begin_src" . ?🖬) ("#BEGIN_SRC" . ?🖬)
1112 ("#end_src" . ?■) ("#END_SRC" . ?■))
1113 prettify-symbols-alist))
1114
1115 (add-hook 'org-mode-hook #'acdw/org-mode-prettify)
1116
1117 (global-prettify-symbols-mode +1)
1118#+end_src
1119
1023** Parentheses 1120** Parentheses
1024 1121
1025*** Smart parentheses 1122*** Smart parentheses