2

When using parentheses matching, how can I set the color of the parenthesis my cursor is actually on?

I found I can use the below set-face-attribute to control the color of the other parenthesis, but I cannot find any info on how to control the color of the parenthesis I am on.

(set-face-attribute 'show-paren-match nil
                    :background "#ffffff"
                    :foreground "#000000")
Drew
  • 75,699
  • 9
  • 109
  • 225
gdonald
  • 167
  • 7
  • 1
    Are you looking for [rainbow-delimiters](https://github.com/Fanael/rainbow-delimiters) by any chance? The package is available in MELPA as well. – NickD Mar 14 '23 at 20:38
  • In addition to `rainbow-delimiters` you may find [smartparens](https://github.com/Fuco1/smartparens) of interest. – slackline Mar 15 '23 at 22:56
  • @NickD: I guess OP only wants to change `show-paren-mode`’s color... – shynur Mar 16 '23 at 01:40
  • Search this site for `[parentheses] [highlight]`. – Drew Mar 22 '23 at 03:41

2 Answers2

3

C-h f show-paren-mode:

show-paren-mode is an interactive native-compiled Lisp function in ‘paren.el’.

Click ‘paren.el’ in your Emacs.

Find the definition of the function show-paren-function, and see:

(overlay-put show-paren--overlay-1 'face face))
;; ...
;; ...
(overlay-put show-paren--overlay 'face face))))))

You can replace the face (not 'face) with '(:background "yellow" :foreground "red"), then reevaluate this defun form.


The above steps will change how show-paren-mode displays color.

You may want to add some code to your .emacs to automate the above process.

shynur
  • 4,065
  • 1
  • 3
  • 23
0

Emacs comes with the convenient possibility to adjust all of the own settings using the therefore provided buffer interfaces.

To access properties of font faces choose in Emacs menu:

MENU: 
     Options: 
              Customize Emacs:
                               Specific Face ...

The buffer opened by this menu item comes with a [Search] function helping to find the appropriate face settings.

The keywords to use to get the settings related to highlighting parentheses are: 'paren' and 'face' (I must admit not that easy to guess ...):

dialog buffer

The color of the matching parenthesis can be set from there by opening the Show Paren Match dialog (click the left triangle) and the color of the parenthesis you are at (assuming that there is no match) by opening the Show Paren Mismatch:

enter image description here

With the settings above you will get:

closing paren orphan paren

To my knowledge it is not possible to set the color of the parenthesis you are at to a different color as the color of the matching parenthesis. And even if it would be possible, it would not make much sense anyway.

Claudio
  • 410
  • 2
  • 11