all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* UI glitch with text-scale-increase / text-scale-decrease with linum / nlinum
@ 2015-02-08 19:42 Gauthier Segay
  2015-02-09 14:57 ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: Gauthier Segay @ 2015-02-08 19:42 UTC (permalink / raw
  To: help-gnu-emacs; +Cc: monnier, markus.triska

I've setup this
http://ergoemacs.org/emacs/emacs_mouse_wheel_config.html

;; on Linux, make Control+wheel do increase/decrease font size
(global-set-key (kbd "<C-mouse-4>") 'text-scale-increase)
(global-set-key (kbd "<C-mouse-5>") 'text-scale-decrease)

The issue is that linum or nlinum doesn't notice the change, the line
number gutter doesn'adjust it's width.

The work around is to disable and enable again those modes.

How can this be done in the above script?

Can this somehow be handled by linum/nlinum modes whenever the
text-scale or font is changed?

Thanks for your help.



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

* Re: UI glitch with text-scale-increase / text-scale-decrease with linum / nlinum
  2015-02-08 19:42 UI glitch with text-scale-increase / text-scale-decrease with linum / nlinum Gauthier Segay
@ 2015-02-09 14:57 ` Stefan Monnier
  2015-02-09 15:58   ` Gauthier Segay
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2015-02-09 14:57 UTC (permalink / raw
  To: Gauthier Segay; +Cc: help-gnu-emacs, markus.triska

> (global-set-key (kbd "<C-mouse-4>") 'text-scale-increase)
> (global-set-key (kbd "<C-mouse-5>") 'text-scale-decrease)
> The issue is that linum or nlinum doesn't notice the change, the line
> number gutter doesn'adjust it's width.

Can you test the patch below (for nlinum.el) to see if it solves
your problem?


        Stefan


diff --git a/packages/nlinum/nlinum.el b/packages/nlinum/nlinum.el
index 82e274c..ca15800 100644
--- a/packages/nlinum/nlinum.el
+++ b/packages/nlinum/nlinum.el
@@ -1,6 +1,6 @@
 ;;; nlinum.el --- Show line numbers in the margin  -*- lexical-binding: t -*-
 
-;; Copyright (C) 2012, 2014  Free Software Foundation, Inc.
+;; Copyright (C) 2012, 2014, 2015  Free Software Foundation, Inc.
 
 ;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
 ;; Keywords: convenience
@@ -54,6 +54,7 @@ Linum mode is a buffer-local minor mode."
   :lighter nil ;; (" NLinum" nlinum--desc)
   (jit-lock-unregister #'nlinum--region)
   (remove-hook 'window-configuration-change-hook #'nlinum--setup-window t)
+  (remove-hook 'text-scale-mode #'nlinum--setup-window t)
   (remove-hook 'after-change-functions #'nlinum--after-change t)
   (kill-local-variable 'nlinum--line-number-cache)
   (remove-overlays (point-min) (point-max) 'nlinum t)
@@ -63,6 +64,7 @@ Linum mode is a buffer-local minor mode."
     ;; FIXME: Another approach would be to make the mode permanent-local,
     ;; which might indeed be preferable.
     (add-hook 'change-major-mode-hook (lambda () (nlinum-mode -1)))
+    (add-hook 'text-scale-mode #'nlinum--setup-window nil t)
     (add-hook 'window-configuration-change-hook #'nlinum--setup-window nil t)
     (add-hook 'after-change-functions #'nlinum--after-change nil t)
     (jit-lock-register #'nlinum--region t))
@@ -71,14 +73,24 @@ Linum mode is a buffer-local minor mode."
 (defun nlinum--face-height (face)
   (aref (font-info (face-font face)) 2))
 
+(defun nlinum--face-width (face)        ;New info only in Emacs>=25.
+  (let ((fi (font-info (face-font face))))
+    (when (> (length fi) 11)
+      (let ((width (aref info 11)))
+        (if (<= width 0)
+            (aref info 10)
+          width)))))
+
 (defun nlinum--setup-window ()
   (let ((width (if (display-graphic-p)
                    (ceiling
-                    ;; We'd really want to check the widths rather than the
-                    ;; heights, but it's a start.
-                    (/ (* nlinum--width 1.0
-                          (nlinum--face-height 'linum))
-                       (frame-char-height)))
+                    (let ((width (nlinum--face-width 'linum)))
+                      (if width
+                          (/ (* nlinum--width 1.0 width)
+                             (frame-char-width))
+                        (/ (* nlinum--width 1.0
+                              (nlinum--face-height 'linum))
+                           (frame-char-height)))))
                  nlinum--width)))
     (set-window-margins nil (if nlinum-mode width)
                         (cdr (window-margins)))))



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

* Re: UI glitch with text-scale-increase / text-scale-decrease with linum / nlinum
  2015-02-09 14:57 ` Stefan Monnier
@ 2015-02-09 15:58   ` Gauthier Segay
  2015-02-09 17:01     ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: Gauthier Segay @ 2015-02-09 15:58 UTC (permalink / raw
  To: Stefan Monnier; +Cc: help-gnu-emacs, markus.triska

Hello Stefan, thanks for the update.

I tried on this setup:

GNU Emacs 24.4.1 (i686-pc-mingw32) of 2014-10-24 on LEG570

I disabled my theme/font settings (to ensure it doesn't interfere),
patched the file, recompiled the extensions, but I still notice the
same issue happening.

That being said, when I issue M-x text-scale-increase (or decrease)
instead of using ctrl+wheel , it seems to work properly and adjust the
gutter, so I guess this is not necessarily an issue with the
extension.

I'll appreciate if someone can show me how to define my own function
which disables nlinum, calls the text-scale functions and enables
nlinum back; and how to attach that function to the hook.

Thanks.

On Mon, Feb 9, 2015 at 3:57 PM, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> (global-set-key (kbd "<C-mouse-4>") 'text-scale-increase)
>> (global-set-key (kbd "<C-mouse-5>") 'text-scale-decrease)
>> The issue is that linum or nlinum doesn't notice the change, the line
>> number gutter doesn'adjust it's width.
>
> Can you test the patch below (for nlinum.el) to see if it solves
> your problem?
>
>
>         Stefan
>
>
> diff --git a/packages/nlinum/nlinum.el b/packages/nlinum/nlinum.el
> index 82e274c..ca15800 100644
> --- a/packages/nlinum/nlinum.el
> +++ b/packages/nlinum/nlinum.el
> @@ -1,6 +1,6 @@
>  ;;; nlinum.el --- Show line numbers in the margin  -*- lexical-binding: t -*-
>
> -;; Copyright (C) 2012, 2014  Free Software Foundation, Inc.
> +;; Copyright (C) 2012, 2014, 2015  Free Software Foundation, Inc.
>
>  ;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
>  ;; Keywords: convenience
> @@ -54,6 +54,7 @@ Linum mode is a buffer-local minor mode."
>    :lighter nil ;; (" NLinum" nlinum--desc)
>    (jit-lock-unregister #'nlinum--region)
>    (remove-hook 'window-configuration-change-hook #'nlinum--setup-window t)
> +  (remove-hook 'text-scale-mode #'nlinum--setup-window t)
>    (remove-hook 'after-change-functions #'nlinum--after-change t)
>    (kill-local-variable 'nlinum--line-number-cache)
>    (remove-overlays (point-min) (point-max) 'nlinum t)
> @@ -63,6 +64,7 @@ Linum mode is a buffer-local minor mode."
>      ;; FIXME: Another approach would be to make the mode permanent-local,
>      ;; which might indeed be preferable.
>      (add-hook 'change-major-mode-hook (lambda () (nlinum-mode -1)))
> +    (add-hook 'text-scale-mode #'nlinum--setup-window nil t)
>      (add-hook 'window-configuration-change-hook #'nlinum--setup-window nil t)
>      (add-hook 'after-change-functions #'nlinum--after-change nil t)
>      (jit-lock-register #'nlinum--region t))
> @@ -71,14 +73,24 @@ Linum mode is a buffer-local minor mode."
>  (defun nlinum--face-height (face)
>    (aref (font-info (face-font face)) 2))
>
> +(defun nlinum--face-width (face)        ;New info only in Emacs>=25.
> +  (let ((fi (font-info (face-font face))))
> +    (when (> (length fi) 11)
> +      (let ((width (aref info 11)))
> +        (if (<= width 0)
> +            (aref info 10)
> +          width)))))
> +
>  (defun nlinum--setup-window ()
>    (let ((width (if (display-graphic-p)
>                     (ceiling
> -                    ;; We'd really want to check the widths rather than the
> -                    ;; heights, but it's a start.
> -                    (/ (* nlinum--width 1.0
> -                          (nlinum--face-height 'linum))
> -                       (frame-char-height)))
> +                    (let ((width (nlinum--face-width 'linum)))
> +                      (if width
> +                          (/ (* nlinum--width 1.0 width)
> +                             (frame-char-width))
> +                        (/ (* nlinum--width 1.0
> +                              (nlinum--face-height 'linum))
> +                           (frame-char-height)))))
>                   nlinum--width)))
>      (set-window-margins nil (if nlinum-mode width)
>                          (cdr (window-margins)))))



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

* Re: UI glitch with text-scale-increase / text-scale-decrease with linum / nlinum
  2015-02-09 15:58   ` Gauthier Segay
@ 2015-02-09 17:01     ` Stefan Monnier
  2015-02-09 17:22       ` Gauthier Segay
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2015-02-09 17:01 UTC (permalink / raw
  To: help-gnu-emacs

> I disabled my theme/font settings (to ensure it doesn't interfere),
> patched the file, recompiled the extensions, but I still notice the
> same issue happening.

Duh!  I diff'd the wrong file.  Here's the patch I had tested.


        Stefan


diff --git a/packages/nlinum/nlinum.el b/packages/nlinum/nlinum.el
index 82e274c..67b3717 100644
--- a/packages/nlinum/nlinum.el
+++ b/packages/nlinum/nlinum.el
@@ -1,6 +1,6 @@
 ;;; nlinum.el --- Show line numbers in the margin  -*- lexical-binding: t -*-
 
-;; Copyright (C) 2012, 2014  Free Software Foundation, Inc.
+;; Copyright (C) 2012, 2014, 2015  Free Software Foundation, Inc.
 
 ;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
 ;; Keywords: convenience
@@ -54,6 +54,7 @@ Linum mode is a buffer-local minor mode."
   :lighter nil ;; (" NLinum" nlinum--desc)
   (jit-lock-unregister #'nlinum--region)
   (remove-hook 'window-configuration-change-hook #'nlinum--setup-window t)
+  (remove-hook 'text-scale-mode-hook #'nlinum--setup-window t)
   (remove-hook 'after-change-functions #'nlinum--after-change t)
   (kill-local-variable 'nlinum--line-number-cache)
   (remove-overlays (point-min) (point-max) 'nlinum t)
@@ -63,6 +64,7 @@ Linum mode is a buffer-local minor mode."
     ;; FIXME: Another approach would be to make the mode permanent-local,
     ;; which might indeed be preferable.
     (add-hook 'change-major-mode-hook (lambda () (nlinum-mode -1)))
+    (add-hook 'text-scale-mode-hook #'nlinum--setup-window nil t)
     (add-hook 'window-configuration-change-hook #'nlinum--setup-window nil t)
     (add-hook 'after-change-functions #'nlinum--after-change nil t)
     (jit-lock-register #'nlinum--region t))
@@ -71,14 +73,24 @@ Linum mode is a buffer-local minor mode."
 (defun nlinum--face-height (face)
   (aref (font-info (face-font face)) 2))
 
+(defun nlinum--face-width (face)        ;New info only in Emacs>=25.
+  (let ((fi (font-info (face-font face))))
+    (when (> (length fi) 11)
+      (let ((width (aref fi 11)))
+        (if (<= width 0)
+            (aref fi 10)
+          width)))))
+
 (defun nlinum--setup-window ()
   (let ((width (if (display-graphic-p)
                    (ceiling
-                    ;; We'd really want to check the widths rather than the
-                    ;; heights, but it's a start.
-                    (/ (* nlinum--width 1.0
-                          (nlinum--face-height 'linum))
-                       (frame-char-height)))
+                    (let ((width (nlinum--face-width 'linum)))
+                      (if width
+                          (/ (* nlinum--width 1.0 width)
+                             (frame-char-width))
+                        (/ (* nlinum--width 1.0
+                              (nlinum--face-height 'linum))
+                           (frame-char-height)))))
                  nlinum--width)))
     (set-window-margins nil (if nlinum-mode width)
                         (cdr (window-margins)))))




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

* Re: UI glitch with text-scale-increase / text-scale-decrease with linum / nlinum
  2015-02-09 17:01     ` Stefan Monnier
@ 2015-02-09 17:22       ` Gauthier Segay
  0 siblings, 0 replies; 5+ messages in thread
From: Gauthier Segay @ 2015-02-09 17:22 UTC (permalink / raw
  To: Stefan Monnier; +Cc: help-gnu-emacs

Hey, that works!

Thanks

On Mon, Feb 9, 2015 at 6:01 PM, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> I disabled my theme/font settings (to ensure it doesn't interfere),
>> patched the file, recompiled the extensions, but I still notice the
>> same issue happening.
>
> Duh!  I diff'd the wrong file.  Here's the patch I had tested.
>
>
>         Stefan
>
>
> diff --git a/packages/nlinum/nlinum.el b/packages/nlinum/nlinum.el
> index 82e274c..67b3717 100644
> --- a/packages/nlinum/nlinum.el
> +++ b/packages/nlinum/nlinum.el
> @@ -1,6 +1,6 @@
>  ;;; nlinum.el --- Show line numbers in the margin  -*- lexical-binding: t -*-
>
> -;; Copyright (C) 2012, 2014  Free Software Foundation, Inc.
> +;; Copyright (C) 2012, 2014, 2015  Free Software Foundation, Inc.
>
>  ;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
>  ;; Keywords: convenience
> @@ -54,6 +54,7 @@ Linum mode is a buffer-local minor mode."
>    :lighter nil ;; (" NLinum" nlinum--desc)
>    (jit-lock-unregister #'nlinum--region)
>    (remove-hook 'window-configuration-change-hook #'nlinum--setup-window t)
> +  (remove-hook 'text-scale-mode-hook #'nlinum--setup-window t)
>    (remove-hook 'after-change-functions #'nlinum--after-change t)
>    (kill-local-variable 'nlinum--line-number-cache)
>    (remove-overlays (point-min) (point-max) 'nlinum t)
> @@ -63,6 +64,7 @@ Linum mode is a buffer-local minor mode."
>      ;; FIXME: Another approach would be to make the mode permanent-local,
>      ;; which might indeed be preferable.
>      (add-hook 'change-major-mode-hook (lambda () (nlinum-mode -1)))
> +    (add-hook 'text-scale-mode-hook #'nlinum--setup-window nil t)
>      (add-hook 'window-configuration-change-hook #'nlinum--setup-window nil t)
>      (add-hook 'after-change-functions #'nlinum--after-change nil t)
>      (jit-lock-register #'nlinum--region t))
> @@ -71,14 +73,24 @@ Linum mode is a buffer-local minor mode."
>  (defun nlinum--face-height (face)
>    (aref (font-info (face-font face)) 2))
>
> +(defun nlinum--face-width (face)        ;New info only in Emacs>=25.
> +  (let ((fi (font-info (face-font face))))
> +    (when (> (length fi) 11)
> +      (let ((width (aref fi 11)))
> +        (if (<= width 0)
> +            (aref fi 10)
> +          width)))))
> +
>  (defun nlinum--setup-window ()
>    (let ((width (if (display-graphic-p)
>                     (ceiling
> -                    ;; We'd really want to check the widths rather than the
> -                    ;; heights, but it's a start.
> -                    (/ (* nlinum--width 1.0
> -                          (nlinum--face-height 'linum))
> -                       (frame-char-height)))
> +                    (let ((width (nlinum--face-width 'linum)))
> +                      (if width
> +                          (/ (* nlinum--width 1.0 width)
> +                             (frame-char-width))
> +                        (/ (* nlinum--width 1.0
> +                              (nlinum--face-height 'linum))
> +                           (frame-char-height)))))
>                   nlinum--width)))
>      (set-window-margins nil (if nlinum-mode width)
>                          (cdr (window-margins)))))
>
>



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

end of thread, other threads:[~2015-02-09 17:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-08 19:42 UI glitch with text-scale-increase / text-scale-decrease with linum / nlinum Gauthier Segay
2015-02-09 14:57 ` Stefan Monnier
2015-02-09 15:58   ` Gauthier Segay
2015-02-09 17:01     ` Stefan Monnier
2015-02-09 17:22       ` Gauthier Segay

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.