Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun setup-subscripts-display ()
- "Make numbers next to identifiers (like x0 or y4) appear like
- subscripts. Uses `prettify-symbols-mode'."
- (setf prettify-symbols-unprettify-at-point 'right-edge)
- (mapc (lambda (x) (push x prettify-symbols-alist))
- '(("0" . "₀")
- ("1" . "₁")
- ("2" . "₂")
- ("3" . "₃")
- ("4" . "₄")
- ("5" . "₅")
- ("6" . "₆")
- ("7" . "₇")
- ("8" . "₈")
- ("9" . "₉")))
- (cl-macrolet ((save-start (&rest body) `(save-excursion (goto-char start) ,@body)))
- (setf prettify-symbols-compose-predicate
- (lambda (start end _match)
- (if (save-start (cl-digit-char-p (following-char)))
- (or
- ;; #nλ subscripts
- (and (save-start ; #
- (loop while (cl-digit-char-p (following-char))
- do (backward-char))
- (eql (following-char) ?#))
- (save-start ; λ
- (forward-char)
- (eql (following-char) ?λ)))
- ;; regular subscribpts
- (and (save-start ; excepted symbols
- (not (member (sexp-at-point) '(prin1))))
- (save-start ; on the left, ensure there's some letter
- (loop while (cl-digit-char-p (following-char))
- do (backward-char))
- (string-match-p (rx letter) (char-to-string (following-char))))
- (save-start ; on the right, there must be not other letters
- (loop while (cl-digit-char-p (following-char))
- do (forward-char))
- (string-match-p (rx (or white ")" 10))
- (char-to-string (following-char))))))
- (prettify-symbols-default-compose-p start end _match)))))
- (prettify-symbols-mode))
- (setup-subscripts-display)
Advertisement
Add Comment
Please, Sign In to add comment