15

I like using a combination of describe-face and customize-face to adjust the appearance of my working environment. Sometime this workflow fails when I want to change the face of a location I can not reach with the cursor; mode-line, header-line, magit-blame headers etc. Most of the time, I can trail and error my way to a solution but sometimes I get stuck (I didn't know the header-line existed until yesterday for instance).

Is there a convenient way to describe the face of a location in a frame which is not reachable by the cursor? By means of a mouse for instance.

7

I do not know about using the mouse, but I've often found it's easiest for me to run list-faces-display and then just i-search for what the face is likely called or visually scan for text that looks the same.

  • 1
    This is the answer, IMHO. The display is WYSIWYG, and it gives you direct access to the Customize buffer for a given face and direct access to a complete description. – Drew Sep 26 '14 at 22:53
  • I agree and changed the status. The other solution is cool but not convenient. – remvee Sep 27 '14 at 9:12
9

There are 4 regions where text may be displayed in Emacs, here is what you can do to inspect each of them.

  • The mode-line: See the value of mode-line-format.
  • The header-line: See the value of header-line-format.
  • Buffer: If the face is in a region of the buffer you can't reach, see the value of (buffer-string).
  • Minibuffer: If point is currently in the minibuffer, you can do M-: (buffer-string), and that will describe the contents of the minibuffer. You may need to (setq enable-recursive-minibuffers to t) first.
  • Fringe or Margin: None that I know of.

These methods will give you the entire contents of these regions, so it may take some reading to actually find the face you're looking for, but it will certainly be there. Most importantly, it will describe even regions you cannot reach.
For instance, let's say I want to know which face is used in the find-file prompt.

  1. Invoke find-file with C-x C-f.
  2. Describe the minibuffer with M-: (buffer-string)

That will give something like the following output, and right there at the end is the face I was looking for.

#("Find file: ~/" 0 11 (front-sticky t rear-nonsticky t field t read-only t point-entered minibuffer-avoid-prompt face minibuffer-prompt))
  • Interesting! I did not know (buffer-string). But how do I invoke it while I'm in the minibuffer without yielding "Command attempted to use minibuffer while in minibuffer"? – remvee Sep 26 '14 at 12:18
  • @remvee Ah, set the variable enable-recursive-minibuffers to t – Malabarba Sep 26 '14 at 13:30
  • What about the fringe? – Tikhon Jelvis Sep 26 '14 at 18:39
  • @TikhonJelvis oh, good point. That I don't know. – Malabarba Sep 26 '14 at 18:54
  • I think that also leaves the margins? – Sigma Sep 26 '14 at 19:05
3

Turns out you can indeed use the mouse (I think this may be exactly what you were looking for):

  ;; based on: https://emacs.stackexchange.com/a/19585/13444
  (defun brds/describe-char-at-mouse-click (click-event)
    "`describe-char' at CLICK-EVENT's position.
CLICK-EVENT should be a mouse-click event."
    (interactive "e")
    (run-hooks 'mouse-leave-buffer-hook)
    (let ((pos (cadr (event-start click-event))))
      (describe-char pos)))

  ;; <d>escribe
  (global-set-key (kbd "C-c d <down-mouse-1>")
                  #'brds/describe-char-at-mouse-click)
  • This doesn't seem to work for me in the modeline. Does it work for you in any places mentioned in the question? – zck Sep 12 '17 at 4:25
  • Works for me on magit-blame headers, as well as, at a minimum, minibuffer completion candidates, the minibuffer prompt, and company popups. That said, it's not working for me either when I call it on the mode- or header-line: those give me (wrong-type-argument number-or-marker-p header-line) (or [...] mode-line, respectively). I think those might be particularly special cases (along with the fringe and margin). – braham-snyder Sep 12 '17 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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