From 5f798cf8e7338f2fdf4236c069b8a0d18def60df Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 28 Jul 2024 18:57:12 -0400 Subject: [PATCH] feat(indent-guides): add +indent-guides-inhibit-functions Also adds a fix for indent-guides breaking inline images in ein:notebook-mode (#6438). Fix: #6438 Ref: 29277c9b0281 --- modules/ui/indent-guides/config.el | 40 +++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/modules/ui/indent-guides/config.el b/modules/ui/indent-guides/config.el index f3524f9cd..58b43ea16 100644 --- a/modules/ui/indent-guides/config.el +++ b/modules/ui/indent-guides/config.el @@ -1,10 +1,39 @@ ;;; ui/indent-guides/config.el -*- lexical-binding: t; -*- +(defcustom +indent-guides-inhibit-functions nil + "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." + :type 'hook + :group '+indent-guides) + + +;; +;;; Packages + (use-package! highlight-indent-guides - :hook ((prog-mode text-mode conf-mode) . highlight-indent-guides-mode) + :hook ((prog-mode text-mode conf-mode) . +indent-guides-init-maybe-h) :init (setq highlight-indent-guides-method (if (display-graphic-p) 'bitmap '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'." + (unless (run-hook-with-args-until-success '+indent-guides-inhibit-functions) + (highlight-indent-guides-mode +1))) + + (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) + (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 @@ -12,11 +41,4 @@ ;; 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)) - - ;; `highlight-indent-guides' breaks when `org-indent-mode' is active - (add-hook! 'org-mode-local-vars-hook - (defun +indent-guides-disable-maybe-h () - (and highlight-indent-guides-mode - (bound-and-true-p org-indent-mode) - (highlight-indent-guides-mode -1))))) + (add-hook 'doom-first-buffer-hook #'highlight-indent-guides-auto-set-faces)))