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")
4
  • 1
    Are you looking for rainbow-delimiters by any chance? The package is available in MELPA as well.
    – NickD
    Mar 14 at 20:38
  • In addition to rainbow-delimiters you may find smartparens of interest.
    – slackline
    Mar 15 at 22:56
  • @NickD: I guess OP only wants to change show-paren-mode’s color...
    – shynur
    Mar 16 at 1:40
  • Search this site for [parentheses] [highlight].
    – Drew
    Mar 22 at 3:41

2 Answers 2

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.

1
  • 1
    Sincerely, rainbow-delimiters or highlight-parentheses may be a better choice.
    – shynur
    Mar 16 at 1:44
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.

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.