diff options
| -rw-r--r-- | lisp/ChangeLog | 17 | ||||
| -rw-r--r-- | lisp/hl-line.el | 157 |
2 files changed, 129 insertions, 45 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a84b71be5e0..d475b5002dc 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,20 @@ | |||
| 1 | 2003-05-15 Lute Kamstra <Lute.Kamstra@cwi.nl> | ||
| 2 | |||
| 3 | * hl-line.el: Rewrote the local minor mode so that it can be | ||
| 4 | sticky as well and made sticky the default. Reimplemented the | ||
| 5 | global minor mode. Updated the commentary section to document | ||
| 6 | these changes. | ||
| 7 | (hl-line-sticky-flag): New user option. | ||
| 8 | (hl-line-overlay): Made it buffer-local and gave it a docstring. | ||
| 9 | (global-hl-line-overlay): New variable. | ||
| 10 | (hl-line-mode): Rewritten to use `hl-line-sticky-flag'. | ||
| 11 | (hl-line-highlight): Rewritten to use `hl-line-sticky-flag'. | ||
| 12 | (hl-line-unhighlight): Updated docstring. | ||
| 13 | (global-hl-line-mode): Implemented directly so that is does not | ||
| 14 | depend on `hl-line-mode' any more. | ||
| 15 | (global-hl-line-highlight, global-hl-line-unhighlight): New | ||
| 16 | functions. | ||
| 17 | |||
| 1 | 2003-05-15 Kenichi Handa <handa@m17n.org> | 18 | 2003-05-15 Kenichi Handa <handa@m17n.org> |
| 2 | 19 | ||
| 3 | * international/code-pages.el (cyrillic-koi8-t): Alias of koi8-t. | 20 | * international/code-pages.el (cyrillic-koi8-t): Alias of koi8-t. |
diff --git a/lisp/hl-line.el b/lisp/hl-line.el index 727f859a32e..880ec4ae93e 100644 --- a/lisp/hl-line.el +++ b/lisp/hl-line.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; hl-line.el --- highlight the current line | 1 | ;;; hl-line.el --- highlight the current line |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1998, 2000, 2001 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1998, 2000, 2001, 2003 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: Dave Love <fx@gnu.org> | 5 | ;; Author: Dave Love <fx@gnu.org> |
| 6 | ;; Created: 1998-09-13 | 6 | ;; Created: 1998-09-13 |
| @@ -25,26 +25,36 @@ | |||
| 25 | 25 | ||
| 26 | ;;; Commentary: | 26 | ;;; Commentary: |
| 27 | 27 | ||
| 28 | ;; Provides a minor mode (toggled by M-x hl-line-mode) and a global minor | 28 | ;; Provides a buffer-local minor mode (toggled by M-x hl-line-mode) |
| 29 | ;; mode (toggled by M-x global-hl-line-mode) to highlight, on a | 29 | ;; and a global minor mode (toggled by M-x global-hl-line-mode) to |
| 30 | ;; suitable terminal, the line in the current window on which point is | 30 | ;; highlight, on a suitable terminal, the line on which point is. The |
| 31 | ;; (except in a minibuffer window). Done to satisfy a request for a | 31 | ;; global mode highlights the current line in the selected window only |
| 32 | ;; feature of Lesser Editors. | 32 | ;; (except when the minibuffer window is selected). This was |
| 33 | 33 | ;; implemented to satisfy a request for a feature of Lesser Editors. | |
| 34 | ;; You probably don't really want this; if the cursor is difficult to | 34 | ;; The local mode is sticky: it highlights the line about the buffer's |
| 35 | ;; spot, try changing its colour, relying on `blink-cursor-mode' or | 35 | ;; point even if the buffer's window is not selected. Caveat: the |
| 36 | ;; both. The hookery used might affect response noticeably on a slow | 36 | ;; buffer's point might be different from the point of a non-selected |
| 37 | ;; machine. It may be useful in "non-text" buffers such as Gnus or | 37 | ;; window. Set the variable `hl-line-sticky-flag' to nil to make the |
| 38 | ;; PCL-CVS though. | 38 | ;; local mode behave like the global mode. |
| 39 | 39 | ||
| 40 | ;; An overlay is used, active only on the selected window. Hooks are | 40 | ;; You probably don't really want to use the global mode; if the |
| 41 | ;; added to `pre-command-hook' and `post-command-hook' to activate and | 41 | ;; cursor is difficult to spot, try changing its colour, relying on |
| 42 | ;; deactivate (by deleting) the overlay. `hl-line-unhighlight', on | 42 | ;; `blink-cursor-mode' or both. The hookery used might affect |
| 43 | ;; `pre-command-hook', deactivates it unconditionally in case the | 43 | ;; response noticeably on a slow machine. The local mode may be |
| 44 | ;; command changes the selected window. (It does so rather than | 44 | ;; useful in non-editing buffers such as Gnus or PCL-CVS though. |
| 45 | ;; keeping track of changes in the selected window). | 45 | |
| 46 | ;; `hl-line-highlight', on `post-command-hook', activates it again | 46 | ;; An overlay is used. In the non-sticky cases, this overlay is |
| 47 | ;; across the window width. | 47 | ;; active only on the selected window. A hook is added to |
| 48 | ;; `post-command-hook' to activate the overlay and move it to the line | ||
| 49 | ;; about point. To get the non-sticky behavior, `hl-line-unhighlight' | ||
| 50 | ;; is added to `pre-command-hook' as well. This function deactivates | ||
| 51 | ;; the overlay unconditionally in case the command changes the | ||
| 52 | ;; selected window. (It does so rather than keeping track of changes | ||
| 53 | ;; in the selected window). | ||
| 54 | |||
| 55 | ;; You could make variable `global-hl-line-mode' buffer-local and set | ||
| 56 | ;; it to nil to avoid highlighting specific buffers, when the global | ||
| 57 | ;; mode is used. | ||
| 48 | 58 | ||
| 49 | ;;; Code: | 59 | ;;; Code: |
| 50 | 60 | ||
| @@ -58,46 +68,103 @@ | |||
| 58 | :type 'face | 68 | :type 'face |
| 59 | :group 'hl-line) | 69 | :group 'hl-line) |
| 60 | 70 | ||
| 61 | (defvar hl-line-overlay nil) | 71 | (defcustom hl-line-sticky-flag t |
| 72 | "*Non-nil means highlight the current line in all windows. | ||
| 73 | Otherwise Hl-Line mode will highlight only in the selected | ||
| 74 | window. Setting this variable takes effect the next time you use | ||
| 75 | the command `hl-line-mode' to turn Hl-Line mode on." | ||
| 76 | :type 'boolean | ||
| 77 | :version "21.4" | ||
| 78 | :group 'hl-line) | ||
| 79 | |||
| 80 | (defvar hl-line-overlay nil | ||
| 81 | "Overlay used by Hl-Line mode to highlight the current line.") | ||
| 82 | (make-variable-buffer-local 'hl-line-overlay) | ||
| 83 | |||
| 84 | (defvar global-hl-line-overlay nil | ||
| 85 | "Overlay used by Global-Hl-Line mode to highlight the current line.") | ||
| 62 | 86 | ||
| 63 | ;;;###autoload | 87 | ;;;###autoload |
| 64 | (define-minor-mode hl-line-mode | 88 | (define-minor-mode hl-line-mode |
| 65 | "Minor mode to highlight the line about point in the current window. | 89 | "Buffer-local minor mode to highlight the line about point. |
| 66 | With ARG, turn Hl-Line mode on if ARG is positive, off otherwise. | 90 | With ARG, turn Hl-Line mode on if ARG is positive, off otherwise. |
| 67 | Uses functions `hl-line-unhighlight' and `hl-line-highlight' on | 91 | |
| 68 | `pre-command-hook' and `post-command-hook'." | 92 | If `hl-line-sticky-flag' is non-nil, Hl-Line mode highlights the |
| 93 | line about the buffer's point in all windows. Caveat: the | ||
| 94 | buffer's point might be different from the point of a | ||
| 95 | non-selected window. Hl-Line mode uses the function | ||
| 96 | `hl-line-highlight' on `post-command-hook' in this case. | ||
| 97 | |||
| 98 | When `hl-line-sticky-flag' is nil, Hl-Line mode highlights the | ||
| 99 | line about point in the selected window only. In this case, it | ||
| 100 | uses the function `hl-line-unhighlight' on `pre-command-hook' in | ||
| 101 | addition to `hl-line-highlight' on `post-command-hook'." | ||
| 69 | nil nil nil | 102 | nil nil nil |
| 70 | (if hl-line-mode | 103 | (if hl-line-mode |
| 71 | (progn | 104 | (progn |
| 72 | (add-hook 'pre-command-hook #'hl-line-unhighlight nil t) | 105 | ;; In case `kill-all-local-variables' is called. |
| 106 | (add-hook 'change-major-mode-hook #'hl-line-unhighlight nil t) | ||
| 107 | (if hl-line-sticky-flag | ||
| 108 | (remove-hook 'pre-command-hook #'hl-line-unhighlight t) | ||
| 109 | (add-hook 'pre-command-hook #'hl-line-unhighlight nil t)) | ||
| 110 | (hl-line-highlight) | ||
| 73 | (add-hook 'post-command-hook #'hl-line-highlight nil t)) | 111 | (add-hook 'post-command-hook #'hl-line-highlight nil t)) |
| 112 | (remove-hook 'post-command-hook #'hl-line-highlight t) | ||
| 74 | (hl-line-unhighlight) | 113 | (hl-line-unhighlight) |
| 75 | (remove-hook 'pre-command-hook #'hl-line-unhighlight t) | 114 | (remove-hook 'change-major-mode-hook #'hl-line-unhighlight t) |
| 76 | (remove-hook 'post-command-hook #'hl-line-highlight t))) | 115 | (remove-hook 'pre-command-hook #'hl-line-unhighlight t))) |
| 77 | |||
| 78 | ;;;###autoload | ||
| 79 | (easy-mmode-define-global-mode | ||
| 80 | global-hl-line-mode hl-line-mode (lambda () (hl-line-mode 1)) | ||
| 81 | :group 'hl-line) | ||
| 82 | 116 | ||
| 83 | (defun hl-line-highlight () | 117 | (defun hl-line-highlight () |
| 84 | "Active the Hl-Line overlay on the current line in the current window. | 118 | "Active the Hl-Line overlay on the current line." |
| 85 | \(Unless it's a minibuffer window.)" | 119 | (if hl-line-mode ; Might be changed outside the mode function. |
| 86 | (when hl-line-mode ; Might be changed outside the mode function. | 120 | (progn |
| 87 | (unless (window-minibuffer-p (selected-window)) ; silly in minibuffer | 121 | (unless hl-line-overlay |
| 88 | (unless hl-line-overlay | 122 | (setq hl-line-overlay (make-overlay 1 1)) ; to be moved |
| 89 | (setq hl-line-overlay (make-overlay 1 1)) ; to be moved | 123 | (overlay-put hl-line-overlay 'face hl-line-face)) |
| 90 | (overlay-put hl-line-overlay 'face hl-line-face)) | 124 | (overlay-put hl-line-overlay |
| 91 | (overlay-put hl-line-overlay 'window (selected-window)) | 125 | 'window (unless hl-line-sticky-flag (selected-window))) |
| 92 | (move-overlay hl-line-overlay | 126 | (move-overlay hl-line-overlay |
| 93 | (line-beginning-position) (1+ (line-end-position)) | 127 | (line-beginning-position) (1+ (line-end-position)))) |
| 94 | (current-buffer))))) | 128 | (hl-line-unhighlight))) |
| 95 | 129 | ||
| 96 | (defun hl-line-unhighlight () | 130 | (defun hl-line-unhighlight () |
| 97 | "Deactivate the Hl-Line overlay on the current line in the current window." | 131 | "Deactivate the Hl-Line overlay on the current line." |
| 98 | (if hl-line-overlay | 132 | (if hl-line-overlay |
| 99 | (delete-overlay hl-line-overlay))) | 133 | (delete-overlay hl-line-overlay))) |
| 100 | 134 | ||
| 135 | ;;;###autoload | ||
| 136 | (define-minor-mode global-hl-line-mode | ||
| 137 | "Global minor mode to highlight the line about point in the current window. | ||
| 138 | With ARG, turn Global-Hl-Line mode on if ARG is positive, off otherwise. | ||
| 139 | |||
| 140 | Global-Hl-Line mode uses the functions `global-hl-line-unhighlight' and | ||
| 141 | `global-hl-line-highlight' on `pre-command-hook' and `post-command-hook'." | ||
| 142 | :global t | ||
| 143 | :group 'hl-line | ||
| 144 | (if global-hl-line-mode | ||
| 145 | (progn | ||
| 146 | (add-hook 'pre-command-hook #'global-hl-line-unhighlight) | ||
| 147 | (add-hook 'post-command-hook #'global-hl-line-highlight)) | ||
| 148 | (global-hl-line-unhighlight) | ||
| 149 | (remove-hook 'pre-command-hook #'global-hl-line-unhighlight) | ||
| 150 | (remove-hook 'post-command-hook #'global-hl-line-highlight))) | ||
| 151 | |||
| 152 | (defun global-hl-line-highlight () | ||
| 153 | "Active the Global-Hl-Line overlay on the current line in the current window." | ||
| 154 | (when global-hl-line-mode ; Might be changed outside the mode function. | ||
| 155 | (unless (window-minibuffer-p (selected-window)) | ||
| 156 | (unless global-hl-line-overlay | ||
| 157 | (setq global-hl-line-overlay (make-overlay 1 1)) ; to be moved | ||
| 158 | (overlay-put global-hl-line-overlay 'face hl-line-face)) | ||
| 159 | (overlay-put global-hl-line-overlay 'window (selected-window)) | ||
| 160 | (move-overlay global-hl-line-overlay | ||
| 161 | (line-beginning-position) (1+ (line-end-position)))))) | ||
| 162 | |||
| 163 | (defun global-hl-line-unhighlight () | ||
| 164 | "Deactivate the Global-Hl-Line overlay on the current line." | ||
| 165 | (if global-hl-line-overlay | ||
| 166 | (delete-overlay global-hl-line-overlay))) | ||
| 167 | |||
| 101 | (provide 'hl-line) | 168 | (provide 'hl-line) |
| 102 | 169 | ||
| 103 | ;;; hl-line.el ends here | 170 | ;;; hl-line.el ends here |