Matching braces in Emacs

前端 未结 5 1927
孤独总比滥情好
孤独总比滥情好 2021-02-18 20:56

In GNU Emacs there is a feature to highlight matching brackets in code with the same colour.

However when the code which the brackets enclose is really long with severa

5条回答
  •  闹比i
    闹比i (楼主)
    2021-02-18 21:34

    (defun px-match-paren (arg)
      "Go to the matching paren if on a paren; otherwise insert ."
      (interactive "p")
      (cond
       ((char-equal 41 (char-before)) (backward-list 1))
       ((char-equal 125 (char-before)) (backward-list 1))
       ((and
         (char-equal 123 (char-before))
         (char-equal 10 (char-after)))
        (backward-char 1) (forward-list 1))
       ((looking-at "\\s\(") (forward-list 1))
       ((looking-at "\\s\)") (backward-list 1))
       (t (self-insert-command (or arg 1)))))
    

    The to witch you bind this command will toggle opening and closing brace if point is before or after it, otherwise insert (much like vi's "%")

    I also bind C- to forward-sexp and C-S- to backward-sexp so I can really quickly navigate through functions in the file.

提交回复
热议问题