3

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.

Community
  • 1
  • 1
jacg
  • 2,040
  • 1
  • 14
  • 27
  • If you can put the cursor on text (or an overlay) that has the face, the use `C-u x =` and look for the `face` description in buffer `*Help*`. If you cannot, use `M-x list-face-display` and check similar-looking faces. (This is not specific to Helm.) – Drew Jan 12 '17 at 17:01
  • I suspect what is happening is that helm-selected-line is overriding all face attributes on the line. Therefore, the face used for matches on other lines does not show up under the highlighted line. It is likely that all the faces are using the same attribute (background) to do the highlighting. You might be able to do something by tweaking foreground face for helm-match, but I suspect you cannot do much about the background as it will be overridden by helm-selected-line – Tim X Jan 13 '17 at 01:17
  • @TimX `helm-selected-line` overriding other attributes is part of the issue. The more subtle part is that helm prefers to use the match colours generated by `ag` itself and ignores `helm-match` like faces if the former are available. My answer gives more details. – jacg Jan 14 '17 at 14:41
  • I'd like to know the name of the faces to change the target match in the followed-up buffer, if you know what I mean. – Emmanuel Goldstein Apr 16 '22 at 13:14

3 Answers3

2

First here is your "fish": I think the face you are referring to is helm-match.

Here are few different strategies that I would personally try if I needed to find a given face and can't place point on the text with that face:

  1. Use M-x describe-face, guess at what the first part of the name is likely to be (in this case helm), and scan through the likely candidates that start with that.
  2. Go to the code where that face is likely defined (in this case helm-ag.el which you can find with M-x describe-function RET helm-ag), and search for face in that file to find a likely match.
  3. Do M-x customize-face and enter and 'all faces', look for helm-* faces and try to find a name and face (since you can see a sample of the face in this buffer) that matches the one you are looking for.

Probably none of these methods is as direct as you are hoping for, and there may be a quicker solution, but this is what I would do (and have done). In this case I found the face with method #2.

Update:

Here is a screenshot from my setup:

enter image description here

Notice that for me the relevant face is helm-match which inherits from match in replace.el. Also, note that the difference between the way the match appears in the highlighted/selected line compared to the other lines is not due to a different face, but caused by how the background color of the line highlighting affects the color, as can be seen when I highlight the sample text here:

enter image description here

Update 2:

It turns out OP was using helm-ag-do-grep which is defined in a different file - helm-grep.el. Here is the face-setting portion of that code:

;;; Faces
;;
;;
(defgroup helm-grep-faces nil
  "Customize the appearance of helm-grep."
  :prefix "helm-"
  :group 'helm-grep
  :group 'helm-faces)

(defface helm-grep-match
  '((((background light)) :foreground "#b00000")
    (((background dark))  :foreground "gold1"))
  "Face used to highlight grep matches."
  :group 'helm-grep-faces)

(defface helm-grep-file
    '((t (:foreground "BlueViolet"
          :underline t)))
  "Face used to highlight grep results filenames."
  :group 'helm-grep-faces)

(defface helm-grep-lineno
    '((t (:foreground "Darkorange1")))
  "Face used to highlight grep number lines."
  :group 'helm-grep-faces)

(defface helm-grep-finish
    '((t (:foreground "Green")))
  "Face used in mode line when grep is finish."
  :group 'helm-grep-faces)

(defface helm-grep-cmd-line
    '((t (:inherit diff-added)))
  "Face used to highlight grep command line when no results."
  :group 'helm-grep-faces)

I think helm-grep-match is what you are looking for. If not, the face in question is likely to be in the above code snippet, and all of those faces should be customizable using customize-face. This code also tracked down using method #2 described above.

Community
  • 1
  • 1
elethan
  • 16,408
  • 8
  • 64
  • 87
  • `helm-match` was one of the first things I tried. It doesn't seem to be my fish: See the edit to my question for why I believe that to be the case. – jacg Jan 12 '17 at 15:34
  • @jacg that is strange. What version of emacs and `helm-ag` are you using? In my case, setting the face of the matches to `helm-match` is hardcoded in the source code for `helm-ag`. Also, see my updated answer for some screenshots of how it looks for me. – elethan Jan 12 '17 at 16:09
  • My problems occur when I use `helm-do-grep-ag` (which I was accessing through a keybinding, which misled me into thinking I was using `helm-ag`). When I use `helm-ag` I get the same behaviour as you do. (Curious detail: `helm-ag` creates a buffer called `*helm-ag*` (with dash), while `helm-do-grep-ag`'s buffer does not have a dash in its name (as can be seen on my screenshot). – jacg Jan 12 '17 at 20:34
  • @jacg ahh, that explains the discrepancy - nice catch with the subtle difference in the mode-line. Please see my update #2, hopefully it sends you on the right track. – elethan Jan 12 '17 at 21:47
  • Yes, `helm-grep-match` is indeed the one, but it still has no effect. According to helm's maintainer the selection overlay has a higher priority and therefore hides the match, ["[S]o there is nothing wrong here".](https://github.com/emacs-helm/helm/issues/1660#issuecomment-272295810). Yet somehow it works properly in `helm-ag`. – jacg Jan 12 '17 at 23:07
  • Yeah, this seems to come up a lot. Here are a few related posts, including one of my own: http://emacs.stackexchange.com/questions/20620/line-highlighting-canceling-out-syntax-highlighting, http://emacs.stackexchange.com/questions/10445/hl-line-mode-hide-background-how-to-avoid-this, http://emacs.stackexchange.com/questions/19947/unset-inherited-face-attribute. – elethan Jan 13 '17 at 04:20
  • It turns out that helm uses the colours generated by `ag` itself, if there are any, and only starts using `helm-grep-match` and friends if these have been switched off with `--nocolors` as an `ag` option in `helm-grep-ag-command`. See my answer for details and source. – jacg Jan 14 '17 at 14:38
  • Tangential question: your screenshot implies that you use org mode to compose stack exchange posts. Are you using something more sophisticated than mere copypasta? – jacg Jan 14 '17 at 15:19
  • @jacg actually, I typically use `gfm-mode` inside Emacs (github-flavored markdown) which is part of `markdown-mode` to compose questions and answers. This way I will have the same formatting that Stack Exchange itself uses. However, for a while I used this mode: https://github.com/vermiculus/sx.el which is pretty useful too. – elethan Jan 14 '17 at 15:36
2

A similar approach to @elethan's #3:

  • Call list-faces-display, which will show you a list of all faces in alphabetical order.

  • Search for "helm".

Kyle Meyer
  • 1,546
  • 9
  • 10
  • Nice! I didn't know about this command. The list that this command provides seems to be much easier to browse through (particularly for the OP's purpose) than the one provided by `customize-face`, since only the samples are displayed. – elethan Jan 12 '17 at 15:24
  • `list-faces-display` (with a bit of help from `helm-swoop`) was my first line of attack in my original attempts. But it didn't lead my to anything that seems to make a difference. (See question edit.) – jacg Jan 12 '17 at 15:37
0

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#

jacg
  • 2,040
  • 1
  • 14
  • 27