annotate lisp/linum.el @ 102619:f40356cf5650

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