Mercurial > emacs
annotate lisp/paren.el @ 104050:8ee742481c0a
(gnus-demon-add-nntp-close-connection): Fix typo. (Bug#3903)
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Fri, 24 Jul 2009 03:54:25 +0000 |
parents | 3bd929838554 |
children | afa0e028ba97 |
rev | line source |
---|---|
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
33194
diff
changeset
|
1 ;;; paren.el --- highlight matching paren |
14169 | 2 |
64762
41bb365f41c4
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64091
diff
changeset
|
3 ;; Copyright (C) 1993, 1996, 2001, 2002, 2003, 2004, |
100908 | 4 ;; 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. |
3912 | 5 |
25278 | 6 ;; Author: rms@gnu.org |
3977 | 7 ;; Maintainer: FSF |
8 ;; Keywords: languages, faces | |
3976 | 9 |
3912 | 10 ;; This file is part of GNU Emacs. |
11 | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
12 ;; GNU Emacs is free software: you can redistribute it and/or modify |
3912 | 13 ;; it under the terms of the GNU General Public License as published by |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
14 ;; the Free Software Foundation, either version 3 of the License, or |
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
15 ;; (at your option) any later version. |
3912 | 16 |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
3912 | 24 |
25 ;;; Commentary: | |
26 | |
39979
b2ccc516d0dd
Update the Commentary with installation instructions.
Eli Zaretskii <eliz@gnu.org>
parents:
38412
diff
changeset
|
27 ;; Put this into your ~/.emacs: |
b2ccc516d0dd
Update the Commentary with installation instructions.
Eli Zaretskii <eliz@gnu.org>
parents:
38412
diff
changeset
|
28 |
b2ccc516d0dd
Update the Commentary with installation instructions.
Eli Zaretskii <eliz@gnu.org>
parents:
38412
diff
changeset
|
29 ;; (show-paren-mode t) |
b2ccc516d0dd
Update the Commentary with installation instructions.
Eli Zaretskii <eliz@gnu.org>
parents:
38412
diff
changeset
|
30 |
b2ccc516d0dd
Update the Commentary with installation instructions.
Eli Zaretskii <eliz@gnu.org>
parents:
38412
diff
changeset
|
31 ;; It will display highlighting on whatever paren matches the one |
b2ccc516d0dd
Update the Commentary with installation instructions.
Eli Zaretskii <eliz@gnu.org>
parents:
38412
diff
changeset
|
32 ;; before or after point. |
3912 | 33 |
34 ;;; Code: | |
35 | |
18330
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
36 (defgroup paren-showing nil |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
37 "Showing (un)matching of parens and expressions." |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
38 :prefix "show-paren-" |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
39 :group 'paren-matching) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
40 |
4123
b05c50e08993
Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents:
4059
diff
changeset
|
41 ;; This is the overlay used to highlight the matching paren. |
3917 | 42 (defvar show-paren-overlay nil) |
14706
e7352445b396
(show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14624
diff
changeset
|
43 ;; 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
|
44 (defvar show-paren-overlay-1 nil) |
b05c50e08993
Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents:
4059
diff
changeset
|
45 |
18330
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
46 (defcustom show-paren-style 'parenthesis |
100171 | 47 "Style used when showing a matching paren. |
18330
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
48 Valid styles are `parenthesis' (meaning show the matching paren), |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
49 `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
|
50 `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
|
51 otherwise)." |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
52 :type '(choice (const parenthesis) (const expression) (const mixed)) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
53 :group 'paren-showing) |
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-delay |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
56 (if (featurep 'lisp-float-type) (/ (float 1) (float 8)) 1) |
100171 | 57 "Time in seconds to delay before showing a matching paren." |
18330
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
58 :type '(number :tag "seconds") |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
59 :group 'paren-showing) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
60 |
30787
efa4d1ed3f1b
(show-paren-priority): New user option.
Gerd Moellmann <gerd@gnu.org>
parents:
25813
diff
changeset
|
61 (defcustom show-paren-priority 1000 |
100171 | 62 "Priority of paren highlighting overlays." |
30787
efa4d1ed3f1b
(show-paren-priority): New user option.
Gerd Moellmann <gerd@gnu.org>
parents:
25813
diff
changeset
|
63 :type 'integer |
efa4d1ed3f1b
(show-paren-priority): New user option.
Gerd Moellmann <gerd@gnu.org>
parents:
25813
diff
changeset
|
64 :group 'paren-showing |
efa4d1ed3f1b
(show-paren-priority): New user option.
Gerd Moellmann <gerd@gnu.org>
parents:
25813
diff
changeset
|
65 :version "21.1") |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48607
diff
changeset
|
66 |
21891
7d49e4c824b6
(show-paren-ring-bell-on-mismatch): New option.
Richard M. Stallman <rms@gnu.org>
parents:
18837
diff
changeset
|
67 (defcustom show-paren-ring-bell-on-mismatch nil |
100171 | 68 "If non-nil, beep if mismatched paren is detected." |
21891
7d49e4c824b6
(show-paren-ring-bell-on-mismatch): New option.
Richard M. Stallman <rms@gnu.org>
parents:
18837
diff
changeset
|
69 :type 'boolean |
7d49e4c824b6
(show-paren-ring-bell-on-mismatch): New option.
Richard M. Stallman <rms@gnu.org>
parents:
18837
diff
changeset
|
70 :group 'paren-showing |
7d49e4c824b6
(show-paren-ring-bell-on-mismatch): New option.
Richard M. Stallman <rms@gnu.org>
parents:
18837
diff
changeset
|
71 :version "20.3") |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48607
diff
changeset
|
72 |
67913
cf3a03548c18
(show-paren-match, show-paren-mismatch): Use existing group
Juri Linkov <juri@jurta.org>
parents:
67837
diff
changeset
|
73 (defgroup paren-showing-faces nil |
cf3a03548c18
(show-paren-match, show-paren-mismatch): Use existing group
Juri Linkov <juri@jurta.org>
parents:
67837
diff
changeset
|
74 "Group for faces of Show Paren mode." |
67837
88a152f5d26c
(paren-showing-faces): New group.
Richard M. Stallman <rms@gnu.org>
parents:
67153
diff
changeset
|
75 :group 'paren-showing |
88a152f5d26c
(paren-showing-faces): New group.
Richard M. Stallman <rms@gnu.org>
parents:
67153
diff
changeset
|
76 :group 'faces |
88a152f5d26c
(paren-showing-faces): New group.
Richard M. Stallman <rms@gnu.org>
parents:
67153
diff
changeset
|
77 :version "22.1") |
88a152f5d26c
(paren-showing-faces): New group.
Richard M. Stallman <rms@gnu.org>
parents:
67153
diff
changeset
|
78 |
63202
d307630996bc
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-373
Miles Bader <miles@gnu.org>
parents:
61672
diff
changeset
|
79 (defface show-paren-match |
40794
3ab0eeb4df95
(show-paren-match-face): Add dark-background variant.
Miles Bader <miles@gnu.org>
parents:
39979
diff
changeset
|
80 '((((class color) (background light)) |
3ab0eeb4df95
(show-paren-match-face): Add dark-background variant.
Miles Bader <miles@gnu.org>
parents:
39979
diff
changeset
|
81 :background "turquoise") ; looks OK on tty (becomes cyan) |
3ab0eeb4df95
(show-paren-match-face): Add dark-background variant.
Miles Bader <miles@gnu.org>
parents:
39979
diff
changeset
|
82 (((class color) (background dark)) |
3ab0eeb4df95
(show-paren-match-face): Add dark-background variant.
Miles Bader <miles@gnu.org>
parents:
39979
diff
changeset
|
83 :background "steelblue3") ; looks OK on tty (becomes blue) |
3ab0eeb4df95
(show-paren-match-face): Add dark-background variant.
Miles Bader <miles@gnu.org>
parents:
39979
diff
changeset
|
84 (((background dark)) |
3ab0eeb4df95
(show-paren-match-face): Add dark-background variant.
Miles Bader <miles@gnu.org>
parents:
39979
diff
changeset
|
85 :background "grey50") |
3ab0eeb4df95
(show-paren-match-face): Add dark-background variant.
Miles Bader <miles@gnu.org>
parents:
39979
diff
changeset
|
86 (t |
3ab0eeb4df95
(show-paren-match-face): Add dark-background variant.
Miles Bader <miles@gnu.org>
parents:
39979
diff
changeset
|
87 :background "gray")) |
18330
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
88 "Show Paren mode face used for a matching paren." |
67913
cf3a03548c18
(show-paren-match, show-paren-mismatch): Use existing group
Juri Linkov <juri@jurta.org>
parents:
67837
diff
changeset
|
89 :group 'paren-showing-faces) |
63202
d307630996bc
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-373
Miles Bader <miles@gnu.org>
parents:
61672
diff
changeset
|
90 ;; backward-compatibility alias |
d307630996bc
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-373
Miles Bader <miles@gnu.org>
parents:
61672
diff
changeset
|
91 (put 'show-paren-match-face 'face-alias 'show-paren-match) |
18330
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
92 |
63202
d307630996bc
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-373
Miles Bader <miles@gnu.org>
parents:
61672
diff
changeset
|
93 (defface show-paren-mismatch |
18330
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
94 '((((class color)) (:foreground "white" :background "purple")) |
48607
6e11dc64eeca
(show-paren-mismatch-face): Fix face spec.
Andreas Schwab <schwab@suse.de>
parents:
47357
diff
changeset
|
95 (t (:inverse-video t))) |
18330
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
96 "Show Paren mode face used for a mismatching paren." |
67913
cf3a03548c18
(show-paren-match, show-paren-mismatch): Use existing group
Juri Linkov <juri@jurta.org>
parents:
67837
diff
changeset
|
97 :group 'paren-showing-faces) |
63202
d307630996bc
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-373
Miles Bader <miles@gnu.org>
parents:
61672
diff
changeset
|
98 ;; backward-compatibility alias |
d307630996bc
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-373
Miles Bader <miles@gnu.org>
parents:
61672
diff
changeset
|
99 (put 'show-paren-mismatch-face 'face-alias 'show-paren-mismatch) |
4183
a5f0a739d87d
(show-paren-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4123
diff
changeset
|
100 |
55176
6bce3db285b5
(show-paren-highlight-openparen): New var.
Juri Linkov <juri@jurta.org>
parents:
52401
diff
changeset
|
101 (defvar show-paren-highlight-openparen t |
6bce3db285b5
(show-paren-highlight-openparen): New var.
Juri Linkov <juri@jurta.org>
parents:
52401
diff
changeset
|
102 "*Non-nil turns on openparen highlighting when matching forward.") |
6bce3db285b5
(show-paren-highlight-openparen): New var.
Juri Linkov <juri@jurta.org>
parents:
52401
diff
changeset
|
103 |
18582
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
104 (defvar show-paren-idle-timer nil) |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
105 |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
106 ;;;###autoload |
31976
236a7f6d898d
(show-paren-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30787
diff
changeset
|
107 (define-minor-mode show-paren-mode |
18582
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
108 "Toggle Show Paren mode. |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
109 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
|
110 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
|
111 |
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
112 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
|
113 in `show-paren-style' after `show-paren-delay' seconds of Emacs idle time." |
33194
cbfead93715d
(show-paren-mode): Drop unneeded positional args.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31976
diff
changeset
|
114 :global t :group 'paren-showing |
67153
8dc626ffc10d
(show-paren-mode): No longer change `blink-matching-paren-on-screen'.
Luc Teirlinck <teirllm@auburn.edu>
parents:
67052
diff
changeset
|
115 ;; Enable or disable the mechanism. |
25275
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
116 ;; First get rid of the old idle timer. |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
117 (if show-paren-idle-timer |
18582
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
118 (cancel-timer show-paren-idle-timer)) |
25275
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
119 (setq show-paren-idle-timer nil) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
120 ;; If show-paren-mode is enabled in some buffer now, |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
121 ;; set up a new timer. |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
122 (when (memq t (mapcar (lambda (buffer) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
123 (with-current-buffer buffer |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
124 show-paren-mode)) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
125 (buffer-list))) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
126 (setq show-paren-idle-timer (run-with-idle-timer |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
127 show-paren-delay t |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
128 'show-paren-function))) |
31976
236a7f6d898d
(show-paren-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30787
diff
changeset
|
129 (unless show-paren-mode |
25275
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
130 (and show-paren-overlay |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
131 (eq (overlay-buffer show-paren-overlay) (current-buffer)) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
132 (delete-overlay show-paren-overlay)) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
133 (and show-paren-overlay-1 |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
134 (eq (overlay-buffer show-paren-overlay-1) (current-buffer)) |
31976
236a7f6d898d
(show-paren-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30787
diff
changeset
|
135 (delete-overlay show-paren-overlay-1)))) |
18582
fd88d8f82bbc
(show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18567
diff
changeset
|
136 |
3917 | 137 ;; Find the place to show, if there is one, |
138 ;; and show it until input arrives. | |
14706
e7352445b396
(show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
14624
diff
changeset
|
139 (defun show-paren-function () |
25275
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
140 (if show-paren-mode |
47357
97c0efea1010
(show-paren-function): Use syntax-after.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43830
diff
changeset
|
141 (let ((oldpos (point)) |
61672
d7252d4ac684
(show-paren-function): Use it to recognize parens that are
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
58805
diff
changeset
|
142 (dir (cond ((eq (syntax-class (syntax-after (1- (point)))) 5) -1) |
d7252d4ac684
(show-paren-function): Use it to recognize parens that are
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
58805
diff
changeset
|
143 ((eq (syntax-class (syntax-after (point))) 4) 1))) |
47357
97c0efea1010
(show-paren-function): Use syntax-after.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43830
diff
changeset
|
144 pos mismatch face) |
25275
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
145 ;; |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
146 ;; Find the other end of the sexp. |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
147 (when dir |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
148 (save-excursion |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
149 (save-restriction |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
150 ;; Determine the range within which to look for a match. |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
151 (when blink-matching-paren-distance |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
152 (narrow-to-region |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
153 (max (point-min) (- (point) blink-matching-paren-distance)) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
154 (min (point-max) (+ (point) blink-matching-paren-distance)))) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
155 ;; Scan across one sexp within that range. |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
156 ;; Errors or nil mean there is a mismatch. |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
157 (condition-case () |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
158 (setq pos (scan-sexps (point) dir)) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
159 (error (setq pos t mismatch t))) |
43830
78c2427665f0
(show-paren-function): Move back in other direction
Richard M. Stallman <rms@gnu.org>
parents:
40794
diff
changeset
|
160 ;; Move back the other way and verify we get back to the |
78c2427665f0
(show-paren-function): Move back in other direction
Richard M. Stallman <rms@gnu.org>
parents:
40794
diff
changeset
|
161 ;; starting point. If not, these two parens don't really match. |
78c2427665f0
(show-paren-function): Move back in other direction
Richard M. Stallman <rms@gnu.org>
parents:
40794
diff
changeset
|
162 ;; Maybe the one at point is escaped and doesn't really count. |
78c2427665f0
(show-paren-function): Move back in other direction
Richard M. Stallman <rms@gnu.org>
parents:
40794
diff
changeset
|
163 (when (integerp pos) |
78c2427665f0
(show-paren-function): Move back in other direction
Richard M. Stallman <rms@gnu.org>
parents:
40794
diff
changeset
|
164 (unless (condition-case () |
78c2427665f0
(show-paren-function): Move back in other direction
Richard M. Stallman <rms@gnu.org>
parents:
40794
diff
changeset
|
165 (eq (point) (scan-sexps pos (- dir))) |
78c2427665f0
(show-paren-function): Move back in other direction
Richard M. Stallman <rms@gnu.org>
parents:
40794
diff
changeset
|
166 (error nil)) |
78c2427665f0
(show-paren-function): Move back in other direction
Richard M. Stallman <rms@gnu.org>
parents:
40794
diff
changeset
|
167 (setq pos nil))) |
25275
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
168 ;; If found a "matching" paren, see if it is the right |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
169 ;; kind of paren to match the one we started at. |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
170 (when (integerp pos) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
171 (let ((beg (min pos oldpos)) (end (max pos oldpos))) |
61672
d7252d4ac684
(show-paren-function): Use it to recognize parens that are
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
58805
diff
changeset
|
172 (unless (eq (syntax-class (syntax-after beg)) 8) |
25275
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
173 (setq mismatch |
58805
769c3bb23105
(show-paren-function): Fix last change (2004-12-02).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
58738
diff
changeset
|
174 (not (or (eq (char-before end) |
769c3bb23105
(show-paren-function): Fix last change (2004-12-02).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
58738
diff
changeset
|
175 ;; This can give nil. |
769c3bb23105
(show-paren-function): Fix last change (2004-12-02).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
58738
diff
changeset
|
176 (cdr (syntax-after beg))) |
769c3bb23105
(show-paren-function): Fix last change (2004-12-02).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
58738
diff
changeset
|
177 (eq (char-after beg) |
769c3bb23105
(show-paren-function): Fix last change (2004-12-02).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
58738
diff
changeset
|
178 ;; This can give nil. |
67052
8ad986f91500
(show-paren-function): Allow new paren-class info.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
179 (cdr (syntax-after (1- end)))) |
8ad986f91500
(show-paren-function): Allow new paren-class info.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
180 ;; The cdr might hold a new paren-class |
8ad986f91500
(show-paren-function): Allow new paren-class info.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
181 ;; info rather than a matching-char info, |
8ad986f91500
(show-paren-function): Allow new paren-class info.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
182 ;; in which case the two CDRs should match. |
8ad986f91500
(show-paren-function): Allow new paren-class info.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
183 (eq (cdr (syntax-after (1- end))) |
8ad986f91500
(show-paren-function): Allow new paren-class info.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64762
diff
changeset
|
184 (cdr (syntax-after beg)))))))))))) |
18330
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
185 ;; |
25275
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
186 ;; Highlight the other end of the sexp, or unhighlight if none. |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
187 (if (not pos) |
21891
7d49e4c824b6
(show-paren-ring-bell-on-mismatch): New option.
Richard M. Stallman <rms@gnu.org>
parents:
18837
diff
changeset
|
188 (progn |
25275
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
189 ;; If not at a paren that has a match, |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
190 ;; turn off any previous paren highlighting. |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
191 (and show-paren-overlay (overlay-buffer show-paren-overlay) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
192 (delete-overlay show-paren-overlay)) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
193 (and show-paren-overlay-1 (overlay-buffer show-paren-overlay-1) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
194 (delete-overlay show-paren-overlay-1))) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
195 ;; |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
196 ;; Use the correct face. |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
197 (if mismatch |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
198 (progn |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
199 (if show-paren-ring-bell-on-mismatch |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
200 (beep)) |
63202
d307630996bc
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-373
Miles Bader <miles@gnu.org>
parents:
61672
diff
changeset
|
201 (setq face 'show-paren-mismatch)) |
d307630996bc
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-373
Miles Bader <miles@gnu.org>
parents:
61672
diff
changeset
|
202 (setq face 'show-paren-match)) |
25275
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
203 ;; |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
204 ;; If matching backwards, highlight the closeparen |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
205 ;; before point as well as its matching open. |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
206 ;; If matching forward, and the openparen is unbalanced, |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
207 ;; highlight the paren at point to indicate misbalance. |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
208 ;; Otherwise, turn off any such highlighting. |
55176
6bce3db285b5
(show-paren-highlight-openparen): New var.
Juri Linkov <juri@jurta.org>
parents:
52401
diff
changeset
|
209 (if (and (not show-paren-highlight-openparen) (= dir 1) (integerp pos)) |
25275
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
210 (when (and show-paren-overlay-1 |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
211 (overlay-buffer show-paren-overlay-1)) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
212 (delete-overlay show-paren-overlay-1)) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
213 (let ((from (if (= dir 1) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
214 (point) |
102658
3bd929838554
* subr.el (forward-point): Add obsolescence declaration.
Juanma Barranquero <lekktu@gmail.com>
parents:
100908
diff
changeset
|
215 (- (point) 1))) |
25275
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
216 (to (if (= dir 1) |
102658
3bd929838554
* subr.el (forward-point): Add obsolescence declaration.
Juanma Barranquero <lekktu@gmail.com>
parents:
100908
diff
changeset
|
217 (+ (point) 1) |
25275
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
218 (point)))) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
219 (if show-paren-overlay-1 |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
220 (move-overlay show-paren-overlay-1 from to (current-buffer)) |
74359
749bbf34ba64
Fix the highlight overlay extension
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
68651
diff
changeset
|
221 (setq show-paren-overlay-1 (make-overlay from to nil t))) |
25275
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
222 ;; Always set the overlay face, since it varies. |
30787
efa4d1ed3f1b
(show-paren-priority): New user option.
Gerd Moellmann <gerd@gnu.org>
parents:
25813
diff
changeset
|
223 (overlay-put show-paren-overlay-1 'priority show-paren-priority) |
25275
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
224 (overlay-put show-paren-overlay-1 'face face))) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
225 ;; |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
226 ;; Turn on highlighting for the matching paren, if found. |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
227 ;; If it's an unmatched paren, turn off any such highlighting. |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
228 (unless (integerp pos) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
229 (delete-overlay show-paren-overlay)) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
230 (let ((to (if (or (eq show-paren-style 'expression) |
18330
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
231 (and (eq show-paren-style 'mixed) |
005facba9434
customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents:
18318
diff
changeset
|
232 (not (pos-visible-in-window-p pos)))) |
25275
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
233 (point) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
234 pos)) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
235 (from (if (or (eq show-paren-style 'expression) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
236 (and (eq show-paren-style 'mixed) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
237 (not (pos-visible-in-window-p pos)))) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
238 pos |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
239 (save-excursion |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
240 (goto-char pos) |
102658
3bd929838554
* subr.el (forward-point): Add obsolescence declaration.
Juanma Barranquero <lekktu@gmail.com>
parents:
100908
diff
changeset
|
241 (- (point) dir))))) |
25275
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
242 (if show-paren-overlay |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
243 (move-overlay show-paren-overlay from to (current-buffer)) |
74359
749bbf34ba64
Fix the highlight overlay extension
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
68651
diff
changeset
|
244 (setq show-paren-overlay (make-overlay from to nil t)))) |
25275
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
245 ;; |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
246 ;; Always set the overlay face, since it varies. |
30787
efa4d1ed3f1b
(show-paren-priority): New user option.
Gerd Moellmann <gerd@gnu.org>
parents:
25813
diff
changeset
|
247 (overlay-put show-paren-overlay 'priority show-paren-priority) |
77851
5d313ba2e8de
(show-paren-function): Undo 2007-04-19 and 2007-04-20 changes.
Chong Yidong <cyd@stupidchicken.com>
parents:
77333
diff
changeset
|
248 (overlay-put show-paren-overlay 'face face))) |
25275
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
249 ;; show-paren-mode is nil in this buffer. |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
250 (and show-paren-overlay |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
251 (delete-overlay show-paren-overlay)) |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
252 (and show-paren-overlay-1 |
1b1edbd429ea
(show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents:
24650
diff
changeset
|
253 (delete-overlay show-paren-overlay-1)))) |
3912 | 254 |
3919 | 255 (provide 'paren) |
256 | |
58416
28906724d6e3
(syntax-after): Undo last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
58042
diff
changeset
|
257 ;; arch-tag: d0969b88-7ac0-4bd0-bd53-e73b892b86a9 |
3919 | 258 ;;; paren.el ends here |