all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: 67248@debbugs.gnu.org
Subject: bug#67248: 30.0.50; string-pixel-width is affected by the global value of display-line-numbers
Date: Fri, 17 Nov 2023 23:23:58 +0200	[thread overview]
Message-ID: <8cc52908-98c6-b853-a679-b4ac29755555@yandex.ru> (raw)

1. (string-pixel-width "abc") ; => 51
2. (customize-set-variable 'display-line-numbers t)
3. (string-pixel-width "abc") ; => 119

This function's implementation makes provision for
display-line-numbers-mode, but not for the original variable
display-line-numbers, which will be t independent of the value of
display-line-numbers-mode.

I think it's a bad idea to have these two different ways to do the same
thing, and it can lead to bugs like this one. I would suggest obsoleting
the public use of display-line-numbers -- making it private, probably.
At least removing it from the customization group display-line-numbers.

Barring that, the patch below seems to work.  Although it proliferates
the differences between Emacs versions which one would have to be on the
lookout for.

Originally reported at
https://github.com/company-mode/company-mode/issues/1427.

diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el
index 572822351b1..4fda98ae3d0 100644
--- a/lisp/emacs-lisp/subr-x.el
+++ b/lisp/emacs-lisp/subr-x.el
@@ -343,8 +343,7 @@ string-pixel-width
      (with-current-buffer (get-buffer-create " *string-pixel-width*")
        ;; If `display-line-numbers-mode' is enabled in internal
        ;; buffers, it breaks width calculation, so disable it (bug#59311)
-      (when (bound-and-true-p display-line-numbers-mode)
-        (display-line-numbers-mode -1))
+      (setq-local display-line-numbers nil)
        (delete-region (point-min) (point-max))
        ;; Disable line-prefix and wrap-prefix, for the same reason.
        (setq line-prefix nil


In GNU Emacs 30.0.50 (build 271, x86_64-pc-linux-gnu, GTK+ Version
  3.24.34, cairo version 1.16.0) of 2023-11-17 built on potemkin
Repository revision: 94849ba35f40393362050b5937578dcf3076b4bf
Repository branch: feature/cl-lib-improvements
Windowing system distributor 'The X.Org Foundation', version 11.0.12101004
System Description: Ubuntu 22.10





             reply	other threads:[~2023-11-17 21:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-17 21:23 Dmitry Gutov [this message]
2023-11-18  7:14 ` bug#67248: 30.0.50; string-pixel-width is affected by the global value of display-line-numbers Eli Zaretskii
2023-11-18 16:36   ` Dmitry Gutov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8cc52908-98c6-b853-a679-b4ac29755555@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=67248@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.