From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: joaotavora@gmail.com (=?iso-8859-1?Q?Jo=E3o_T=E1vora?=) Newsgroups: gmane.emacs.devel Subject: PATCH: make linum.el play nicely with other margin-setting extensions Date: Thu, 12 Nov 2015 12:23:02 +0000 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1447331021 22428 80.91.229.3 (12 Nov 2015 12:23:41 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 12 Nov 2015 12:23:41 +0000 (UTC) To: emacs-devel@gnu.org, markus.triska@gmx.at Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Nov 12 13:23:40 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZwquT-0005Zr-1g for ged-emacs-devel@m.gmane.org; Thu, 12 Nov 2015 13:23:25 +0100 Original-Received: from localhost ([::1]:46252 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwquS-0003nN-De for ged-emacs-devel@m.gmane.org; Thu, 12 Nov 2015 07:23:24 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46260) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwquE-0003ms-M4 for emacs-devel@gnu.org; Thu, 12 Nov 2015 07:23:11 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZwquB-000180-H8 for emacs-devel@gnu.org; Thu, 12 Nov 2015 07:23:10 -0500 Original-Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]:37594) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwquB-00017o-3u for emacs-devel@gnu.org; Thu, 12 Nov 2015 07:23:07 -0500 Original-Received: by wmww144 with SMTP id w144so85910116wmw.0 for ; Thu, 12 Nov 2015 04:23:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:user-agent:mime-version :content-type:content-transfer-encoding; bh=v5BzUCbso5RoS2xn6ds+Rh7pI+h/UxIwHx6uONaMryM=; b=BiJFKBcV/mNaxq/28o9NK8uj/5+157yZMzx92RqXBPXf9JTqyIduEzIuoJiQK7artd abMYl89iv8m7sQGN55mEsaK7qIzuitD0VEv6vbrduwClARhXQ+Z/3yxCBxgbZX1LEKQU khkAtqNbY3F4jxveuIeLlgb/nmJrmhh6lS+HRJb0MyCP6YCAVsM6HTDSQFiFhf5n6Vqm maT4G/CqNVje1wPii55ZaE0lzbKCzr+BoDa96gj5x+SQY+FG3B3qJJraK4PPPjpEO5gg nkL7AObFU2lIcayWhmfYtMbV8KFakFdMg9Ovd8hoJgrVWmSt3M9HbNTame8srD6f9/EM ZMqg== X-Received: by 10.28.30.208 with SMTP id e199mr27910578wme.22.1447330985306; Thu, 12 Nov 2015 04:23:05 -0800 (PST) Original-Received: from GONDOMAR.yourcompany.com (mail1.siscog.pt. [93.108.236.53]) by smtp.gmail.com with ESMTPSA id vr10sm14193823wjc.38.2015.11.12.04.23.03 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Nov 2015 04:23:04 -0800 (PST) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (windows-nt) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c09::231 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:194218 Archived-At: 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))))) =20 (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)= ))))) =20 (defun linum-after-change (beg end _len) ;; update overlays on deletions, and after newlines are inserted Thanks, Jo=E3o