From 54dcb9fd4499959dcb2105f195bc8a808095b883 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 12 Apr 2016 02:59:36 -0400 Subject: [PATCH] Add highlight-indentation --- Cask | 1 + core/core-ui.el | 18 ++++++++++++++++++ core/defuns/defuns-ui.el | 30 ++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/Cask b/Cask index 4ca00fd59..984fb6581 100644 --- a/Cask +++ b/Cask @@ -27,6 +27,7 @@ ;; UI --- core/core-ui.el (depends-on "visual-fill-column") +(depends-on "highlight-indentation" :git "https://github.com/localredhead/Highlight-Indentation-for-Emacs") (depends-on "rainbow-delimiters") (depends-on "rainbow-mode") (depends-on "nlinum") diff --git a/core/core-ui.el b/core/core-ui.el index bf47e83fe..cf389f461 100644 --- a/core/core-ui.el +++ b/core/core-ui.el @@ -145,6 +145,24 @@ (use-package visual-fill-column :defer t) +(use-package highlight-indentation + :commands (highlight-indentation-mode highlight-indentation-current-column-mode) + :init + (add-hook! (web-mode nxml-mode yaml-mode json-mode scss-mode + c-mode-common ruby-mode python-mode lua-mode) + 'highlight-indentation-mode) + + :config + ;; A long-winded method for ensuring whitespace is maintained (so that + ;; highlight-indentation-mode can display them consistently) + (add-hook! highlight-indentation-mode + (if highlight-indentation-mode + (progn + (narf/add-whitespace) + (add-hook 'after-save-hook 'narf/add-whitespace nil t)) + (remove-hook 'after-save-hook 'narf/add-whitespace t))) + (add-hook 'before-save-hook 'delete-trailing-whitespace)) + (use-package rainbow-delimiters :commands rainbow-delimiters-mode :init diff --git a/core/defuns/defuns-ui.el b/core/defuns/defuns-ui.el index 18bdeaa47..166c7910f 100644 --- a/core/defuns/defuns-ui.el +++ b/core/defuns/defuns-ui.el @@ -46,5 +46,35 @@ (compose-region beg end how 'decompose-region)) nil)) +;;;###autoload +(defun narf/add-whitespace (&optional start end) + (interactive (progn (barf-if-buffer-read-only) + (if (use-region-p) + (list (region-beginning) (region-end)) + (list nil nil)))) + (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) (not (>= (point) end-marker))) + (let (line-start line-end) + (save-excursion + (forward-line -1) + (setq line-start (point) + line-end (save-excursion (back-to-indentation) (point))) + (if (and (= line-start line-end) + (/= line-end (line-end-position))) + (progn + (forward-line 2) + (setq line-start (point) + line-end (save-excursion (back-to-indentation) (point))) + (forward-line -1)) + (forward-line 1)) + (insert (make-string (- line-end line-start) 32)))) + (forward-line 1))))) + (set-buffer-modified-p nil) + nil) + (provide 'defuns-ui) ;;; defuns-ui.el ends here