branch: elpa/highlight-parentheses
commit f0bd58c8dadd2db703b7bfd09e911b5fda05b3df
Merge: c38885b 73b4aa7
Author: Tassilo Horn <[email protected]>
Commit: GitHub <[email protected]>
Merge pull request #20 from tprk77/master
Optionally highlight adjacent parens
---
highlight-parentheses.el | 29 +++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/highlight-parentheses.el b/highlight-parentheses.el
index bdffd37..0d602a0 100644
--- a/highlight-parentheses.el
+++ b/highlight-parentheses.el
@@ -1,6 +1,7 @@
;;; highlight-parentheses.el --- highlight surrounding parentheses
;;
;; Copyright (C) 2007, 2009, 2013 Nikolaj Schumacher
+;; Copyright (C) 2018 Tim Perkins
;;
;; Author: Nikolaj Schumacher <bugs * nschum de>
;; Maintainer: Tassilo Horn <[email protected]>
@@ -69,6 +70,12 @@ The list starts with the inside parentheses and moves
outwards."
:set 'hl-paren-set
:group 'highlight-parentheses)
+(defcustom hl-paren-highlight-adjacent nil
+ "Highlight adjacent parentheses, just like show-paren-mode."
+ :type '(boolean)
+ :set 'hl-paren-set
+ :group 'highlight-parentheses)
+
(defface hl-paren-face nil
"Face used for highlighting parentheses.
Color attributes might be overriden by `hl-paren-colors' and
@@ -98,17 +105,19 @@ This is used to prevent analyzing the same context over
and over.")
(unless (= (point) hl-paren-last-point)
(setq hl-paren-last-point (point))
(let ((overlays hl-paren-overlays)
- pos1 pos2
- (pos (point)))
+ pos1 pos2)
(save-excursion
- (condition-case err
- (while (and (setq pos1 (cadr (syntax-ppss pos1)))
- (cdr overlays))
- (move-overlay (pop overlays) pos1 (1+ pos1))
- (when (setq pos2 (scan-sexps pos1 1))
- (move-overlay (pop overlays) (1- pos2) pos2)))
- (error nil))
- (goto-char pos))
+ (ignore-errors
+ (when hl-paren-highlight-adjacent
+ (cond ((memq (preceding-char) '(?\) ?\} ?\] ?\>))
+ (backward-char 1))
+ ((memq (following-char) '(?\( ?\{ ?\[ ?\<))
+ (forward-char 1))))
+ (while (and (setq pos1 (cadr (syntax-ppss pos1)))
+ (cdr overlays))
+ (move-overlay (pop overlays) pos1 (1+ pos1))
+ (when (setq pos2 (scan-sexps pos1 1))
+ (move-overlay (pop overlays) (1- pos2) pos2)))))
(hl-paren-delete-overlays overlays))))
(defcustom hl-paren-delay 0.137