Mercurial > emacs
annotate lisp/paren.el @ 18717:70ed7ba1ed08
(hilit-submit-feedback): Change mail address.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 10 Jul 1997 06:50:14 +0000 |
parents | fd88d8f82bbc |
children | 9b248fbd740f |
rev | line source |
---|---|
3912 | 1 ;;; paren.el --- highlight matching paren. |
14169 | 2 |
14706
e7352445b396
(show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14624
diff
changeset
|
3 ;; Copyright (C) 1993, 1996 Free Software Foundation, Inc. |
3912 | 4 |
3977 | 5 ;; Author: rms@gnu.ai.mit.edu |
6 ;; Maintainer: FSF | |
7 ;; Keywords: languages, faces | |
3976 | 8 |
3912 | 9 ;; This file is part of GNU Emacs. |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
14169 | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
3912 | 25 |
26 ;;; Commentary: | |
27 | |
28 ;; Load this and it will display highlighting on whatever | |
29 ;; paren matches the one before or after point. | |
30 | |
31 ;;; Code: | |
32 | |
18330
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
33 (defgroup paren-showing nil |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
34 "Showing (un)matching of parens and expressions." |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
35 :prefix "show-paren-" |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
36 :group 'paren-matching) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
37 |
4123
b05c50e08993
Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents:
4059
diff
changeset
|
38 ;; This is the overlay used to highlight the matching paren. |
3917 | 39 (defvar show-paren-overlay nil) |
14706
e7352445b396
(show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14624
diff
changeset
|
40 ;; This is the overlay used to highlight the closeparen right before point. |
4123
b05c50e08993
Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents:
4059
diff
changeset
|
41 (defvar show-paren-overlay-1 nil) |
b05c50e08993
Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents:
4059
diff
changeset
|
42 |
18330
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
43 (defcustom show-paren-mode nil |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
44 "Toggle Show Paren mode. |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
45 When Show Paren mode is enabled, any matching parenthesis is highlighted |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
46 after `show-paren-delay' seconds of Emacs idle time. |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
47 You must modify via \\[customize] for this variable to have an effect." |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
48 :set (lambda (symbol value) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
49 (show-paren-mode (or value 0))) |
18582
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
50 :initialize 'custom-initialize-default |
18330
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
51 :type 'boolean |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
52 :group 'paren-showing |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
53 :require 'paren) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
54 |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
55 (defcustom show-paren-style 'parenthesis |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
56 "*Style used when showing a matching paren. |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
57 Valid styles are `parenthesis' (meaning show the matching paren), |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
58 `expression' (meaning show the entire expression enclosed by the paren) and |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
59 `mixed' (meaning show the matching paren if it is visible, and the expression |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
60 otherwise)." |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
61 :type '(choice (const parenthesis) (const expression) (const mixed)) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
62 :group 'paren-showing) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
63 |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
64 (defcustom show-paren-delay |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
65 (if (featurep 'lisp-float-type) (/ (float 1) (float 8)) 1) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
66 "*Time in seconds to delay before showing a matching paren." |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
67 :type '(number :tag "seconds") |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
68 :group 'paren-showing) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
69 |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
70 (defface show-paren-match-face |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
71 '((((class color)) (:background "turquoise")) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
72 (((class grayscale)) (:background "gray")) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
73 (t (:reverse-video t))) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
74 "Show Paren mode face used for a matching paren." |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
75 :group 'faces |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
76 :group 'paren-showing) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
77 |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
78 (defface show-paren-mismatch-face |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
79 '((((class color)) (:foreground "white" :background "purple")) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
80 (t (:reverse-video t))) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
81 "Show Paren mode face used for a mismatching paren." |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
82 :group 'faces |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
83 :group 'paren-showing) |
4183
a5f0a739d87d
(show-paren-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4123
diff
changeset
|
84 |
18582
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
85 (defvar show-paren-idle-timer nil) |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
86 |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
87 ;;;###autoload |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
88 (defun show-paren-mode (&optional arg) |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
89 "Toggle Show Paren mode. |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
90 With prefix ARG, turn Show Paren mode on if and only if ARG is positive. |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
91 Returns the new status of Show Paren mode (non-nil means on). |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
92 |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
93 When Show Paren mode is enabled, any matching parenthesis is highlighted |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
94 in `show-paren-style' after `show-paren-delay' seconds of Emacs idle time." |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
95 (interactive "P") |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
96 (when window-system |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
97 (let ((on-p (if arg |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
98 (> (prefix-numeric-value arg) 0) |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
99 (not show-paren-mode)))) |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
100 (setq blink-matching-paren-on-screen (not on-p)) |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
101 (when show-paren-idle-timer |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
102 (cancel-timer show-paren-idle-timer)) |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
103 (if on-p |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
104 (setq show-paren-idle-timer (run-with-idle-timer |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
105 show-paren-delay t |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
106 'show-paren-function)) |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
107 (and show-paren-overlay (overlay-buffer show-paren-overlay) |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
108 (delete-overlay show-paren-overlay)) |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
109 (and show-paren-overlay-1 (overlay-buffer show-paren-overlay-1) |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
110 (delete-overlay show-paren-overlay-1))) |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
111 (setq show-paren-mode on-p)))) |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
112 |
3917 | 113 ;; Find the place to show, if there is one, |
114 ;; and show it until input arrives. | |
14706
e7352445b396
(show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14624
diff
changeset
|
115 (defun show-paren-function () |
4582
7b665693054c
(show-paren-command-hook): Do nothing if input is pending.
Richard M. Stallman <rms@gnu.org>
parents:
4565
diff
changeset
|
116 ;; Do nothing if no window system to display results with. |
5623
d571ad3c796e
(show-paren-command-hook): Do nothing when in kbd macro.
Richard M. Stallman <rms@gnu.org>
parents:
4582
diff
changeset
|
117 ;; Do nothing if executing keyboard macro. |
4582
7b665693054c
(show-paren-command-hook): Do nothing if input is pending.
Richard M. Stallman <rms@gnu.org>
parents:
4565
diff
changeset
|
118 ;; Do nothing if input is pending. |
18330
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
119 (when window-system |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
120 (let (pos dir mismatch face (oldpos (point))) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
121 (cond ((eq (char-syntax (preceding-char)) ?\)) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
122 (setq dir -1)) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
123 ((eq (char-syntax (following-char)) ?\() |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
124 (setq dir 1))) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
125 ;; |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
126 ;; Find the other end of the sexp. |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
127 (when dir |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
128 (save-excursion |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
129 (save-restriction |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
130 ;; Determine the range within which to look for a match. |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
131 (when blink-matching-paren-distance |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
132 (narrow-to-region |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
133 (max (point-min) (- (point) blink-matching-paren-distance)) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
134 (min (point-max) (+ (point) blink-matching-paren-distance)))) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
135 ;; Scan across one sexp within that range. |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
136 ;; Errors or nil mean there is a mismatch. |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
137 (condition-case () |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
138 (setq pos (scan-sexps (point) dir)) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
139 (error (setq pos t mismatch t))) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
140 ;; If found a "matching" paren, see if it is the right |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
141 ;; kind of paren to match the one we started at. |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
142 (when (integerp pos) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
143 (let ((beg (min pos oldpos)) (end (max pos oldpos))) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
144 (when (/= (char-syntax (char-after beg)) ?\$) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
145 (setq mismatch |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
146 (not (eq (char-before end) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
147 ;; This can give nil. |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
148 (matching-paren (char-after beg))))))))))) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
149 ;; |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
150 ;; Highlight the other end of the sexp, or unhighlight if none. |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
151 (if (not pos) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
152 (progn |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
153 ;; If not at a paren that has a match, |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
154 ;; turn off any previous paren highlighting. |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
155 (and show-paren-overlay (overlay-buffer show-paren-overlay) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
156 (delete-overlay show-paren-overlay)) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
157 (and show-paren-overlay-1 (overlay-buffer show-paren-overlay-1) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
158 (delete-overlay show-paren-overlay-1))) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
159 ;; |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
160 ;; Use the correct face. |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
161 (if mismatch |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
162 (setq face 'show-paren-mismatch-face) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
163 (setq face 'show-paren-match-face)) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
164 ;; |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
165 ;; If matching backwards, highlight the closeparen |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
166 ;; before point as well as its matching open. |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
167 ;; If matching forward, and the openparen is unbalanced, |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
168 ;; highlight the paren at point to indicate misbalance. |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
169 ;; Otherwise, turn off any such highlighting. |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
170 (if (and (= dir 1) (integerp pos)) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
171 (when (and show-paren-overlay-1 |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
172 (overlay-buffer show-paren-overlay-1)) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
173 (delete-overlay show-paren-overlay-1)) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
174 (let ((from (if (= dir 1) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
175 (point) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
176 (forward-point -1))) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
177 (to (if (= dir 1) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
178 (forward-point 1) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
179 (point)))) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
180 (if show-paren-overlay-1 |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
181 (move-overlay show-paren-overlay-1 from to (current-buffer)) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
182 (setq show-paren-overlay-1 (make-overlay from to))) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
183 ;; Always set the overlay face, since it varies. |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
184 (overlay-put show-paren-overlay-1 'face face))) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
185 ;; |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
186 ;; Turn on highlighting for the matching paren, if found. |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
187 ;; If it's an unmatched paren, turn off any such highlighting. |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
188 (unless (integerp pos) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
189 (delete-overlay show-paren-overlay)) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
190 (let ((to (if (or (eq show-paren-style 'expression) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
191 (and (eq show-paren-style 'mixed) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
192 (not (pos-visible-in-window-p pos)))) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
193 (point) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
194 pos)) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
195 (from (if (or (eq show-paren-style 'expression) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
196 (and (eq show-paren-style 'mixed) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
197 (not (pos-visible-in-window-p pos)))) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
198 pos |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
199 (save-excursion |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
200 (goto-char pos) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
201 (forward-point (- dir)))))) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
202 (if show-paren-overlay |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
203 (move-overlay show-paren-overlay from to (current-buffer)) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
204 (setq show-paren-overlay (make-overlay from to)))) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
205 ;; |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
206 ;; Always set the overlay face, since it varies. |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
207 (overlay-put show-paren-overlay 'face face))))) |
3912 | 208 |
3919 | 209 (provide 'paren) |
210 | |
18582
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
211 (if show-paren-mode |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
212 (show-paren-mode t)) |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
213 |
3919 | 214 ;;; paren.el ends here |