Created
December 22, 2011 14:14
-
-
Save krestenkrab/1510432 to your computer and use it in GitHub Desktop.
hindent.el: Highlight indentation of current line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; | |
;;; Copyright (C) Kresten Krab Thorup | |
;;; Available under Apache License, Version 2. | |
;;; | |
;;; | |
;;; This minor mode will highlight the indentation of the current line | |
;;; as a vertical bar (grey background color) aligned with the column of the | |
;;; first character of the current line. | |
;;; | |
(defface hindent-face | |
;; Fringe has non intrusive color in most color-themes | |
'((t :inherit fringe)) | |
"Basic face for highlighting indentation guides." | |
:group 'basic-faces) | |
(define-minor-mode | |
hindent-minor-mode | |
"Hilight Indentation minor mode displays | |
a vertical bar corresponding to the indentation of the current line" | |
:lighter " |" | |
(if hindent-current-regex | |
(font-lock-remove-keywords nil hindent-current-regex)) | |
(set (make-local-variable 'hindent-current-regex) nil) | |
(if hindent-minor-mode | |
(add-hook 'post-command-hook 'hindent-current-line-hook nil t) | |
(font-lock-fontify-buffer))) | |
;; used to hold the last regex we installed | |
(defvar hindent-current-regex nil) | |
;; | |
;; This hook runs after every keystroke | |
;; | |
(defun hindent-current-line-hook () | |
(progn | |
;; (display-warning :warning "inside hook") | |
(let* ((current-point (point)) | |
(indent (progn | |
(beginning-of-line) | |
(skip-chars-forward " \t") | |
(current-column)))) | |
(progn | |
(if hindent-current-regex | |
(font-lock-remove-keywords nil hindent-current-regex)) | |
(if (and hindent-minor-mode | |
(> indent 1)) | |
(let* ((re (format "^.\\{%d\\}\\( \\)" indent)) | |
(arg `((,re (1 'hindent-face prepend))))) | |
(progn | |
(set (make-local-variable 'hindent-current-regex) arg) | |
(font-lock-add-keywords nil arg))) | |
(remove-hook 'post-command-hook 'highlight-ident-current-line-hook t)) | |
(font-lock-fontify-buffer) | |
(goto-char current-point))))) | |
(provide 'hindent-minor-mode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would be great if it use a line as in fci-mode. Give a look: http://snag.gy/U9AmJ.jpg