4.8 KiB
4.8 KiB
Surfing Through Codebases
Code Surfing is a minor-mode which makes it easy for me to explore codebases that I am not entirely familiar with. It disables the language font-locking1[Glossary]]], and reintroduces colors using rainbow-identifiers mode. In combination with my Focused Text Editing fundamentals, and my Emacs code navigation tooling, I can work my way through codebases I otherwise don't understand.
(provide 'cce/code-surf)
(defun enable-code-surf ()
(interactive)
(global-rainbow-identifiers-mode)
(global-auto-highlight-symbol-mode)
(set-face-attribute 'font-lock-builtin-face nil :inherit 'default :foreground nil :background nil)
(set-face-attribute 'font-lock-comment-face nil :inherit 'default :foreground "grey50" :background nil)
(set-face-attribute 'font-lock-comment-delimiter-face nil :inherit 'font-lock-comment-face)
(set-face-attribute 'font-lock-constant-face nil :inherit 'default :foreground nil :background nil)
(set-face-attribute 'font-lock-doc-face nil :inherit 'default :foreground "grey50" :background nil)
(set-face-attribute 'font-lock-function-name-face nil :inherit 'default :foreground nil :background nil)
(set-face-attribute 'font-lock-keyword-face nil :inherit 'default :foreground nil :background nil :weight 'normal)
(set-face-attribute 'font-lock-negation-char-face nil :inherit 'default) :foreground nil :background nil
(set-face-attribute 'font-lock-preprocessor-face nil :inherit 'default) :foreground nil :background nil
(set-face-attribute 'font-lock-string-face nil :inherit 'default :foreground nil :background nil)
(set-face-attribute 'font-lock-type-face nil :inherit 'default :foreground nil :background nil)
(set-face-attribute 'font-lock-variable-name-face nil :inherit 'default :foreground nil :background nil)
(set-face-attribute 'font-lock-warning-face nil :inherit 'default :foreground nil :background nil)
(set-face-attribute 'font-lock-regexp-grouping-backslash nil :inherit 'default :foreground nil :background nil)
(set-face-attribute 'font-lock-regexp-grouping-construct nil :inherit 'default :foreground nil :background nil)
(setq rainbow-identifiers-faces-to-override '(font-lock-function-name-face
font-lock-warning-face
font-lock-type-face
font-lock-constant-face
font-lock-variable-name-face)))
(setq code-surf-last-themes custom-enabled-themes)
(define-minor-mode code-surf-mode "Disable most font locking and enable rainbow-delimeters"
nil "[CS]" nil
(if code-surf-mode
(progn
(message "enable")
(enable-code-surf))
(progn
(message "disable")
(global-rainbow-identifiers-mode -1)
(global-auto-highlight-symbol-mode -1)
(mapc (lambda (name)
(enable-theme name))
code-surf-last-themes))))
This code-surf-mode
uses Rainbow Identifiers and Auto Highlight Symbol. Configuration of rainbow-identifiers is simple, we simply expand the range of colors that it is willing to use, and define a global minor mode which will enable rainbow-identifiers in every buffer which inherits prog-mode
.
(use-package rainbow-identifiers
:config
(define-global-minor-mode
global-rainbow-identifiers-mode
rainbow-identifiers-mode
(lambda ()
(when (derived-mode-p 'prog-mode)
(rainbow-identifiers-mode))))
(setq rainbow-identifiers-cie-l*a*b*-lightness 40
rainbow-identifiers-cie-l*a*b*-saturation 70
rainbow-identifiers-choose-face-function 'rainbow-identifiers-cie-l*a*b*-choose-face))
(use-package auto-highlight-symbol
:bind (:map evil-leader--default-map)
("v" . hydra-highlight-symbol/body)
:config
(defhydra hydra-highlight-symbol nil
"
Highlight -----------> Dim
_h_: Highlight at Point _f_: flow
_j_: Previous Symbol _r_: focus-ro
_k_: Next Symbol _e_: end flow
_d_: Clear All Symbols
_a_: Toggle AHS
"
("h" highlight-symbol-at-point)
("j" highlight-symbol-prev)
("k" highlight-symbol-next)
("d" highlight-symbol-remove-all)
("a" auto-highlight-symbol-mode)
("f" flow :exit t)
("e" end-flow :exit t)
("r" focus-read-only-mode)))
1
[[id:modern_interface_terms