all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stephen Berman <stephen.berman@gmx.net>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 7307@debbugs.gnu.org
Subject: bug#7307: 24.0.50; Mode line had more than just dashes removed
Date: Sun, 21 Nov 2010 01:37:20 +0100	[thread overview]
Message-ID: <87hbfbtsu7.fsf@escher.home> (raw)
In-Reply-To: <jwvoc9zsmyt.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Mon, 08 Nov 2010 13:28:17 -0500")

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

On Mon, 08 Nov 2010 13:28:17 -0500 Stefan Monnier <monnier@iro.umontreal.ca> wrote:

(Sorry about the delay; I couldn't get back to it sooner.)

>> How about something like the following patch?
>
> Looks pretty good.  It should probably come together with a Lisp part
> that removes the current mode-line-format change.

See the attached patch.

>> This builds the string
>> dynamically by filling decode_mode_spec_buf to the desired length,
>> dispensing with an additional lots_of_<foo> string.  AFAICT this gives
>> good results (though I admittedly haven't been able to find a case where
>> lots_of_filler (replacing lots_of_dashes) is used; what is such a
>> case?).
>
> I guess the lots_of_filler case is when you use things like "%5-".

?? That's not a documented mode line %-spec, is it?  Anyway, using it I
still see no difference.

>> I also exposed the string character variable mode_line_filler to Lisp,
>> so it could be customizable, but I haven't been able to figure out how
>> to update the mode line with a new character.
>
> That's because you re-initialize mode_line_filler each time.
> Instead you should initialize it once and "for all" in init_xdisp.
> But indeed, that exposes another problem: being global, you won't be
> able to have "----" in tty frames and "    " in GUI frames in the
> same process.

I've discovered, if I'm not mistaken, that it apparently isn't necessary
to initialize mode_line_filler at the C level at all: rather, this can
be done in cus-start.el, and (except with --daemon, see below) it
correctly distinguishes tty and GUI frames.  (Admittedly, I don't
understand why it works, and would be grateful if you or someone else
could tell me.)

>> Also, I don't know the right way to set the default value: I assume it
>> shouldn't be done in decode_mode_spec() as below but at the top level
>> together with the DEFVAR, but then how can it be associated with the
>> window whose mode line is being constructed?
>
> Indeed.  You could use a terminal property instead of (or additionally
> to) a global variable, or you could let the global variable be a cons
> cell where the car is the char to use for GUI frames and the cdr is for
> tty frames :-(

It turns out to be much simpler (if I'm not mistaken).  That is, the
attached patch (against trunk from 2010-11-11) at least appears to DTRT,
except for three issues:

(i) As Andreas already noted, this does not work for non-ASCII
characters, which show up as octal codes.  I haven't yet figured out how
to fix this (I tried using string_make_multibyte, but then attempting to
use a non-ASCII character as the filler makes Emacs crash).

(ii) Using the character customization type and trying to set the filler
character to SPC signals the error "This field should contain a single
character".  I looked at the code but failed to see why this happens.
The patch below contains a workaround I found in ruler.el: allowing the
filler to choose between character and integer type; choosing the latter
with value 32 results in spaces filling the mode line.

(iii) Starting Emacs with --daemon and then opening a frame with
emacsclient -c results in the mode line being filled with `-'
characters, because the daemon uses a tty frame.  Moreover, the Custom
buffer for mode-line-filler says the state was "CHANGED outside
Customize", even with -Q.

If these three issues, or at least the first two, can be dealt with, do
you think this is a reasonable way to make the mode line filler
customizable?

Steve Berman


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: mode line filler patch --]
[-- Type: text/x-patch, Size: 3705 bytes --]

=== modified file 'lisp/bindings.el'
--- lisp/bindings.el	2010-10-19 19:20:33 +0000
+++ lisp/bindings.el	2010-11-19 11:27:06 +0000
@@ -336,8 +336,7 @@
 	 'mode-line-modes
 	 `(which-func-mode ("" which-func-format ,spaces))
 	 `(global-mode-string ("" global-mode-string ,spaces))
-	 `(:eval (unless (display-graphic-p)
-		   ,(propertize "-%-" 'help-echo help-echo)))))
+	 `(:eval ,(propertize "%-" 'help-echo help-echo))))
        (standard-mode-line-modes
 	(list
 	 (propertize "%[" 'help-echo recursive-edit-help-echo)

=== modified file 'lisp/cus-start.el'
--- lisp/cus-start.el	2010-10-31 22:47:12 +0000
+++ lisp/cus-start.el	2010-11-20 19:52:54 +0000
@@ -397,6 +397,15 @@
 	     (truncate-partial-width-windows display boolean "23.1")
 	     (mode-line-inverse-video mode-line boolean)
 	     (mode-line-in-non-selected-windows mode-line boolean "22.1")
+	     (mode-line-filler mode-line
+			       (choice
+				(character :tag "Character")
+				(integer :tag "Integer char value"
+					 ;; :validate ruler-mode-character-validate
+					 ))
+			       "24.1"
+			       :standard (if (display-graphic-p) ?  ?-)
+			       :initialize custom-initialize-delay)
 	     (line-number-display-limit display
 					(choice integer
 						(const :tag "No limit" nil)))

=== modified file 'src/xdisp.c'
--- src/xdisp.c	2010-11-09 20:07:10 +0000
+++ src/xdisp.c	2010-11-19 22:13:02 +0000
@@ -667,6 +667,11 @@
 
 int cursor_type_changed;
 
+/* Filler character used by the "%-" mode line spec.  Defaults to ' '
+   on a graphical display and to '-' on a tty.  */
+
+EMACS_INT mode_line_filler;
+ 
 /* Nonzero after display_mode_line if %l was used and it displayed a
    line number.  */
 
@@ -19382,8 +19387,6 @@
    Note we operate on the current buffer for most purposes,
    the exception being w->base_line_pos.  */
 
-static char lots_of_dashes[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
-
 static const char *
 decode_mode_spec (struct window *w, register int c, int field_width,
 		  int precision, Lisp_Object *string)
@@ -19453,21 +19456,21 @@
     case '-':
       {
 	register int i;
-
-	/* Let lots_of_dashes be a string of infinite length.  */
-	if (mode_line_target == MODE_LINE_NOPROP ||
-	    mode_line_target == MODE_LINE_STRING)
-	  return "--";
-	if (field_width <= 0
-	    || field_width > sizeof (lots_of_dashes))
-	  {
-	    for (i = 0; i < FRAME_MESSAGE_BUF_SIZE (f) - 1; ++i)
-	      decode_mode_spec_buf[i] = '-';
-	    decode_mode_spec_buf[i] = '\0';
-	    return decode_mode_spec_buf;
-	  }
-	else
-	  return lots_of_dashes;
+	int fill_len;
+	int lots_of_filler = 140;
+  
+	/* Make a string of mode_line_filler characters.  */
+	fill_len = 
+	  (mode_line_target == MODE_LINE_NOPROP
+	   || mode_line_target == MODE_LINE_STRING) 
+	  ? 2
+	  : ((field_width <= 0 || field_width > lots_of_filler)
+	     ? FRAME_MESSAGE_BUF_SIZE (f) - 1 
+	     : lots_of_filler);
+	for (i = 0; i < fill_len; ++i)
+	  decode_mode_spec_buf[i] = mode_line_filler;
+	decode_mode_spec_buf[i] = '\0';
+	return decode_mode_spec_buf;
       }
 
     case 'b':
@@ -26654,6 +26657,10 @@
     doc: /* String (or mode line construct) included (normally) in `mode-line-format'.  */);
   Vglobal_mode_string = Qnil;
 
+  DEFVAR_INT ("mode-line-filler", &mode_line_filler,
+    doc: /* Filler character used by the "%-" mode line spec.
+Defaults to ' ' on a graphical display and to '-' on a tty.  */);
+
   DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position,
     doc: /* Marker for where to display an arrow on top of the buffer text.
 This must be the beginning of a line in order to work.

  reply	other threads:[~2010-11-21  0:37 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-29 23:05 bug#7307: 24.0.50; Mode line had more than just dashes removed Stephen Berman
2010-10-30  6:51 ` Eli Zaretskii
2010-10-30 13:27   ` Stephen Berman
2010-10-30 13:49     ` Eli Zaretskii
2010-10-30 15:23       ` Stephen Berman
2010-10-31  3:54     ` Stefan Monnier
2010-11-01 18:11       ` Stephen Berman
2010-11-01 19:32         ` Eli Zaretskii
2010-11-01 23:35           ` Stephen Berman
2010-11-02  5:35             ` Eli Zaretskii
2010-11-02  6:31               ` Eli Zaretskii
2010-11-02 14:32         ` Stefan Monnier
2010-11-05 16:18           ` Stephen Berman
2010-11-05 18:45             ` Andreas Schwab
2010-11-05 23:08               ` Stephen Berman
2010-11-08 18:28             ` Stefan Monnier
2010-11-21  0:37               ` Stephen Berman [this message]
2010-10-31  0:49 ` James Cloos
2010-11-01 18:11   ` Stephen Berman
2012-06-03  9:05 ` Chong Yidong

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=87hbfbtsu7.fsf@escher.home \
    --to=stephen.berman@gmx.net \
    --cc=7307@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.