5

Q: is there a way to center the minibuffer/echo area horizontally?

I use Emacs in a single, very wide frame split into three windows side by side. I'm usually working in the center window, with the other windows showing notes, a REPL, etc.:

+-----------+-----------+-----------+
|           |           |           |
|   notes   | EYES HERE |   notes   |
|           |           |           |
+-----------+-----------+-----------+
| echo                              |
+-----------------------------------+

When I use the minibuffer or get a message in the echo area, the text is flush with the left side of the frame. On super wide frames like the one I'm using, this placement is really inconvenient.

Is there a way to make minibuffer/echo area text show up in the center of the frame (i.e., in the middle along the x-axis)?

+-----------+-----------+-----------+
|           |           |           |
|   notes   | EYES HERE |   notes   |
|           |           |           |
+-----------+-----------+-----------+
|            echo here?             |
+-----------------------------------+

In a perfect world, the minibuffer/echo area would start flush with the left margin of the active window, but I'd be glad if I could just get the text moved to the middle of the frame.

4
  • I haven't tried it but look at this post lunaryorn.com/posts/center-buffer-text-in-emacs.html
    – Jules
    Oct 12, 2016 at 22:02
  • There have been attempts at frame-oriented layouts, instead of windows. In your setting, that would mean 3 frames, and the minibuffer/echo area would appear at the bottom of the current one. But it's quite a change to get used to. It would be great if one could get a similar behavior with a single frame divided in windows...
    – T. Verron
    Oct 14, 2016 at 9:03
  • @Jules Doesn't look like lunaryorn.com/posts/center-buffer-text-in-emacs deals also with minibuffers. Minibuffers are quite a different story.
    – Tobias
    Oct 14, 2016 at 14:51
  • Any luck with this one, Dan?
    – mihai
    Mar 29, 2019 at 13:28

1 Answer 1

1

The following advice does this stuff in a hacky way. One disadvantage I am already aware of is that the spaces are also inserted into the message buffer.

(advice-add #'message :filter-args #'message-filter-center)

(defun message-filter-center (args)
  "Center message string.
This is a :filter-args advice for `message`."
  (if (car args)
      (with-current-buffer (window-buffer (minibuffer-window))
    (let ((str (apply #'format-message args)))
      (list "%s" (propertize str 'line-prefix (list 'space :align-to (max 0 (/ (- (window-width (minibuffer-window)) (string-width str)) 2)))))))
    args))

EDIT: After the comment of user:blujay I use the line-prefix text property instead of the string composed of whitespaces. That text property gets through message. Fiddling with the content of the message window directly is quite more involved.


I've got the impression that the above version causes some strange problems (e.g., added space at the end of completed lisp-symbols on C-h f). Therefore, I also add the original version here which did not have these problems:

(advice-add #'message :filter-args #'message-filter-center)

(defun message-filter-center (args)
  "Center message string.
This is a :filter-args advice for `message`."
  (if (car args)
      (with-current-buffer (window-buffer (minibuffer-window))
    (let* ((str (apply #'format-message args))
           (filler (make-string (max 0 (/ (- (window-width (minibuffer-window)) (string-width str)) 2)) ? )))
      (list "%s%s" filler str)))
    args))
2
  • You might be able to use an overlay with the before-string property to achieve the same effect without altering the actual contents of the minibuffer: gnu.org/software/emacs/manual/html_node/elisp/…
    – user3871
    Oct 14, 2016 at 9:52
  • Thanks, but so far it's not working. I haven't gotten around to upgrading to emacs 25 yet, so can't tinker with the function (format-message is new).
    – Dan
    Oct 18, 2016 at 16:29

Your Answer

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

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