unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Lars Ingebrigtsen <larsi@gnus.org>
To: "Basil L. Contovounesios" <contovob@tcd.ie>
Cc: 34476@debbugs.gnu.org, "積丹尼 Dan Jacobson" <jidanni@jidanni.org>
Subject: bug#34476: fluffy whitespace in the mode-line, despite it running off the screen
Date: Fri, 07 Aug 2020 10:31:22 +0200	[thread overview]
Message-ID: <87a6z67t7p.fsf@gnus.org> (raw)
In-Reply-To: <87eeoi7un0.fsf@gnus.org> (Lars Ingebrigtsen's message of "Fri, 07 Aug 2020 10:00:35 +0200")

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

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Hm...  well, since this is an optional thing users can switch on,
> perhaps making it slightly slower wouldn't be that much of a problem.
> Let's see...

OK, here's a proof of concept.  With the patch, the mode line looks like:


[-- Attachment #2: Type: image/png, Size: 6516 bytes --]

[-- Attachment #3: Type: text/plain, Size: 2428 bytes --]


If this way of implementing it sounds OK to everybody, then I'll finish
the patch (and add support for "only compact if the line is too long")
and add documentation and NEWS.

diff --git a/src/xdisp.c b/src/xdisp.c
index 4fe1c4288a..938b3b408a 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -25216,14 +25216,42 @@ display_mode_line (struct window *w, enum face_id face_id, Lisp_Object format)
 			 format_mode_line_unwind_data (NULL, NULL,
 						       Qnil, false));
 
-  mode_line_target = MODE_LINE_DISPLAY;
-
   /* Temporarily make frame's keyboard the current kboard so that
      kboard-local variables in the mode_line_format will get the right
      values.  */
   push_kboard (FRAME_KBOARD (it.f));
   record_unwind_save_match_data ();
-  display_mode_element (&it, 0, 0, 0, format, Qnil, false);
+
+  if (NILP (Vmode_line_compact))
+    {
+      mode_line_target = MODE_LINE_DISPLAY;
+      display_mode_element (&it, 0, 0, 0, format, Qnil, false);
+    }
+  else
+    {
+      Lisp_Object mode_string = Fformat_mode_line (format, Qnil, Qnil, Qnil);
+      char *string = xmalloc (SBYTES (mode_string) + 1),
+	*ostring = SSDATA (mode_string);
+      char *s = string, prev = 0;
+
+      /* Copy over the data from the mode line string, but ignore
+	 repeating spaces.  This should be safe even for multibyte
+	 strings, since this is UTF-8. */
+      for (int i = 0; i < SBYTES (mode_string); i++)
+	{
+	  char c = ostring[i];
+	  if (!(c == ' ' && prev == ' '))
+	    {
+	      *s++ = c;
+	      prev = c;
+	    }
+	}
+      *s = 0;
+      
+      display_string (string, Qnil, Qnil, 0, 0, &it, 0, 0, 0,
+		      STRING_MULTIBYTE (mode_string));
+      xfree (string);
+    }
   pop_kboard ();
 
   unbind_to (count, Qnil);
@@ -34551,6 +34579,11 @@ syms_of_xdisp (void)
 The face used for trailing whitespace is `trailing-whitespace'.  */);
   Vshow_trailing_whitespace = Qnil;
 
+  DEFVAR_LISP ("mode-line-compact", Vmode_line_compact,
+    doc: /* Non-nil means that mode lines should be compact.
+This means that repeating spaces will be replaced with a single space.  */);
+  Vmode_line_compact = Qnil;
+
   DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display,
     doc: /* Control highlighting of non-ASCII space and hyphen chars.
 If the value is t, Emacs highlights non-ASCII chars which have the


-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no

  reply	other threads:[~2020-08-07  8:31 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-14 13:34 bug#34476: fluffy whitespace in the mode-line, despite it running off the screen 積丹尼 Dan Jacobson
2019-07-09 16:43 ` Lars Ingebrigtsen
2019-07-09 20:46   ` Basil L. Contovounesios
2019-07-09 21:44     ` Lars Ingebrigtsen
2020-08-07  8:00       ` Lars Ingebrigtsen
2020-08-07  8:31         ` Lars Ingebrigtsen [this message]
2020-08-07 11:32           ` Eli Zaretskii
2020-08-07 11:41             ` Lars Ingebrigtsen
2020-08-07 11:59               ` Eli Zaretskii
2020-08-07 12:15                 ` Lars Ingebrigtsen
2020-08-07 13:52                   ` Eli Zaretskii
2020-08-08  9:11                     ` Lars Ingebrigtsen
2020-08-08  9:48                       ` Eli Zaretskii
2020-08-08 10:01                         ` Eli Zaretskii
2020-08-08 11:18                           ` Lars Ingebrigtsen
2020-08-08 12:55                             ` Eli Zaretskii
2020-08-08 14:16                               ` Lars Ingebrigtsen
2020-08-08 15:00                                 ` Eli Zaretskii
2020-08-09  9:56                                   ` Lars Ingebrigtsen
2020-08-09 14:07                                     ` Eli Zaretskii
2020-08-10 14:46                                       ` Eli Zaretskii
2020-08-10 14:56                                         ` Lars Ingebrigtsen
2020-08-14 10:46                                         ` Eli Zaretskii
2020-08-14 12:00                                           ` Lars Ingebrigtsen
2020-08-14 13:16                                             ` Eli Zaretskii
2020-08-15  8:47                                           ` Eli Zaretskii
2020-08-15 10:55                                             ` Lars Ingebrigtsen
2020-08-15 15:12                                               ` Eli Zaretskii
2020-08-16 11:21                                                 ` Lars Ingebrigtsen
2020-08-16 14:43                                                   ` Eli Zaretskii
2020-08-17  8:33                                                     ` Lars Ingebrigtsen
2020-08-17 14:17                                                       ` Eli Zaretskii
2020-12-29  3:54                                                         ` Lars Ingebrigtsen
2020-12-29 15:02                                                           ` Eli Zaretskii
2020-12-29 15:07                                                             ` Lars Ingebrigtsen
2020-12-29 15:54                                                               ` Eli Zaretskii
2020-12-29 17:04                                                                 ` martin rudalics
2020-12-30  2:36                                                                   ` Lars Ingebrigtsen
2020-08-08 11:18                         ` Lars Ingebrigtsen

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87a6z67t7p.fsf@gnus.org \
    --to=larsi@gnus.org \
    --cc=34476@debbugs.gnu.org \
    --cc=contovob@tcd.ie \
    --cc=jidanni@jidanni.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 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).