The Complete Computing Environment

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, 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 ()

  (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

(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
      (message "enable")
      (message "disable")
      (global-rainbow-identifiers-mode -1)
      (global-auto-highlight-symbol-mode -1)
      (mapc (lambda (name)
              (enable-theme name))

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
    (lambda ()
      (when (derived-mode-p 'prog-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)
  (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. Glossary↩︎