emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

PATCH: make linum.el play nicely with other margin-setting extensions


From: João Távora
Subject: PATCH: make linum.el play nicely with other margin-setting extensions
Date: Thu, 12 Nov 2015 12:23:02 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (windows-nt)

The problem popped up in darkroom.el which is in ELPA. The margins
aren't correctly in any situation intermingling calls to M-x linum-mode
and M-x darkroom-mode.

This patch to linum.el appears to work nicely, and probably fixes stuff
for other margin-setting extensions, but I'd like a review from the
maintainer or someone else more knowledgeable:

diff --git a/lisp/linum.el b/lisp/linum.el
index 23e5605..776247d 100644
--- a/lisp/linum.el
+++ b/lisp/linum.el
@@ -120,7 +120,13 @@ Linum mode is a buffer-local minor mode."
   (mapc #'delete-overlay linum-overlays)
   (setq linum-overlays nil)
   (dolist (w (get-buffer-window-list (current-buffer) nil t))
-    (set-window-margins w 0 (cdr (window-margins w)))))
+    ;; restore margins if needed
+    (let ((set-margins (window-parameter w 'linum--set-margins))
+          (current-margins (window-margins w)))
+      (when (and set-margins
+                 (equal set-margins current-margins))
+        (set-window-margins w 0 (cdr current-margins))
+        (set-window-parameter w 'linum--set-margins nil)))))
 
 (defun linum-update-current ()
   "Update line numbers for the current buffer."
@@ -178,7 +184,12 @@ Linum mode is a buffer-local minor mode."
       (let ((inhibit-point-motion-hooks t))
         (forward-line))
       (setq line (1+ line)))
-    (set-window-margins win width (cdr (window-margins win)))))
+    ;; open up space in the left margin, if needed, and record that
+    ;; fact as a the window-parameter `linum--set-margins'
+    (let ((existing-margins (window-margins win)))
+      (when (> width (or (car existing-margins) 0))
+        (set-window-margins win width (cdr existing-margins))
+        (set-window-parameter win 'linum--set-margins (window-margins win))))))
 
 (defun linum-after-change (beg end _len)
   ;; update overlays on deletions, and after newlines are inserted


Thanks,
João






reply via email to

[Prev in Thread] Current Thread [Next in Thread]