annotate lisp/paren.el @ 44155:d94cb7b3b165

(Fdisplay_buffer): Doc fix.
author Richard M. Stallman <rms@gnu.org>
date Tue, 26 Mar 2002 09:09:56 +0000
parents 78c2427665f0
children 97c0efea1010
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13805
diff changeset
2
40794
3ab0eeb4df95 (show-paren-match-face): Add dark-background variant.
Miles Bader <miles@gnu.org>
parents: 39979
diff changeset
3 ;; Copyright (C) 1993, 1996, 2001 Free Software Foundation, Inc.
3912
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4
25278
cbe304a26771 Fix maintainer address.
Karl Heuer <kwzh@gnu.org>
parents: 25275
diff changeset
5 ;; Author: rms@gnu.org
3977
bb696888ccb7 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 3976
diff changeset
6 ;; Maintainer: FSF
bb696888ccb7 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 3976
diff changeset
7 ;; Keywords: languages, faces
3976
87addb9e55f8 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 3919
diff changeset
8
3912
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 ;; any later version.
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19 ;; GNU General Public License for more details.
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13805
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13805
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13805
diff changeset
24 ;; Boston, MA 02111-1307, USA.
3912
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26 ;;; Commentary:
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27
39979
b2ccc516d0dd Update the Commentary with installation instructions.
Eli Zaretskii <eliz@gnu.org>
parents: 38412
diff changeset
28 ;; Put this into your ~/.emacs:
b2ccc516d0dd Update the Commentary with installation instructions.
Eli Zaretskii <eliz@gnu.org>
parents: 38412
diff changeset
29
b2ccc516d0dd Update the Commentary with installation instructions.
Eli Zaretskii <eliz@gnu.org>
parents: 38412
diff changeset
30 ;; (show-paren-mode t)
b2ccc516d0dd Update the Commentary with installation instructions.
Eli Zaretskii <eliz@gnu.org>
parents: 38412
diff changeset
31
b2ccc516d0dd Update the Commentary with installation instructions.
Eli Zaretskii <eliz@gnu.org>
parents: 38412
diff changeset
32 ;; 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
33 ;; before or after point.
3912
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 ;;; Code:
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36
18330
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
37 (defgroup paren-showing nil
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
38 "Showing (un)matching of parens and expressions."
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
39 :prefix "show-paren-"
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
40 :group 'paren-matching)
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
41
4123
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
42 ;; This is the overlay used to highlight the matching paren.
3917
00ea0fc45685 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 3913
diff changeset
43 (defvar show-paren-overlay nil)
14706
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
44 ;; 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
45 (defvar show-paren-overlay-1 nil)
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
46
18330
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
47 (defcustom show-paren-style 'parenthesis
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
48 "*Style used when showing a matching paren.
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
49 Valid styles are `parenthesis' (meaning show the matching paren),
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
50 `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
51 `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
52 otherwise)."
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
53 :type '(choice (const parenthesis) (const expression) (const mixed))
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
54 :group 'paren-showing)
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
55
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
56 (defcustom show-paren-delay
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
57 (if (featurep 'lisp-float-type) (/ (float 1) (float 8)) 1)
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
58 "*Time in seconds to delay before showing a matching paren."
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
59 :type '(number :tag "seconds")
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
60 :group 'paren-showing)
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
61
30787
efa4d1ed3f1b (show-paren-priority): New user option.
Gerd Moellmann <gerd@gnu.org>
parents: 25813
diff changeset
62 (defcustom show-paren-priority 1000
efa4d1ed3f1b (show-paren-priority): New user option.
Gerd Moellmann <gerd@gnu.org>
parents: 25813
diff changeset
63 "*Priority of paren highlighting overlays."
efa4d1ed3f1b (show-paren-priority): New user option.
Gerd Moellmann <gerd@gnu.org>
parents: 25813
diff changeset
64 :type 'integer
efa4d1ed3f1b (show-paren-priority): New user option.
Gerd Moellmann <gerd@gnu.org>
parents: 25813
diff changeset
65 :group 'paren-showing
efa4d1ed3f1b (show-paren-priority): New user option.
Gerd Moellmann <gerd@gnu.org>
parents: 25813
diff changeset
66 :version "21.1")
efa4d1ed3f1b (show-paren-priority): New user option.
Gerd Moellmann <gerd@gnu.org>
parents: 25813
diff changeset
67
21891
7d49e4c824b6 (show-paren-ring-bell-on-mismatch): New option.
Richard M. Stallman <rms@gnu.org>
parents: 18837
diff changeset
68 (defcustom show-paren-ring-bell-on-mismatch nil
7d49e4c824b6 (show-paren-ring-bell-on-mismatch): New option.
Richard M. Stallman <rms@gnu.org>
parents: 18837
diff changeset
69 "*If non-nil, beep if mismatched paren is detected."
7d49e4c824b6 (show-paren-ring-bell-on-mismatch): New option.
Richard M. Stallman <rms@gnu.org>
parents: 18837
diff changeset
70 :type 'boolean
7d49e4c824b6 (show-paren-ring-bell-on-mismatch): New option.
Richard M. Stallman <rms@gnu.org>
parents: 18837
diff changeset
71 :group 'paren-showing
7d49e4c824b6 (show-paren-ring-bell-on-mismatch): New option.
Richard M. Stallman <rms@gnu.org>
parents: 18837
diff changeset
72 :version "20.3")
7d49e4c824b6 (show-paren-ring-bell-on-mismatch): New option.
Richard M. Stallman <rms@gnu.org>
parents: 18837
diff changeset
73
18330
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
74 (defface show-paren-match-face
40794
3ab0eeb4df95 (show-paren-match-face): Add dark-background variant.
Miles Bader <miles@gnu.org>
parents: 39979
diff changeset
75 '((((class color) (background light))
3ab0eeb4df95 (show-paren-match-face): Add dark-background variant.
Miles Bader <miles@gnu.org>
parents: 39979
diff changeset
76 :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
77 (((class color) (background dark))
3ab0eeb4df95 (show-paren-match-face): Add dark-background variant.
Miles Bader <miles@gnu.org>
parents: 39979
diff changeset
78 :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
79 (((background dark))
3ab0eeb4df95 (show-paren-match-face): Add dark-background variant.
Miles Bader <miles@gnu.org>
parents: 39979
diff changeset
80 :background "grey50")
3ab0eeb4df95 (show-paren-match-face): Add dark-background variant.
Miles Bader <miles@gnu.org>
parents: 39979
diff changeset
81 (t
3ab0eeb4df95 (show-paren-match-face): Add dark-background variant.
Miles Bader <miles@gnu.org>
parents: 39979
diff changeset
82 :background "gray"))
18330
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
83 "Show Paren mode face used for a matching paren."
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
84 :group 'faces
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
85 :group 'paren-showing)
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
86
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
87 (defface show-paren-mismatch-face
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
88 '((((class color)) (:foreground "white" :background "purple"))
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
89 (t (:reverse-video t)))
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
90 "Show Paren mode face used for a mismatching paren."
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
91 :group 'faces
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
92 :group 'paren-showing)
4183
a5f0a739d87d (show-paren-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 4123
diff changeset
93
18582
fd88d8f82bbc (show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents: 18567
diff changeset
94 (defvar show-paren-idle-timer nil)
fd88d8f82bbc (show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents: 18567
diff changeset
95
fd88d8f82bbc (show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents: 18567
diff changeset
96 ;;;###autoload
31976
236a7f6d898d (show-paren-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30787
diff changeset
97 (define-minor-mode show-paren-mode
18582
fd88d8f82bbc (show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents: 18567
diff changeset
98 "Toggle Show Paren mode.
fd88d8f82bbc (show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents: 18567
diff changeset
99 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
100 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
101
fd88d8f82bbc (show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents: 18567
diff changeset
102 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
103 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
104 :global t :group 'paren-showing
25275
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
105 ;; Turn off the usual paren-matching method
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
106 ;; when this one is turned on.
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
107 (if (local-variable-p 'show-paren-mode)
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
108 (make-local-variable 'blink-matching-paren-on-screen)
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
109 (kill-local-variable 'blink-matching-paren-on-screen))
31976
236a7f6d898d (show-paren-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30787
diff changeset
110 (setq blink-matching-paren-on-screen (not show-paren-mode))
25275
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
111
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
112 ;; Now enable or disable the mechanism.
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
113 ;; 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
114 (if show-paren-idle-timer
18582
fd88d8f82bbc (show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents: 18567
diff changeset
115 (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
116 (setq show-paren-idle-timer nil)
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
117 ;; 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
118 ;; set up a new timer.
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
119 (when (memq t (mapcar (lambda (buffer)
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
120 (with-current-buffer buffer
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
121 show-paren-mode))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
122 (buffer-list)))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
123 (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
124 show-paren-delay t
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
125 'show-paren-function)))
31976
236a7f6d898d (show-paren-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30787
diff changeset
126 (unless show-paren-mode
25275
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
127 (and show-paren-overlay
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
128 (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
129 (delete-overlay show-paren-overlay))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
130 (and show-paren-overlay-1
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-1) (current-buffer))
31976
236a7f6d898d (show-paren-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30787
diff changeset
132 (delete-overlay show-paren-overlay-1))))
18582
fd88d8f82bbc (show-paren-idle-timer): New defvar.
Richard M. Stallman <rms@gnu.org>
parents: 18567
diff changeset
133
3917
00ea0fc45685 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 3913
diff changeset
134 ;; Find the place to show, if there is one,
00ea0fc45685 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 3913
diff changeset
135 ;; and show it until input arrives.
14706
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
136 (defun show-paren-function ()
25275
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
137 (if show-paren-mode
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
138 (let (pos dir mismatch face (oldpos (point)))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
139 (cond ((eq (char-syntax (preceding-char)) ?\))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
140 (setq dir -1))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
141 ((eq (char-syntax (following-char)) ?\()
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
142 (setq dir 1)))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
143 ;;
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
144 ;; 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
145 (when dir
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
146 (save-excursion
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
147 (save-restriction
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
148 ;; 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
149 (when blink-matching-paren-distance
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
150 (narrow-to-region
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
151 (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
152 (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
153 ;; 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
154 ;; 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
155 (condition-case ()
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
156 (setq pos (scan-sexps (point) dir))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
157 (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
158 ;; 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
159 ;; 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
160 ;; 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
161 (when (integerp pos)
78c2427665f0 (show-paren-function): Move back in other direction
Richard M. Stallman <rms@gnu.org>
parents: 40794
diff changeset
162 (unless (condition-case ()
78c2427665f0 (show-paren-function): Move back in other direction
Richard M. Stallman <rms@gnu.org>
parents: 40794
diff changeset
163 (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
164 (error nil))
78c2427665f0 (show-paren-function): Move back in other direction
Richard M. Stallman <rms@gnu.org>
parents: 40794
diff changeset
165 (setq pos nil)))
25275
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
166 ;; 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
167 ;; 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
168 (when (integerp pos)
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
169 (let ((beg (min pos oldpos)) (end (max pos oldpos)))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
170 (when (/= (char-syntax (char-after beg)) ?\$)
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
171 (setq mismatch
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
172 (not (eq (char-before end)
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
173 ;; This can give nil.
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
174 (matching-paren (char-after beg)))))))))))
18330
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
175 ;;
25275
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
176 ;; 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
177 (if (not pos)
21891
7d49e4c824b6 (show-paren-ring-bell-on-mismatch): New option.
Richard M. Stallman <rms@gnu.org>
parents: 18837
diff changeset
178 (progn
25275
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
179 ;; 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
180 ;; turn off any previous paren highlighting.
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
181 (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
182 (delete-overlay show-paren-overlay))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
183 (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
184 (delete-overlay show-paren-overlay-1)))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
185 ;;
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
186 ;; Use the correct face.
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
187 (if mismatch
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
188 (progn
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
189 (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
190 (beep))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
191 (setq face 'show-paren-mismatch-face))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
192 (setq face 'show-paren-match-face))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
193 ;;
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
194 ;; If matching backwards, highlight the closeparen
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
195 ;; 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
196 ;; 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
197 ;; 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
198 ;; Otherwise, turn off any such highlighting.
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
199 (if (and (= dir 1) (integerp pos))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
200 (when (and show-paren-overlay-1
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
201 (overlay-buffer show-paren-overlay-1))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
202 (delete-overlay show-paren-overlay-1))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
203 (let ((from (if (= dir 1)
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
204 (point)
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
205 (forward-point -1)))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
206 (to (if (= dir 1)
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
207 (forward-point 1)
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
208 (point))))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
209 (if show-paren-overlay-1
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
210 (move-overlay show-paren-overlay-1 from to (current-buffer))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
211 (setq show-paren-overlay-1 (make-overlay from to)))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
212 ;; 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
213 (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
214 (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
215 ;;
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
216 ;; 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
217 ;; 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
218 (unless (integerp pos)
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
219 (delete-overlay show-paren-overlay))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
220 (let ((to (if (or (eq show-paren-style 'expression)
18330
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
221 (and (eq show-paren-style 'mixed)
005facba9434 customise, rewrite and extend.
Simon Marshall <simon@gnu.org>
parents: 18318
diff changeset
222 (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
223 (point)
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
224 pos))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
225 (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
226 (and (eq show-paren-style 'mixed)
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
227 (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
228 pos
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
229 (save-excursion
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
230 (goto-char pos)
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
231 (forward-point (- dir))))))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
232 (if show-paren-overlay
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
233 (move-overlay show-paren-overlay from to (current-buffer))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
234 (setq show-paren-overlay (make-overlay from to))))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
235 ;;
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
236 ;; 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
237 (overlay-put show-paren-overlay 'priority show-paren-priority)
25275
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
238 (overlay-put show-paren-overlay 'face face)))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
239 ;; 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
240 (and show-paren-overlay
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
241 (delete-overlay show-paren-overlay))
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
242 (and show-paren-overlay-1
1b1edbd429ea (show-paren-mode): Support making show-paren-mode
Karl Heuer <kwzh@gnu.org>
parents: 24650
diff changeset
243 (delete-overlay show-paren-overlay-1))))
3912
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244
3919
bbac27613cee *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 3917
diff changeset
245 (provide 'paren)
bbac27613cee *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 3917
diff changeset
246
bbac27613cee *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 3917
diff changeset
247 ;;; paren.el ends here