Search code examples
emacsemacs-helm

How to discover which faces are used in helm buffers?


I wish to change the appearance of something in a *helm ag* buffer. None of my usual tricks for discovering which face is being used at some point (my favourite being M-x customize-face with the point in the region of interest) work, as there is no (obvious) way of getting control of a cursor in helm buffers.

My questions are:

  • Teach me to fish, feed me for life: How can I discover the faces used in a buffer in which I cannot place the cursor?

  • Give me a fish, feed me for a day: Which face is used in the *helm ag* buffer to highlight the pattern match on the currently selected line?

Update

In the case of *helm-ag* buffers created by the helm-ag command, the relevant face is helm-match. However, in *helm ag* buffers (no dash!) created by the helm-do-grep-ag command, the helm-match face seems to have no effect, as described in the further information below.

Further information

Here is a picture of an emacs session in which no custom themes have been enabled.

illustration of the problem

In the lower left there is a *helm ag* buffer searching for defun. The third line in the buffer is selected. The match (defun) is highlighted in all other lines, but not on the selected one.

On the right are some face customization buffers for likely candidates. helm-match has been set to have a red foreground, but this is not reflected in the *helm-ag* buffer. This seems to suggest that helm-match is not the fish I'm looking for.


Solution

  • ag itself uses colours to highlight matches. Helm uses these colours and ignores helm-grep-match unless helm-grep-ag-command contains the --nocolors option.

    There are therefore two approaches:

    1. Set the colours you want with the --color-match option to ag in helm-grep-ag-command.

    2. Disable ag's match highlighting with the --nocolor opiton in helm-grep-ag-command and set Emacs' helm-match or helm-grep-match (not entirely sure which one is the right one here) to specify the match colours. As this second option uses elisp to deal with the colouring, it's likely to be slower than the first.

    In both cases, match highlighting will be overriden by helm-selection, so the only way to get any highlighting of the match on the selected line is to have helm-selection not specify either the background or the foreground, thereby leaving the opportuinity for the match highlighting to be seen.

    Reference: https://github.com/emacs-helm/helm/issues/1660#