├── README.md └── hlinum.el /README.md: -------------------------------------------------------------------------------- 1 | # Notice 2 | 3 | This package is obsolete because there is a better alternative in Emacs 26 and later. 4 | 5 | Emacs 26 officially provides the `display-line-numbers` function to show the line numbers and you can use the `line-number-current-line` 6 | face to highlight the current line number. 7 | They show the better performance than `linum-mode` and `hlinum-mode`. 8 | 9 | 10 | # hlinum-mode 11 | 12 | This library extends linum-mode to highlight current line number. 13 | It requires Emacs 24.4 or later. 14 | 15 | To use this package, add these lines to your .emacs file: 16 | ```elisp 17 | (require 'hlinum) 18 | (hlinum-activate) 19 | ``` 20 | 21 | And by using `M-x linum-mode`, you can see line numbers with highlighting current line number. 22 | 23 | You can customize the color of highlighting current line by changing `linum-highlight-face`. By default, hlinum highlights current line only in the active buffer. To highlight current line in all buffers, change `linum-highlight-in-all-buffersp` to `t`. 24 | -------------------------------------------------------------------------------- /hlinum.el: -------------------------------------------------------------------------------- 1 | ;;; hlinum.el --- Extension for linum.el to highlight current line number 2 | 3 | ;; Copyright (C) 2011-2016 by Tomoya Tanjo 4 | 5 | ;; Author: Tomoya Tanjo 6 | ;; URL: https://github.com/tom-tan/hlinum-mode/ 7 | ;; Package-Requires: ((cl-lib "0.2")) 8 | ;; Keywords: convenience, extensions 9 | 10 | ;; This program is free software; you can redistribute it and/or modify 11 | ;; it under the terms of the GNU General Public License as published by 12 | ;; the Free Software Foundation, either version 3 of the License, or 13 | ;; (at your option) any later version. 14 | 15 | ;; This program is distributed in the hope that it will be useful, 16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | ;; GNU General Public License for more details. 19 | 20 | ;; You should have received a copy of the GNU General Public License 21 | ;; along with this program. If not, see . 22 | 23 | ;;; Commentary: 24 | 25 | ;; Extension for linum-mode to highlight current line number. 26 | ;; 27 | ;; To use this package, add these lines to your .emacs file: 28 | ;; (require 'hlinum) 29 | ;; (hlinum-activate) 30 | ;; And by using M-x linum-mode, you can see line numbers 31 | ;; with highlighting current line number. 32 | ;; 33 | ;; You can customize the color of highlighting current line by 34 | ;; changing `linum-highlight-face'. 35 | ;; By default, hlinum highlights current line only in the active buffer. 36 | ;; To highlight current line in all buffers, change 37 | ;; `linum-highlight-in-all-buffersp' to t. 38 | 39 | ;;; Code: 40 | 41 | (require 'linum) 42 | (require 'cl-lib) 43 | 44 | (defface linum-highlight-face 45 | '((t (:inherit default :foreground "black" 46 | :background "gray"))) 47 | "Face for highlighting current line" 48 | :group 'linum) 49 | 50 | (defcustom linum-highlight-in-all-buffersp 51 | nil 52 | "Non-nil means hlinum highlights current line in all buffers. 53 | Otherwise hlinum will highlight only in the active buffer." 54 | :type 'boolean 55 | :group 'linum) 56 | 57 | (defun hlinum-color (face &optional line) 58 | "Highlight line number LINE by using face FACE. 59 | If LINE is nil, highlight current line." 60 | (save-excursion 61 | (when line (forward-line (- line (line-number-at-pos)))) 62 | (let* ((pt (max (window-start) 63 | (progn (move-beginning-of-line nil) 64 | (point)))) 65 | (ov (cl-find-if 66 | (lambda (e) (stringp (overlay-get e 'linum-str))) 67 | (overlays-in pt pt)))) 68 | (when ov 69 | (let* ((str (overlay-get ov 'before-string)) 70 | (lstr (overlay-get ov 'linum-str)) 71 | (nov (move-overlay ov pt pt))) 72 | (add-text-properties 0 (length lstr) 73 | `(face ,face) lstr) 74 | (add-text-properties 0 1 `(display ((margin left-margin) 75 | ,lstr)) str) 76 | (overlay-put nov 'before-string str) 77 | (overlay-put nov 'linum-str lstr)))))) 78 | 79 | (defun hlinum-highlight-line (&optional line) 80 | (hlinum-color 'linum-highlight-face line)) 81 | (defun hlinum-unhighlight-line (&optional line) 82 | (unless linum-highlight-in-all-buffersp 83 | (hlinum-color 'linum line))) 84 | 85 | (defun hlinum-highlight-region () 86 | (when mark-active 87 | (cl-loop for l 88 | from (line-number-at-pos (region-beginning)) 89 | to (line-number-at-pos (region-end)) 90 | do (hlinum-highlight-line l)))) 91 | 92 | (defun hlinum-after-scroll (win start) 93 | (when (eq (current-buffer) (window-buffer)) 94 | (if mark-active 95 | (hlinum-highlight-region) 96 | (hlinum-highlight-line)))) 97 | 98 | ;;;###autoload 99 | (defun hlinum-activate () 100 | "Enable highlighting current line number." 101 | (interactive) 102 | (advice-add 'linum-update-current :after 'hlinum-highlight-line) 103 | (advice-add 'linum-after-scroll :after 'hlinum-after-scroll) 104 | (add-hook 'pre-command-hook 'hlinum-unhighlight-line) 105 | (add-hook 'post-command-hook 'hlinum-highlight-region)) 106 | 107 | ;;;###autoload 108 | (defun hlinum-deactivate () 109 | "Disable highlighting current line number." 110 | (interactive) 111 | (remove-hook 'pre-command-hook 'hlinum-unhighlight-line) 112 | (remove-hook 'post-command-hook 'hlinum-highlight-region) 113 | (advice-remove 'linum-update-current 'hlinum-highlight-line) 114 | (advice-remove 'linum-after-scroll 'hlinum-after-scroll)) 115 | 116 | (provide 'hlinum) 117 | ;;; hlinum.el ends here 118 | --------------------------------------------------------------------------------