2

By default, in terminal, emacs's mode-line-mule-info displays:

  1. buffer coding systems
  2. keyboard coding systems
  3. terminal coding systems
  4. EOF indicator

Example:

-UUU:%%--F1  *GNU Emacs*    All L1     (Fundamental) ---------------------------

I want just the buffer coding systems, but not the keyboard or terminal coding systems like:

-U:%%--F1  *GNU Emacs*    All L1     (Fundamental) -----------------------------

Is there a way to turn them off?

2
  • I found mode-line-mule-info consists of %z and mode-line-eol-desc, but knows nothing further.
    – Alaneuler
    Dec 22, 2022 at 5:55
  • 1
    To me it looks like this behavior is 'hard-coded' in the C code. Therefore, I guess you can better pose this question in the Emacs help mailing list (or notify them about your question here)... Dec 22, 2022 at 16:16

1 Answer 1

4

The last of the three mule-info characters corresponds to the buffer coding system in Emacs 28.1.
So I give a solution for that case.

It is right that the replacement for "%z" is hard-coded in function decode_mode_spec of xdisp.c.

In the following code we replace "%z" by an expression that is to be evaluated.
The expression evaluates the mode line format string "%z" and returns just the one-character substring at the end of it.

  (defconst mode-line-buffer-coding-info (or
                      ;; avoid repeated setting:
                      (and (boundp 'mode-line-buffer-coding-info)
                           mode-line-buffer-coding-info)
                      ;; actual value:
                      (assoc-string "%z" mode-line-mule-info)))

  (setf (car (member "%z" (default-value 'mode-line-mule-info))) '(:eval (substring (format-mode-line mode-line-buffer-coding-info) -1 nil)))

You can put this code into your init file.


About the order of the coding system indicators:

The source code of decode_mode_spec in xdisp.c for processing the 'z' format letter is:

    case 'z':
      /* coding-system (not including end-of-line format) */
    case 'Z':
      /* coding-system (including end-of-line type) */
      {
    bool eol_flag = (c == 'Z');
    char *p = decode_mode_spec_buf;

    if (! FRAME_WINDOW_P (f))
      {
        /* No need to mention EOL here--the terminal never needs
           to do EOL conversion.  */
        p = decode_mode_spec_coding (CODING_ID_NAME
                     (FRAME_KEYBOARD_CODING (f)->id),
                     p, false);
        p = decode_mode_spec_coding (CODING_ID_NAME
                     (FRAME_TERMINAL_CODING (f)->id),
                     p, false);
      }
    p = decode_mode_spec_coding (BVAR (b, buffer_file_coding_system),
                     p, eol_flag);

where decode_mode_spec_coding takes the char buffer pointer p, adds the char(s) for the coding system and returns the incremented pointer.

As we see, at first it processes the keyboard coding then the terminal coding and at last the buffer encoding.

Furthermore: From the Emacs manual:

On a text terminal, cs is preceded by two additional characters that describe the coding systems for keyboard input and terminal output. Furthermore, if you are using an input method, cs is preceded by a string that identifies the input method (see Input Methods).

2
  • Thanks for your answer! But isn't it the first of the mule-info characters corresponds to the buffer coding system?
    – Alaneuler
    Dec 23, 2022 at 0:11
  • @Alaneuler I added a section on the order of the coding system indicators.
    – Tobias
    Dec 23, 2022 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.