jdtsmith / indent-bars

Fast, configurable indentation guide-bars for Emacs
GNU General Public License v3.0
272 stars 7 forks source link

Only showing up on empty lines until I run indent-bars-reset #27

Closed kportertx closed 8 months ago

kportertx commented 8 months ago
emacs --version
GNU Emacs 29.1.90
Development version c22eeba82770 on emacs-29 branch; build date 2023-10-26.
...

Before: 2023-10-26-170516_157x456_scrot

After reset: 2023-10-26-170607_151x451_scrot

I only seem to have this problem with files indented with tabs.

jdtsmith commented 8 months ago

What mode is this? How are you calling indent-bars-mode? It should be in the mode hook of the mode(s) of interest. It's possible your mode is doing something to interfere with indent-bars redrawing the tabs, or maybe something as simple as indent-tabs-mode is not correctly set at the time you are calling indent-bars-mode.

Also, if possible use indent-tabs-mode=nil.

kportertx commented 8 months ago
The major mode is C/* mode defined in c-ts-mode.el:

indent-tabs-mode is initially nil, it is changed to t by editorconfig-mode.

I'm calling it via:

(use-package indent-bars
  ;; indent-bars highlights indentation with configurable font-lock
  ;; based vertical bars, using stipples.  The color and appearance
  :straight (indent-bars :type git :host github :repo "jdtsmith/indent-bars")
  :custom
  (indent-bars-color '(highlight :face-bg t :blend 0.15))
  (indent-bars-pattern ".")
  (indent-bars-width-frac 0.3)
  (indent-bars-pad-frac 0.3)
  (indent-bars-zigzag nil)
  (indent-bars-color-by-depth '(:regexp "outline-\\([0-9]+\\)" :blend 1)) ; blend=1: blend with BG only
  (indent-bars-highlight-current-depth '(:blend 0.5)) ; pump up the BG blend on current
  (indent-bars-display-on-blank-lines t)
  :hook
  (prog-mode . indent-bars-mode))
jdtsmith commented 8 months ago

indent-tabs-mode is initially nil, it is changed to t by editorconfig-mode

Sounds like you need to arrange for indent-bars to run after editor-config. But again, no tabs is faster and preferred.

kportertx commented 8 months ago

I don't own the style guide for the project.

I'll see if I can figure that out. Would there happen to be a way to hook on indent-tabs-mode changing would there? Having suspected that this may be the issue, I was failing to find a way to call indent-bars-reset on indent-tabs-mode change.

~Thought of a better search query while typing, will have to try this later: https://www.gnu.org/software/emacs/manual/html_node/elisp/Watching-Variables.html~ - This won't work since the event triggers before the value is changed.

jdtsmith commented 8 months ago

How do you call the other conflicting mode?

kportertx commented 8 months ago

I've tried with editorconfig disabled and manually setting indent-tabs-mode t for such projects, the issue is the same.

(use-package editorconfig
  :ensure t
  :custom
  (editorconfig-trim-whitespaces-mode 'ws-butler-mode)
  :init
  (editorconfig-mode))
jdtsmith commented 8 months ago

I'm not seeing this in c files I've tested. Can you construct a reproducer starting from emacs -q? Ideally loading and configuring just indent-bars, see if that works as normal, then add other possible packages which interfere to isolate.

kportertx commented 8 months ago

Note: file is indented with tabs:

With (setq-default indent-tabs-mode t) 2023-10-30-083417_256x454_scrot

With (setq-default indent-tabs-mode nil) 2023-10-30-083728_250x454_scrot

jdtsmith commented 8 months ago

Is this starting from emacs -q (i.e. no configuration other than loading indent-bars and c-ts-mode)? That's what's needed to make progress.

kportertx commented 8 months ago

Yes, this is with emacs -q - and using the indent-bars config above.

jdtsmith commented 8 months ago

Please post the configuration and steps which led to this. If you open a file which includes tabs for indentation, but do not have indent-tabs-mode correctly configured, of course it won't work correctly. The solution is to ensure that variable is correctly configured.

jdtsmith commented 8 months ago

You may have meant that you fixed this by correctly configuring indent-tabs-mode. indent-bars relies on this mode being correct in buffers to configure what it looks for in terms of "blank" lines. Not sure why this variable was wrong for you originally, but it seems you found a workaround? Let me know if that's not the case.

kportertx commented 8 months ago

Was unable to get back to this sooner:

Configuration steps after starting with emacs -q:

(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 6))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

(use-package indent-bars
  ;; indent-bars highlights indentation with configurable font-lock
  ;; based vertical bars, using stipples.  The color and appearance
  :ensure t
  :straight (indent-bars :type git :host github :repo "jdtsmith/indent-bars")
  :custom
  (indent-bars-color '(highlight :face-bg t :blend 0.15))
  (indent-bars-pattern ".")
  (indent-bars-width-frac 0.3)
  (indent-bars-pad-frac 0.3)
  (indent-bars-zigzag nil)
  (indent-bars-color-by-depth '(:regexp "outline-\\([0-9]+\\)" :blend 1)) ; blend=1: blend with BG only
  (indent-bars-highlight-current-depth '(:blend 0.5)) ; pump up the BG blend on current
  (indent-bars-display-on-blank-lines t)
  :hook
  (prog-mode . indent-bars-mode))

2023-11-06-085736_264x447_scrot

Result is not quite right but - looks like the bars are every 4 spaces while the default for tabs is 8 - but I'm not too concerned about the defaults. I use `editorconfig

From your last response, I think the problem could be that editorconfig-mode is making various indentation setting changes after indent-tabs-mode has loaded. If so, I'm not sure how to correct this ordering.

Restarting to try with editorconfig:

(setopt package-archives
  '(("melpa" . "https://melpa.org/packages/")
     ("elpa" . "https://elpa.gnu.org/packages/")
     ("nongnu" . "https://elpa.nongnu.org/nongnu/")))

(unless (bound-and-true-p package--initialized)
  (package-initialize))

(when (not package-archive-contents)
  (package-refresh-contents))

(when (not (package-installed-p 'use-package))
  (package-install 'use-package))

;; Setup straight package manager.
(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 6))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

(require 'use-package)
(use-package use-package
  :ensure nil
  :custom
  ;; Disable deprecation warnings about cl. The cl library has been deprecated,
  ;; but lots of packages still use it.
  (byte-compile-warnings '(cl-functions))
  ;; Don’t pop up a buffer to warn me about deprecation and other minor issues.
  ;; (warning-minimum-level :emergency)
  (use-package-compute-statistics t) ;; for profiling, M-x use-package-report
  )

(use-package editorconfig
  :ensure t
  :init
  (editorconfig-mode))

(use-package indent-bars
  ;; indent-bars highlights indentation with configurable font-lock
  ;; based vertical bars, using stipples.  The color and appearance
  :ensure t
  :straight (indent-bars :type git :host github :repo "jdtsmith/indent-bars")
  :custom
  (indent-bars-color '(highlight :face-bg t :blend 0.15))
  (indent-bars-pattern ".")
  (indent-bars-width-frac 0.3)
  (indent-bars-pad-frac 0.3)
  (indent-bars-zigzag nil)
  (indent-bars-color-by-depth '(:regexp "outline-\\([0-9]+\\)" :blend 1)) ; blend=1: blend with BG only
  (indent-bars-highlight-current-depth '(:blend 0.5)) ; pump up the BG blend on current
  (indent-bars-display-on-blank-lines t)
  :hook
  (prog-mode . indent-bars-mode))

(use-package treesit-auto
  :ensure t
  :config
  (global-treesit-auto-mode))

Ok - now it seems to be working correctly - maybe the ordering of having editorconfig loaded before indent-bars matters.

2023-11-06-090937_139x450_scrot

I'll see if I can adjust my config to ensure this ordering.

Update: Adding :after (editorconfg) to the indent-bars config didn't help.

jdtsmith commented 8 months ago

OK looks like you got the tab-indent stuff sorted out. In C modes the variable c-basic-offset is used to configure the bar spacing, or, failing that, standard-indent. Are these set to sensible values? indent-bars does not discover the offset from the file (though of course you could use file-local-variables to set one of these up). It relies on you to have correctly configured and indented your mode. Your second screenshot has a spacing of 4 (which is the default I think).