all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* PATCH: make linum.el play nicely with other margin-setting extensions
@ 2015-11-12 12:23 João Távora
  2015-11-12 16:24 ` Eli Zaretskii
  2015-11-13 10:01 ` martin rudalics
  0 siblings, 2 replies; 17+ messages in thread
From: João Távora @ 2015-11-12 12:23 UTC (permalink / raw)
  To: emacs-devel, markus.triska

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






^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2017-11-04 14:42 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-12 12:23 PATCH: make linum.el play nicely with other margin-setting extensions João Távora
2015-11-12 16:24 ` Eli Zaretskii
2015-11-13  8:32   ` João Távora
2015-11-13 12:23     ` Juanma Barranquero
2015-11-14  8:53     ` Eli Zaretskii
2015-11-15 14:19       ` João Távora
2015-11-15 19:39         ` Eli Zaretskii
     [not found]           ` <CALDnm521uDOtxE407+pWnq6W=SLLndxp+xmJ1Twtjz3wub8oiQ@mail.gmail.com>
     [not found]             ` <jwvpoza3g89.fsf-monnier+Inbox@gnu.org>
2015-11-17 22:35               ` bug#20674: " João Távora
2017-11-04 14:42                 ` Noam Postavsky
2015-11-16  9:24         ` Yuri Khan
     [not found]           ` <CALDnm53Gkm7p2-O-xYf4xMBYPM8sqt2bG5ug-tZu3RKAUE1-gw@mail.gmail.com>
     [not found]             ` <CAP_d_8VPyasNi21JKMRX+Hz55G5-CwtXuwS3FjXx4Ucp3UDKew@mail.gmail.com>
     [not found]               ` <CALDnm50EPe8HCucQEnHPadDHwVmgjN8DmeJ+kvh2Nbtb2tYeZw@mail.gmail.com>
     [not found]                 ` <CAP_d_8UjQQuM_45dzUWCGL6Y=3vJ+uZayyqSz1k+sAFmLEN-VQ@mail.gmail.com>
2015-11-16 14:49                   ` João Távora
2015-11-13 10:01 ` martin rudalics
2015-11-13 11:11   ` João Távora
2015-11-13 14:53     ` martin rudalics
2015-11-13 15:32       ` João Távora
2015-11-14  8:27         ` martin rudalics
2015-11-14 19:55           ` João Távora

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.