annotate lisp/linum.el @ 92228:0d777f362195

*** empty log message ***
author Glenn Morris <rgm@gnu.org>
date Tue, 26 Feb 2008 04:31:30 +0000
parents 87d23b09ce4d
children ee5932bf781d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
88073
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
1 ;;; linum.el --- display line numbers in the left margin
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
2
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
3 ;; Copyright (C) 2008 Free Software Foundation, Inc.
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
4
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
5 ;; Author: Markus Triska <markus.triska@gmx.at>
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
6 ;; Maintainer: FSF
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
7 ;; Keywords: convenience
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
8
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
10
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 3, or (at your option)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
14 ;; any later version.
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
15
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
19 ;; GNU General Public License for more details.
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
20
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
24 ;; Boston, MA 02110-1301, USA.
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
25
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
26 ;;; Commentary:
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
27
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
28 ;; Display line numbers for the current buffer.
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
29 ;;
88075
77e6cba71081 Update comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 88073
diff changeset
30 ;; Toggle display of line numbers with M-x linum-mode. To enable
88073
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
31 ;; line numbering in all buffers, use M-x global-linum-mode.
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
32
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
33 ;;; Code:
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
34
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
35 (defconst linum-version "0.9wx")
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
36
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
37 (defvar linum-overlays nil "Overlays used in this buffer.")
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
38 (defvar linum-available nil "Overlays available for reuse.")
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
39 (defvar linum-before-numbering-hook nil
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
40 "Functions run in each buffer before line numbering starts.")
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
41
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
42 (mapc #'make-variable-buffer-local '(linum-overlays linum-available))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
43
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
44 (defgroup linum nil
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
45 "Show line numbers in the left margin."
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
46 :group 'convenience)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
47
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
48 ;;;###autoload
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
49 (defcustom linum-format 'dynamic
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
50 "Format used to display line numbers.
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
51 Either a format string like \"%7d\", `dynamic' to adapt the width
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
52 as needed, or a function that is called with a line number as its
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
53 argument and should evaluate to a string to be shown on that line.
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
54 See also `linum-before-numbering-hook'."
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
55 :group 'linum
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
56 :type 'sexp)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
57
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
58 (defface linum
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
59 '((t :inherit shadow))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
60 "Face for displaying line numbers in the display margin."
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
61 :group 'linum)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
62
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
63 (defcustom linum-eager t
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
64 "Whether line numbers should be updated after each command.
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
65 The conservative setting `nil' might miss some buffer changes,
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
66 and you have to scroll or press \\[recenter-top-bottom] to update the numbers."
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
67 :group 'linum
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
68 :type 'boolean)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
69
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
70 (defcustom linum-delay t
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
71 "Delay updates to give Emacs a chance for other changes."
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
72 :group 'linum
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
73 :type 'boolean)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
74
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
75 ;;;###autoload
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
76 (define-minor-mode linum-mode
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
77 "Toggle display of line numbers in the left margin."
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
78 :lighter "" ; for desktop.el
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
79 (if linum-mode
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
80 (progn
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
81 (if linum-eager
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
82 (add-hook 'post-command-hook (if linum-delay
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
83 'linum-schedule
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
84 'linum-update-current) nil t)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
85 (add-hook 'after-change-functions 'linum-after-change nil t))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
86 (add-hook 'window-scroll-functions 'linum-after-scroll nil t)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
87 ;; mistake in Emacs: window-size-change-functions cannot be local
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
88 (add-hook 'window-size-change-functions 'linum-after-size)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
89 (add-hook 'change-major-mode-hook 'linum-delete-overlays nil t)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
90 (add-hook 'window-configuration-change-hook
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
91 'linum-after-config nil t)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
92 (linum-update-current))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
93 (remove-hook 'post-command-hook 'linum-update-current t)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
94 (remove-hook 'post-command-hook 'linum-schedule t)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
95 (remove-hook 'window-size-change-functions 'linum-after-size)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
96 (remove-hook 'window-scroll-functions 'linum-after-scroll t)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
97 (remove-hook 'after-change-functions 'linum-after-change t)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
98 (remove-hook 'window-configuration-change-hook 'linum-after-config t)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
99 (remove-hook 'change-major-mode-hook 'linum-delete-overlays t)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
100 (linum-delete-overlays)))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
101
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
102 ;;;###autoload
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
103 (define-globalized-minor-mode global-linum-mode linum-mode linum-on)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
104
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
105 (defun linum-on ()
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
106 (unless (minibufferp)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
107 (linum-mode 1)))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
108
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
109 (defun linum-delete-overlays ()
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
110 "Delete all overlays displaying line numbers for this buffer."
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
111 (mapc #'delete-overlay linum-overlays)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
112 (setq linum-overlays nil)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
113 (dolist (w (get-buffer-window-list (current-buffer) nil t))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
114 (set-window-margins w 0)))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
115
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
116 (defun linum-update-current ()
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
117 "Update line numbers for the current buffer."
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
118 (linum-update (current-buffer)))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
119
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
120 (defun linum-update (buffer)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
121 "Update line numbers for all windows displaying BUFFER."
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
122 (with-current-buffer buffer
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
123 (when linum-mode
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
124 (setq linum-available linum-overlays)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
125 (setq linum-overlays nil)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
126 (save-excursion
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
127 (mapc #'linum-update-window
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
128 (get-buffer-window-list buffer nil 'visible)))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
129 (mapc #'delete-overlay linum-available)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
130 (setq linum-available nil))))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
131
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
132 (defun linum-update-window (win)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
133 "Update line numbers for the portion visible in window WIN."
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
134 (goto-char (window-start win))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
135 (let ((line (line-number-at-pos))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
136 (limit (1+ (window-end win t)))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
137 (fmt (cond ((stringp linum-format) linum-format)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
138 ((eq linum-format 'dynamic)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
139 (let ((w (length (number-to-string
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
140 (count-lines (point-min) (point-max))))))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
141 (concat "%" (number-to-string w) "d")))))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
142 (width 0)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
143 visited
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
144 ov)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
145 (run-hooks 'linum-before-numbering-hook)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
146 ;; Create an overlay (or reuse an existing one) for each
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
147 ;; line visible in this window, if necessary.
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
148 (while (and (not (eobp)) (< (point) limit))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
149 (setq visited nil)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
150 (dolist (o (overlays-in (point) (point)))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
151 (when (eq (overlay-get o 'linum-line) line)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
152 (unless (memq o linum-overlays)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
153 (push o linum-overlays))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
154 (setq linum-available (delete o linum-available))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
155 (setq visited t)))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
156 (let ((str (if fmt
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
157 (propertize (format fmt line) 'face 'linum)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
158 (funcall linum-format line))))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
159 (setq width (max width (length str)))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
160 (unless visited
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
161 (if (null linum-available)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
162 (setq ov (make-overlay (point) (point)))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
163 (setq ov (pop linum-available))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
164 (move-overlay ov (point) (point)))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
165 (push ov linum-overlays)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
166 (setq str (propertize " " 'display `((margin left-margin) ,str)))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
167 (overlay-put ov 'before-string str)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
168 (overlay-put ov 'linum-line line)))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
169 (forward-line)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
170 (setq line (1+ line)))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
171 (set-window-margins win width)))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
172
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
173 (defun linum-after-change (beg end len)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
174 ;; update overlays on deletions, and after newlines are inserted
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
175 (when (or (= beg end)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
176 (= end (point-max))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
177 (string-match-p "\n" (buffer-substring-no-properties beg end)))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
178 (linum-update-current)))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
179
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
180 (defun linum-after-scroll (win start)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
181 (linum-update (window-buffer win)))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
182
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
183 (defun linum-after-size (frame)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
184 (linum-after-config))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
185
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
186 (defun linum-schedule ()
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
187 ;; schedule an update; the delay gives Emacs a chance for display changes
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
188 (run-with-idle-timer 0 nil #'linum-update-current))
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
189
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
190 (defun linum-after-config ()
92141
87d23b09ce4d (linum-after-config): Update all visible windows.
Juanma Barranquero <lekktu@gmail.com>
parents: 88090
diff changeset
191 (walk-windows (lambda (w) (linum-update (window-buffer w))) nil 'visible))
88073
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
192
88090
b796e645bb4e (linum-unload-function): New function.
Juanma Barranquero <lekktu@gmail.com>
parents: 88076
diff changeset
193 (defun linum-unload-function ()
b796e645bb4e (linum-unload-function): New function.
Juanma Barranquero <lekktu@gmail.com>
parents: 88076
diff changeset
194 "Unload the Linum library."
b796e645bb4e (linum-unload-function): New function.
Juanma Barranquero <lekktu@gmail.com>
parents: 88076
diff changeset
195 (global-linum-mode -1)
b796e645bb4e (linum-unload-function): New function.
Juanma Barranquero <lekktu@gmail.com>
parents: 88076
diff changeset
196 ;; continue standard unloading
b796e645bb4e (linum-unload-function): New function.
Juanma Barranquero <lekktu@gmail.com>
parents: 88076
diff changeset
197 nil)
b796e645bb4e (linum-unload-function): New function.
Juanma Barranquero <lekktu@gmail.com>
parents: 88076
diff changeset
198
88073
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
199 (provide 'linum)
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
200
88076
7caa67533b3a Add arch tagline
Miles Bader <miles@gnu.org>
parents: 88075
diff changeset
201 ;; arch-tag: dea45631-ed3c-4867-8b49-1c41c80aec6a
88073
c720c7381645 New file.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
202 ;;; linum.el ends here