2

I am using Emacs: Highlight Brackets ()[]{}.

I want to highlight matching brackets when the cursor is behind and front of starting and ending brackets. How can I accomplish this?

foo ( "hello" ) 
   ^ ^       ^ ^
   1 2       3 4 // cursor points

I have followed @Gilles 'SO- stop being evil's answer for Changing show-paren-mode Areas:

(defadvice show-paren-function
 (around show-paren-closing-before
         activate compile)
 (if (eq (syntax-class (syntax-after (point))) 5)
     (save-excursion
       (forward-char)
       ad-do-it)
   ad-do-it))

which helped me to highlight brackets cursor points 1, 3, 4, but it does not highlight when on 2nd cursor point.

My setup is:

(show-paren-mode 1)
(setq show-paren-delay 0)
(setq show-paren-style 'parenthesis)

(defadvice show-paren-function
  (around show-paren-closing-before
          activate compile)
  (if (eq (syntax-class (syntax-after (point))) 5)
      (save-excursion
        (forward-char)
        ad-do-it)
    ad-do-it))

(require 'paren)
(setq show-paren-style 'parenthesis)
NickD
  • 27,023
  • 3
  • 23
  • 42
alper
  • 1,238
  • 11
  • 30
  • The only time when this works for me is at cursor position 3 - and reading the code that's the only time when it *should* work. So I'm not sure how it helps with positions 1 and 4. The syntax class of an opening paren is 4 and the syntax class of a closing paren is 5 (see [Syntax Table Internals](https://www.gnu.org/software/emacs/manual/html_node/elisp/Syntax-Table-Internals.html#Syntax-Table-Internals)). – NickD Jun 17 '20 at 21:23
  • I am not sure how I end up working it on positions `[1,3,4]`. Could there be any other solution to make it work on all positions? – alper Jun 18 '20 at 08:30

0 Answers0