From 0d9e188b26ca1d01a57598e37171e5333272cad7 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 7 Sep 2024 17:56:58 -0400 Subject: [PATCH] refactor!(indent-guides): use indent-bars instead BREAKING CHANGE: This swaps out the `highlight-indent-guides` package with the newer, and proportedly faster, `indent-bars`. Users don't have to make any changes to their config to support this, unless they've heavily reconfigured `highlight-indent-guides`. Ref: https://github.com/orgs/doomemacs/projects/5/views/1?filterQuery=-status%3ARejected%2CDone+indent&pane=issue&itemId=38113671 --- modules/config/default/+emacs-bindings.el | 2 +- modules/config/default/+evil-bindings.el | 2 +- modules/ui/indent-guides/README.org | 2 +- modules/ui/indent-guides/config.el | 58 +++++++++++++++-------- modules/ui/indent-guides/packages.el | 4 +- 5 files changed, 44 insertions(+), 24 deletions(-) diff --git a/modules/config/default/+emacs-bindings.el b/modules/config/default/+emacs-bindings.el index 43b26f200..b1da1068b 100644 --- a/modules/config/default/+emacs-bindings.el +++ b/modules/config/default/+emacs-bindings.el @@ -334,7 +334,7 @@ (:when (modulep! :checkers syntax) :desc "Flycheck" "f" #'flycheck-mode) (:when (modulep! :ui indent-guides) - :desc "Indent guides" "i" #'highlight-indent-guides-mode) + :desc "Indent guides" "i" #'indent-bars-mode) (:when (modulep! :ui minimap) :desc "Minimap mode" "m" #'minimap-mode) (:when (modulep! :lang org +present) diff --git a/modules/config/default/+evil-bindings.el b/modules/config/default/+evil-bindings.el index 7613a0a2a..f96aa3312 100644 --- a/modules/config/default/+evil-bindings.el +++ b/modules/config/default/+evil-bindings.el @@ -843,7 +843,7 @@ :desc "Frame fullscreen" "F" #'toggle-frame-fullscreen :desc "Evil goggles" "g" #'evil-goggles-mode (:when (modulep! :ui indent-guides) - :desc "Indent guides" "i" #'highlight-indent-guides-mode) + :desc "Indent guides" "i" #'indent-bars-mode) :desc "Indent style" "I" #'doom/toggle-indent-style :desc "Line numbers" "l" #'doom/toggle-line-numbers (:when (modulep! :ui minimap) diff --git a/modules/ui/indent-guides/README.org b/modules/ui/indent-guides/README.org index d0496e9df..09aa09b10 100644 --- a/modules/ui/indent-guides/README.org +++ b/modules/ui/indent-guides/README.org @@ -13,7 +13,7 @@ /This module has no flags./ ** Packages -- [[doom-package:highlight-indent-guides]] +- [[doom-package:indent-bars]] ** Hacks /No hacks documented for this module./ diff --git a/modules/ui/indent-guides/config.el b/modules/ui/indent-guides/config.el index 9312f0ad7..f0bbed9a8 100644 --- a/modules/ui/indent-guides/config.el +++ b/modules/ui/indent-guides/config.el @@ -1,11 +1,10 @@ ;;; ui/indent-guides/config.el -*- lexical-binding: t; -*- -(defcustom +indent-guides-inhibit-functions nil +(defcustom +indent-guides-inhibit-functions () "A list of predicate functions. -Each function will be run in the context of a buffer where -`highlight-indent-guides-mode' should be enabled. If any function returns -non-nil, the mode will not be activated." +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." :type 'hook :group '+indent-guides) @@ -13,17 +12,25 @@ non-nil, the mode will not be activated." ;; ;;; Packages -(use-package! highlight-indent-guides +(use-package! indent-bars :hook ((prog-mode text-mode conf-mode) . +indent-guides-init-maybe-h) :init - (setq highlight-indent-guides-method 'character - highlight-indent-guides-bitmap-function #'highlight-indent-guides--bitmap-line) - (defun +indent-guides-init-maybe-h () - "Enable `highlight-indent-guides-mode'. -Consults `+indent-guides-inhibit-functions'." + "Enable `indent-bars-mode' depending on `+indent-guides-inhibit-functions'." (unless (run-hook-with-args-until-success '+indent-guides-inhibit-functions) - (highlight-indent-guides-mode +1))) + (indent-bars-mode +1))) + :config + ;; Bitmap performance is inconsistent across display systems (pgtk, ns, mac, + ;; gtk, etc). There's also a bitmap init bug in PGTK builds of Emacs before + ;; v30 that could cause crashes (see jdtsmith/indent-bars#3). If you use PGTK + ;; and reverse this setting, you've been warned! + (setq indent-bars-prefer-character t) + + ;; TODO: Uncomment once we support treesit + ;; (setq indent-bars-treesit-support (modulep! :tools tree-sitter)) + + (unless (boundp 'enable-theme-functions) + (add-hook 'doom-load-theme-hook #'indent-bars-reset-styles)) (add-hook! '+indent-guides-inhibit-functions ;; Org's virtual indentation messes up indent-guides. @@ -33,12 +40,23 @@ Consults `+indent-guides-inhibit-functions'." ;; notebooks. (defun +indent-guides-in-ein-notebook-p () (and (bound-and-true-p ein:notebook-mode) - (bound-and-true-p ein:output-area-inlined-images)))) - :config - ;; HACK: If this package is loaded too early (by the user, and in terminal - ;; Emacs), then `highlight-indent-guides-auto-set-faces' will have been - ;; called much too early to set its faces correctly. To get around this, we - ;; need to call it again, but at a time when I can ensure a frame exists an - ;; the current theme is loaded. - (when (doom-context-p 'init) - (add-hook 'doom-first-buffer-hook #'highlight-indent-guides-auto-set-faces))) + (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 () + (frame-parameter nil 'parent-frame))) + + ;; HACK: Out of the box, indent-bars offers no way to fully disable + ;; "highlighting the current line", so I advise on in, since the feature is + ;; unnecessary work (and allocation of timers) for users that don't want it, + ;; and for our performance-leaning defaults. + (setq indent-bars-depth-update-delay nil) + (defadvice! +indent-guides--disable-highlight-current-line-a (fn &rest args) + :around #'indent-bars-setup + (letf! (defun indent-bars--highlight-current-depth () + (when indent-bars-depth-update-delay + (funcall indent-bars--highlight-current-depth))) + (prog1 (apply fn args) + (unless indent-bars-depth-update-delay + (remove-hook 'post-command-hook #'indent-bars--highlight-current-depth t)))))) diff --git a/modules/ui/indent-guides/packages.el b/modules/ui/indent-guides/packages.el index b305d6e75..78d640b43 100644 --- a/modules/ui/indent-guides/packages.el +++ b/modules/ui/indent-guides/packages.el @@ -1,4 +1,6 @@ ;; -*- no-byte-compile: t; -*- ;;; ui/indent-guides/packages.el -(package! highlight-indent-guides :pin "cf352c85cd15dd18aa096ba9d9ab9b7ab493e8f6") +(package! indent-bars + :recipe (:host github :repo "jdtsmith/indent-bars") + :pin "c8376cf4373a6444ca88e88736db7576dedb51d6")