GithubHelp home page GithubHelp logo

Comments (2)

hlissner avatar hlissner commented on July 19, 2024

Hey there! And thanks, I'm glad you like it.

You can replace def-package! with use-package. They're aliases. It's there just for consistency (with my emacs.d) and in case I need to wrap use-package in some functionality later. add-hook! is a convenience macro for adding 1-to-many, many-to-many, or many-to-1 functions to hooks. In any case, here is my config without any of my private macros:

(use-package highlight-indentation
  :commands (highlight-indentation-mode highlight-indentation-current-column-mode)
  :config
  (defun doom|inject-trailing-whitespace (&optional start end)
    "The opposite of `delete-trailing-whitespace'. Injects whitespace into
buffer so that `highlight-indentation-mode' will display uninterrupted indent
markers. This whitespace is stripped out on save, as not to affect the resulting
file."
    (interactive (progn (barf-if-buffer-read-only)
                        (if (use-region-p)
                            (list (region-beginning) (region-end))
                          (list nil nil))))
    (unless indent-tabs-mode
      (save-match-data
        (save-excursion
          (let ((end-marker (copy-marker (or end (point-max))))
                (start (or start (point-min))))
            (goto-char start)
            (while (and (re-search-forward "^$" end-marker t) (< (point) end-marker))
              (let (line-start line-end next-start next-end)
                (save-excursion
                  ;; Check previous line indent
                  (forward-line -1)
                  (setq line-start (point)
                        line-end (save-excursion (back-to-indentation) (point)))
                  ;; Check next line indent
                  (forward-line 2)
                  (setq next-start (point)
                        next-end (save-excursion (back-to-indentation) (point)))
                  ;; Back to origin
                  (forward-line -1)
                  ;; Adjust indent
                  (let* ((line-indent (- line-end line-start))
                         (next-indent (- next-end next-start))
                         (indent (min line-indent next-indent)))
                    (insert (make-string (if (zerop indent) 0 (1+ indent)) ? )))))
              (forward-line 1)))))
      (set-buffer-modified-p nil))
  nil)

  (defun highlight-indentation-handle-whitespace ()
    (if (or highlight-indentation-mode highlight-indentation-current-column-mode)
        (progn
          (doom|inject-trailing-whitespace)
          (add-hook 'before-save-hook #'delete-trailing-whitespace nil t)
          (add-hook 'after-save-hook #'doom|inject-trailing-whitespace nil t))
      (remove-hook 'before-save-hook #'delete-trailing-whitespace t)
      (remove-hook 'after-save-hook #'doom|inject-trailing-whitespace t)
      (delete-trailing-whitespace)))
  (add-hook 'highlight-indentation-mode-hook 'highlight-indentation-handle-whitespace)
  (add-hook 'highlight-indentation-current-column-mode-hook 'highlight-indentation-handle-whitespace)

However, I must disagree with adding highlight-indentation to doom-themes. There are multiple such plugins, each with their own pros and cons for different languages; I can't suppot all of them nor can I presume to guess every user's needs. I also think it's trivial enough for a user to implement themselves (my config notwithstanding).

doom-one does set the highlight indentation faces however (so they'll be colored appropriately if you do use any of those plugins).

from themes.

jwintz avatar jwintz commented on July 19, 2024

Many thanks ! Works like a charm.

from themes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.