unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#17813: 24.3.91; bad linum display with `text-scale-adjust'
@ 2014-06-19 17:25 Shigeru Fukaya
  2014-06-19 18:46 ` Stefan Monnier
  2014-07-08 19:33 ` Stefan Monnier
  0 siblings, 2 replies; 7+ messages in thread
From: Shigeru Fukaya @ 2014-06-19 17:25 UTC (permalink / raw)
  To: 17813

[-- Attachment #1: Type: text/plain, Size: 480 bytes --]


Font size of line numbers by `linum-mode' follow `text-scale-adjust', though
the size of left margin doesn't change.
(nlinum also has the same problem)

The possible solutions are,


(1) To change the width of left margin for line numbers.

[attached patch]


(2) To fix the font size of line numbers.

(set-face-attribute 'linum nil :height (face-attribute 'linum :height nil t))


Solution (2) may need more in case of multi frames with different font size.


Regards,
Shigeru

[-- Attachment #2: linum.diff --]
[-- Type: application/octet-stream, Size: 583 bytes --]

--- orig/linum.el	2014-03-21 14:34:40.000000000 +0900
+++ ./linum.el	2014-06-20 02:13:55.023933400 +0900
@@ -178,6 +178,10 @@ Linum mode is a buffer-local minor mode.
       (let ((inhibit-point-motion-hooks t))
         (forward-line))
       (setq line (1+ line)))
+    (when (and face-remapping-alist (bound-and-true-p linum-mode))
+      (let ((h (cadr (assq :height (assq 'default face-remapping-alist)))))
+	(when (numberp h)
+	  (setq width (ceiling (* width h))))))
     (set-window-margins win width (cdr (window-margins win)))))
 
 (defun linum-after-change (beg end _len)

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

* bug#17813: 24.3.91; bad linum display with `text-scale-adjust'
  2014-06-19 17:25 bug#17813: 24.3.91; bad linum display with `text-scale-adjust' Shigeru Fukaya
@ 2014-06-19 18:46 ` Stefan Monnier
  2014-06-20  9:30   ` Eli Zaretskii
  2014-07-08 19:33 ` Stefan Monnier
  1 sibling, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2014-06-19 18:46 UTC (permalink / raw)
  To: Shigeru Fukaya; +Cc: 17813, miles

> Font size of line numbers by `linum-mode' follow `text-scale-adjust', though
> the size of left margin doesn't change.
> (nlinum also has the same problem)

> The possible solutions are,
> (1) To change the width of left margin for line numbers.
> (2) To fix the font size of line numbers.

I think the right solution is to scale the margin width by the ratio
"linum font size / base font size".  Then users can set their `linum'
face the way want and choose between (1) and (2).

But it turns out that face-attribute can't be used for that because it
does not pay attention to face-remapping-alist.

Miles, Eli, others, do you know of a function that returns "the font
size, including face-remapping-alist effects"?


        Stefan





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

* bug#17813: 24.3.91; bad linum display with `text-scale-adjust'
  2014-06-19 18:46 ` Stefan Monnier
@ 2014-06-20  9:30   ` Eli Zaretskii
  2014-06-20 13:35     ` Stefan Monnier
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2014-06-20  9:30 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: shigeru.fukaya, 17813, miles

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Date: Thu, 19 Jun 2014 14:46:48 -0400
> Cc: 17813@debbugs.gnu.org, miles@gnu.org
> 
> I think the right solution is to scale the margin width by the ratio
> "linum font size / base font size".  Then users can set their `linum'
> face the way want and choose between (1) and (2).
> 
> But it turns out that face-attribute can't be used for that because it
> does not pay attention to face-remapping-alist.

Not sure what you mean by that: attributes don't care about remapping,
because remapping doesn't change the attributes, it only changes their
values.

> Miles, Eli, others, do you know of a function that returns "the font
> size, including face-remapping-alist effects"?

I think you want

  (aref (font-info (face-font 'default)) 2)

But note that font's size and its "width" (which is actually the
average width recorded in the font file) are not identical.  We don't
have a Lisp API to get the average width of a non-default font;
perhaps we should.





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

* bug#17813: 24.3.91; bad linum display with `text-scale-adjust'
  2014-06-20  9:30   ` Eli Zaretskii
@ 2014-06-20 13:35     ` Stefan Monnier
  2014-06-20 14:27       ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2014-06-20 13:35 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: shigeru.fukaya, 17813, miles

>> I think the right solution is to scale the margin width by the ratio
>> "linum font size / base font size".  Then users can set their `linum'
>> face the way want and choose between (1) and (2).
>> But it turns out that face-attribute can't be used for that because it
>> does not pay attention to face-remapping-alist.
> Not sure what you mean by that: attributes don't care about remapping,
> because remapping doesn't change the attributes, it only changes their
> values.

I mean the following:

 a way to know "if I apply face `foo' (and only face `foo') to a chunk
 of text in the current buffer, what will it look like: will it be bold?
 what will be its size? ..."

`face-attribute' doesn't work here because it fails to take into account
the effect of face-remapping-alist.

>> Miles, Eli, others, do you know of a function that returns "the font
>> size, including face-remapping-alist effects"?
> I think you want
>   (aref (font-info (face-font 'default)) 2)

Indeed, that seems to work, thanks.

> But note that font's size and its "width" (which is actually the
> average width recorded in the font file) are not identical.  We don't
> have a Lisp API to get the average width of a non-default font;

Indeed, that's an additional problem.

> perhaps we should.

I'm all for it.


        Stefan





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

* bug#17813: 24.3.91; bad linum display with `text-scale-adjust'
  2014-06-20 13:35     ` Stefan Monnier
@ 2014-06-20 14:27       ` Eli Zaretskii
  2014-06-20 15:35         ` Stefan Monnier
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2014-06-20 14:27 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: shigeru.fukaya, 17813, miles

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Cc: shigeru.fukaya@gmail.com,  17813@debbugs.gnu.org,  miles@gnu.org
> Date: Fri, 20 Jun 2014 09:35:32 -0400
> 
> >> I think the right solution is to scale the margin width by the ratio
> >> "linum font size / base font size".  Then users can set their `linum'
> >> face the way want and choose between (1) and (2).
> >> But it turns out that face-attribute can't be used for that because it
> >> does not pay attention to face-remapping-alist.
> > Not sure what you mean by that: attributes don't care about remapping,
> > because remapping doesn't change the attributes, it only changes their
> > values.
> 
> I mean the following:
> 
>  a way to know "if I apply face `foo' (and only face `foo') to a chunk
>  of text in the current buffer, what will it look like: will it be bold?
>  what will be its size? ..."
> 
> `face-attribute' doesn't work here because it fails to take into account
> the effect of face-remapping-alist.

APIs that need to take face remapping into account need to be
specifically programmed to do that.  Some were, some weren't;
face-font belongs to the former.

> >   (aref (font-info (face-font 'default)) 2)
> 
> Indeed, that seems to work, thanks.
> 
> > But note that font's size and its "width" (which is actually the
> > average width recorded in the font file) are not identical.  We don't
> > have a Lisp API to get the average width of a non-default font;
> 
> Indeed, that's an additional problem.
> 
> > perhaps we should.
> 
> I'm all for it.

Would it be OK to add that as the last element to the array returned
by font-info?





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

* bug#17813: 24.3.91; bad linum display with `text-scale-adjust'
  2014-06-20 14:27       ` Eli Zaretskii
@ 2014-06-20 15:35         ` Stefan Monnier
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2014-06-20 15:35 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: shigeru.fukaya, 17813, miles

> Would it be OK to add that as the last element to the array returned
> by font-info?

Sounds fine to me, but I know very little about font handling.

I do know that the face/font code uses various arrays that don't all
have the same length but share the same meaning for the first elements,
so of course, we should first make sure that adding an element to the
array doesn't break other parts.


        Stefan





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

* bug#17813: 24.3.91; bad linum display with `text-scale-adjust'
  2014-06-19 17:25 bug#17813: 24.3.91; bad linum display with `text-scale-adjust' Shigeru Fukaya
  2014-06-19 18:46 ` Stefan Monnier
@ 2014-07-08 19:33 ` Stefan Monnier
  1 sibling, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2014-07-08 19:33 UTC (permalink / raw)
  To: Shigeru Fukaya; +Cc: 17813

Version:24.5

> (1) To change the width of left margin for line numbers.
> [attached patch]

I installed the patch below instead (I earlier used a similar patch for
nlinum), which should be slightly more robust.  Thank you,


        Stefan


=== modified file 'lisp/linum.el'
--- lisp/linum.el	2014-02-10 01:34:22 +0000
+++ lisp/linum.el	2014-07-08 19:27:00 +0000
@@ -138,6 +138,9 @@
       (mapc #'delete-overlay linum-available)
       (setq linum-available nil))))
 
+(defun linum--face-height (face)
+  (aref (font-info (face-font face)) 2))
+
 (defun linum-update-window (win)
   "Update line numbers for the portion visible in window WIN."
   (goto-char (window-start win))
@@ -178,6 +181,12 @@
       (let ((inhibit-point-motion-hooks t))
         (forward-line))
       (setq line (1+ line)))
+    (when (display-graphic-p)
+      (setq width (ceiling
+                   ;; We'd really want to check the widths rather than the
+                   ;; heights, but it's a start.
+                   (/ (* width 1.0 (linum--face-height 'linum))
+                      (frame-char-height)))))
     (set-window-margins win width (cdr (window-margins win)))))
 
 (defun linum-after-change (beg end _len)






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

end of thread, other threads:[~2014-07-08 19:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-19 17:25 bug#17813: 24.3.91; bad linum display with `text-scale-adjust' Shigeru Fukaya
2014-06-19 18:46 ` Stefan Monnier
2014-06-20  9:30   ` Eli Zaretskii
2014-06-20 13:35     ` Stefan Monnier
2014-06-20 14:27       ` Eli Zaretskii
2014-06-20 15:35         ` Stefan Monnier
2014-07-08 19:33 ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).