about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--config.org90
1 files changed, 1 insertions, 89 deletions
diff --git a/config.org b/config.org index 2b83bc7..a239658 100644 --- a/config.org +++ b/config.org
@@ -1046,99 +1046,11 @@ For right now, I’m /just/ using Anzu – I don’t like parts of =isearch= but
1046 1046
1047** Prettify symbols 1047** Prettify symbols
1048 1048
1049*** A bit from Rasmus
1050
1051 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]].
1052
1053 #+begin_src emacs-lisp
1054 (defvar-local rasmus/org-at-src-begin -1
1055 "Variable that holds whether last position was a ")
1056
1057 (defvar rasmus/ob-header-symbol ?☰
1058 "Symbol used for babel headers")
1059
1060 (defun rasmus/org-prettify-src--update ()
1061 (let ((case-fold-search t)
1062 (re "^[ \t]*#\\+begin_src[ \t]+[^ \f\t\n\r\v]+[ \t]*")
1063 found)
1064 (save-excursion
1065 (goto-char (point-min))
1066 (while (re-search-forward re nil t)
1067 (goto-char (match-end 0))
1068 (let ((args (org-trim
1069 (buffer-substring-no-properties (point)
1070 (line-end-position)))))
1071 (when (org-string-nw-p args)
1072 (let ((new-cell (cons args rasmus/ob-header-symbol)))
1073 (cl-pushnew new-cell prettify-symbols-alist :test #'equal)
1074 (cl-pushnew new-cell found :test #'equal)))))
1075 (setq prettify-symbols-alist
1076 (cl-set-difference prettify-symbols-alist
1077 (cl-set-difference
1078 (cl-remove-if-not
1079 (lambda (elm)
1080 (eq (cdr elm) rasmus/ob-header-symbol))
1081 prettify-symbols-alist)
1082 found :test #'equal)))
1083 ;; Clean up old font-lock-keywords.
1084 (font-lock-remove-keywords nil prettify-symbols--keywords)
1085 (setq prettify-symbols--keywords (prettify-symbols--make-keywords))
1086 (font-lock-add-keywords nil prettify-symbols--keywords)
1087 (while (re-search-forward re nil t)
1088 (font-lock-flush (line-beginning-position) (line-end-position))))))
1089
1090 (defun rasmus/org-prettify-src ()
1091 "Hide src options via `prettify-symbols-mode'.
1092
1093 `prettify-symbols-mode' is used because it has uncollpasing. It's
1094 may not be efficient."
1095 (let* ((case-fold-search t)
1096 (at-src-block (save-excursion
1097 (beginning-of-line)
1098 (looking-at "^[ \t]*#\\+begin_src[ \t]+[^ \f\t\n\r\v]+[ \t]*"))))
1099 ;; Test if we moved out of a block.
1100 (when (or (and rasmus/org-at-src-begin
1101 (not at-src-block))
1102 ;; File was just opened.
1103 (eq rasmus/org-at-src-begin -1))
1104 (rasmus/org-prettify-src--update))
1105 ;; Remove composition if at line; doesn't work properly.
1106 ;; (when at-src-block
1107 ;; (with-silent-modifications
1108 ;; (remove-text-properties (match-end 0)
1109 ;; (1+ (line-end-position))
1110 ;; '(composition))))
1111 (setq rasmus/org-at-src-begin at-src-block)))
1112
1113 (defun rasmus/org-prettify-symbols ()
1114 (mapc (apply-partially 'add-to-list 'prettify-symbols-alist)
1115 (cl-reduce 'append
1116 (mapcar (lambda (x) (list x (cons (upcase (car x)) (cdr x))))
1117 `(("#+begin_src" . ?✎) ;; ➤ 🖝 ➟ ➤ ✎
1118 ("#+end_src" . ?⏹) ;; □
1119 ("#+header:" . ,rasmus/ob-header-symbol)
1120 ("#+begin_quote" . ?»)
1121 ("#+end_quote" . ?«)))))
1122 (turn-on-prettify-symbols-mode)
1123 (add-hook 'post-command-hook 'rasmus/org-prettify-src t t))
1124 #+end_src
1125
1126*** Regular prettify-symbols-mode
1127
1128#+begin_src emacs-lisp 1049#+begin_src emacs-lisp
1129 (cuss prettify-symbols-unprettify-at-point 'right-edge 1050 (cuss prettify-symbols-unprettify-at-point 'right-edge
1130 "Unprettify a symbol when inside it or next to it.") 1051 "Unprettify a symbol when inside it or next to it.")
1131 1052
1132 (defun acdw/org-mode-prettify () 1053 (add-hook 'prog-mode-hook #'prettify-symbols-mode)
1133 "Prettify `org-mode'."
1134 (append '(("[ ]" . ?□) ("[X]" . ?☑) ("[-]" . ?◐)
1135 ("#begin_src" . ?🖬) ("#BEGIN_SRC" . ?🖬)
1136 ("#end_src" . ?■) ("#END_SRC" . ?■))
1137 prettify-symbols-alist))
1138
1139 (add-hook 'org-mode-hook #'acdw/org-mode-prettify)
1140
1141 (global-prettify-symbols-mode +1)
1142#+end_src 1054#+end_src
1143 1055
1144** Parentheses 1056** Parentheses