2019-03-11 12:39:38 -04:00
|
|
|
;;; ui/indent-guides/config.el -*- lexical-binding: t; -*-
|
|
|
|
|
2024-09-07 17:56:58 -04:00
|
|
|
(defcustom +indent-guides-inhibit-functions ()
|
2024-07-28 18:57:12 -04:00
|
|
|
"A list of predicate functions.
|
|
|
|
|
2024-09-07 17:56:58 -04:00
|
|
|
Each function will be run in the context of a buffer where `indent-bars' should
|
|
|
|
be enabled. If any function returns non-nil, the mode will not be activated."
|
2024-07-28 18:57:12 -04:00
|
|
|
:type 'hook
|
|
|
|
:group '+indent-guides)
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;;; Packages
|
|
|
|
|
2024-09-07 17:56:58 -04:00
|
|
|
(use-package! indent-bars
|
2024-07-28 18:57:12 -04:00
|
|
|
:hook ((prog-mode text-mode conf-mode) . +indent-guides-init-maybe-h)
|
2023-12-05 17:41:59 -05:00
|
|
|
:init
|
2024-07-28 18:57:12 -04:00
|
|
|
(defun +indent-guides-init-maybe-h ()
|
2024-09-07 17:56:58 -04:00
|
|
|
"Enable `indent-bars-mode' depending on `+indent-guides-inhibit-functions'."
|
2024-07-28 18:57:12 -04:00
|
|
|
(unless (run-hook-with-args-until-success '+indent-guides-inhibit-functions)
|
2024-09-07 17:56:58 -04:00
|
|
|
(indent-bars-mode +1)))
|
|
|
|
:config
|
2024-09-07 21:54:48 -04:00
|
|
|
(setq indent-bars-prefer-character
|
|
|
|
(or
|
|
|
|
;; Bitmaps are far slower on MacOS, inexplicably, but this needs more
|
|
|
|
;; testing to see if it's specific to ns or emacs-mac builds, or is
|
|
|
|
;; just a general MacOS issue.
|
|
|
|
(featurep :system 'macos)
|
|
|
|
;; FIX: A bitmap init bug in PGTK builds of Emacs before v30 that could
|
|
|
|
;; cause crashes (see jdtsmith/indent-bars#3).
|
|
|
|
(and (featurep 'pgtk)
|
|
|
|
(< emacs-major-version 30)))
|
|
|
|
|
|
|
|
;; Show indent guides starting from the first column.
|
|
|
|
indent-bars-starting-column 0
|
|
|
|
;; Make indent guides subtle; the default is too distractingly colorful.
|
|
|
|
indent-bars-width-frac 0.15 ; make bitmaps thinner
|
|
|
|
indent-bars-color-by-depth nil
|
|
|
|
indent-bars-color '(font-lock-comment-face :face-bg nil :blend 0.425)
|
|
|
|
;; Don't highlight current level indentation; it's distracting and is
|
|
|
|
;; unnecessary overhead for little benefit.
|
|
|
|
indent-bars-highlight-current-depth nil)
|
2024-09-07 17:56:58 -04:00
|
|
|
|
|
|
|
;; TODO: Uncomment once we support treesit
|
|
|
|
;; (setq indent-bars-treesit-support (modulep! :tools tree-sitter))
|
|
|
|
|
2024-09-09 16:36:09 -04:00
|
|
|
;; HACK: Both indent-bars and tree-sitter-hl-mode use the jit-font-lock
|
|
|
|
;; mechanism, and so they don't play well together. For those particular
|
|
|
|
;; cases, we'll use `highlight-indent-guides', at least until the
|
|
|
|
;; tree-sitter module adopts treesit.
|
|
|
|
(defvar-local +indent-guides-p nil)
|
|
|
|
(add-hook! 'tree-sitter-mode-hook :append
|
|
|
|
(defun +indent-guides--toggle-on-tree-sitter-h ()
|
|
|
|
(if tree-sitter-mode
|
|
|
|
(when (bound-and-true-p indent-bars-mode)
|
|
|
|
(with-memoization (get 'indent-bars-mode 'disabled-in-tree-sitter)
|
|
|
|
(doom-log "Disabled `indent-bars-mode' because it's not supported in `tree-sitter-mode'")
|
|
|
|
t)
|
|
|
|
(indent-bars-mode -1)
|
|
|
|
(setq +indent-guides-p t))
|
|
|
|
(when +indent-guides-p
|
|
|
|
(indent-bars-mode +1)))))
|
|
|
|
|
2024-09-07 17:56:58 -04:00
|
|
|
(unless (boundp 'enable-theme-functions)
|
|
|
|
(add-hook 'doom-load-theme-hook #'indent-bars-reset-styles))
|
2024-07-28 18:57:12 -04:00
|
|
|
|
|
|
|
(add-hook! '+indent-guides-inhibit-functions
|
|
|
|
;; Org's virtual indentation messes up indent-guides.
|
|
|
|
(defun +indent-guides-in-org-indent-mode-p ()
|
|
|
|
(bound-and-true-p org-indent-mode))
|
|
|
|
;; Fix #6438: indent-guides prevent inline images from displaying in ein
|
|
|
|
;; notebooks.
|
|
|
|
(defun +indent-guides-in-ein-notebook-p ()
|
|
|
|
(and (bound-and-true-p ein:notebook-mode)
|
2024-09-07 17:56:58 -04:00
|
|
|
(bound-and-true-p ein:output-area-inlined-images)))
|
|
|
|
;; Don't display indent guides in childframe popups (not helpful in
|
|
|
|
;; completion or eldoc popups).
|
|
|
|
;; REVIEW: Swap with `frame-parent' when 27 support is dropped
|
|
|
|
(defun +indent-guides-in-childframe-p ()
|
2024-09-08 17:48:39 -04:00
|
|
|
(frame-parameter nil 'parent-frame)))
|
|
|
|
|
2024-09-09 00:35:29 -04:00
|
|
|
;; HACK: `indent-bars-mode' interactions with some packages poorly. This
|
|
|
|
;; section is dedicated to package interop fixes.
|
|
|
|
(when (modulep! :tools magit)
|
|
|
|
(after! magit-blame
|
|
|
|
(add-to-list 'magit-blame-disable-modes 'indent-bars-mode)))
|
|
|
|
|
2024-09-08 17:48:39 -04:00
|
|
|
(when (modulep! :tools lsp)
|
|
|
|
;; HACK: lsp-ui-peek uses overlays, and indent-bars doesn't know how to deal
|
|
|
|
;; with all the whitespace it uses to format its popups, spamming it with
|
|
|
|
;; indent guides. Making the two work together is a project for another
|
|
|
|
;; day, so disable `indent-bars-mode' while its active instead. Doesn't
|
|
|
|
;; affect character bars though.
|
|
|
|
;; REVIEW: Report this upstream to `indent-bars'?
|
|
|
|
(defadvice! +indent-guides--remove-after-lsp-ui-peek-a (&rest _)
|
|
|
|
:after #'lsp-ui-peek--peek-new
|
|
|
|
(when (and indent-bars-mode
|
|
|
|
(not indent-bars-prefer-character)
|
|
|
|
(overlayp lsp-ui-peek--overlay))
|
|
|
|
(save-excursion
|
|
|
|
(let ((indent-bars--display-function #'ignore)
|
|
|
|
(indent-bars--display-blank-lines-function #'ignore))
|
|
|
|
(indent-bars--fontify (overlay-start lsp-ui-peek--overlay)
|
|
|
|
(1+ (overlay-end lsp-ui-peek--overlay))
|
|
|
|
nil)))))
|
|
|
|
(defadvice! +indent-guides--restore-after-lsp-ui-peek-a (&rest _)
|
|
|
|
:after #'lsp-ui-peek--peek-hide
|
|
|
|
(unless indent-bars-prefer-character
|
|
|
|
(indent-bars-setup)))))
|