aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Távora2015-11-17 22:23:59 +0000
committerJoão Távora2015-11-17 22:24:53 +0000
commitb92307f6708f9abff0b2ac242fe4b668232a9153 (patch)
tree81e26c05aadb79e6554dedb197b9d50346f37dd4
parent58e6235007e6761fb9734b942ecff94bf4e9ba68 (diff)
downloademacs-b92307f6708f9abff0b2ac242fe4b668232a9153.tar.gz
emacs-b92307f6708f9abff0b2ac242fe4b668232a9153.zip
linum-mode plays more nicely with other margin-setting extensions
linum.el will only modify the left margin if it needs to, and will only reset the it back to 0 if it guesses that no-one has touched that margin in the meantime. As such, this is a more of a workaround than an actual fix, but fixes the problems described in bug#20674 regarding the interaction with modes such as darkroom-mode and olivetti-mode. A similar fix was commited to nlinum.el in ELPA.git's e7f5f549fbfb740b911fb7f33b42381ecece56d8 * linum.el (linum-delete-overlays): Restore margins more criteriously. (linum-update-window): Set margins more criteriously.
-rw-r--r--lisp/linum.el23
1 files changed, 18 insertions, 5 deletions
diff --git a/lisp/linum.el b/lisp/linum.el
index 7b6a3ea4e42..82c192e94c0 100644
--- a/lisp/linum.el
+++ b/lisp/linum.el
@@ -120,7 +120,15 @@ Linum mode is a buffer-local minor mode."
120 (mapc #'delete-overlay linum-overlays) 120 (mapc #'delete-overlay linum-overlays)
121 (setq linum-overlays nil) 121 (setq linum-overlays nil)
122 (dolist (w (get-buffer-window-list (current-buffer) nil t)) 122 (dolist (w (get-buffer-window-list (current-buffer) nil t))
123 (set-window-margins w 0 (cdr (window-margins w))))) 123 ;; restore margins if needed FIXME: This still fails if the
124 ;; "other" mode has incidently set margins to exactly what linum
125 ;; had: see bug#20674 for a similar workaround in nlinum.el
126 (let ((set-margins (window-parameter w 'linum--set-margins))
127 (current-margins (window-margins w)))
128 (when (and set-margins
129 (equal set-margins current-margins))
130 (set-window-margins w 0 (cdr current-margins))
131 (set-window-parameter w 'linum--set-margins nil)))))
124 132
125(defun linum-update-current () 133(defun linum-update-current ()
126 "Update line numbers for the current buffer." 134 "Update line numbers for the current buffer."
@@ -143,10 +151,10 @@ Linum mode is a buffer-local minor mode."
143 151
144(defun linum--face-width (face) 152(defun linum--face-width (face)
145 (let ((info (font-info (face-font face))) 153 (let ((info (font-info (face-font face)))
146 width) 154 width)
147 (setq width (aref info 11)) 155 (setq width (aref info 11))
148 (if (<= width 0) 156 (if (<= width 0)
149 (setq width (aref info 10))) 157 (setq width (aref info 10)))
150 width)) 158 width))
151 159
152(defun linum-update-window (win) 160(defun linum-update-window (win)
@@ -170,7 +178,7 @@ Linum mode is a buffer-local minor mode."
170 (visited (catch 'visited 178 (visited (catch 'visited
171 (dolist (o (overlays-in (point) (point))) 179 (dolist (o (overlays-in (point) (point)))
172 (when (equal-including-properties 180 (when (equal-including-properties
173 (overlay-get o 'linum-str) str) 181 (overlay-get o 'linum-str) str)
174 (unless (memq o linum-overlays) 182 (unless (memq o linum-overlays)
175 (push o linum-overlays)) 183 (push o linum-overlays))
176 (setq linum-available (delq o linum-available)) 184 (setq linum-available (delq o linum-available))
@@ -193,7 +201,12 @@ Linum mode is a buffer-local minor mode."
193 (setq width (ceiling 201 (setq width (ceiling
194 (/ (* width 1.0 (linum--face-width 'linum)) 202 (/ (* width 1.0 (linum--face-width 'linum))
195 (frame-char-width))))) 203 (frame-char-width)))))
196 (set-window-margins win width (cdr (window-margins win))))) 204 ;; open up space in the left margin, if needed, and record that
205 ;; fact as a the window-parameter `linum--set-margins'
206 (let ((existing-margins (window-margins win)))
207 (when (> width (or (car existing-margins) 0))
208 (set-window-margins win width (cdr existing-margins))
209 (set-window-parameter win 'linum--set-margins (window-margins win))))))
197 210
198(defun linum-after-change (beg end _len) 211(defun linum-after-change (beg end _len)
199 ;; update overlays on deletions, and after newlines are inserted 212 ;; update overlays on deletions, and after newlines are inserted