annotate lisp/paren.el @ 16189:b41f7cd8f5b3 libc-960918 libc-960919 libc-960920 libc-960921 libc-960922 libc-960923

RMS: Use pc instead of unknown, for pc clones. Use -linux-gnu for Linux-based GNU systems.
author Richard Kenner <kenner@gnu.org>
date Sun, 15 Sep 1996 00:49:22 +0000
parents 11dadc34fd9a
children 3db0adbc5367
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3912
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 ;;; paren.el --- highlight matching paren.
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13805
diff changeset
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
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4
3977
bb696888ccb7 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 3976
diff changeset
5 ;; Author: rms@gnu.ai.mit.edu
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
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28 ;; Load this and it will display highlighting on whatever
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 ;; paren matches the one before or after point.
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 ;;; Code:
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32
4123
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
33 ;; This is the overlay used to highlight the matching paren.
3917
00ea0fc45685 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 3913
diff changeset
34 (defvar show-paren-overlay nil)
14706
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
35 ;; 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
36 (defvar show-paren-overlay-1 nil)
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
37
14706
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
38 (defvar show-paren-mode nil)
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
39 (defvar show-paren-idle-timer nil)
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
40
4123
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
41 (defvar show-paren-mismatch-face nil)
3912
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42
14706
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
43 (defvar show-paren-delay (if (featurep 'lisp-float-type) 0.125 1)
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
44 "*Time in seconds to delay before showing the matching paren.")
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
45
4183
a5f0a739d87d (show-paren-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 4123
diff changeset
46 (defvar show-paren-face 'region
14706
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
47 "*Name of the face to use for showing the matching paren.")
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
48
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
49 ;;;###autoload
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
50 (defun show-paren-mode (&optional arg)
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
51 "Toggle Show Paren mode.
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
52 With prefix ARG, turn Show Paren mode on if and only if ARG is positive.
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
53 Returns the new status of Show Paren mode (non-nil means on).
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
54
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
55 When Show Paren mode is enabled, any matching parenthesis is highlighted
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
56 after `show-paren-delay' seconds of Emacs idle time."
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
57 (interactive "P")
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
58 (if window-system
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
59 (let ((on-p (if arg
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
60 (> (prefix-numeric-value arg) 0)
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
61 (not show-paren-mode))))
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
62 (setq blink-matching-paren-on-screen (not on-p))
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
63 (and show-paren-idle-timer (cancel-timer show-paren-idle-timer))
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
64 (if on-p
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
65 (setq show-paren-idle-timer (run-with-idle-timer show-paren-delay t
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
66 'show-paren-function))
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
67 (and show-paren-overlay (overlay-buffer show-paren-overlay)
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
68 (delete-overlay show-paren-overlay))
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
69 (and show-paren-overlay-1 (overlay-buffer show-paren-overlay-1)
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
70 (delete-overlay show-paren-overlay-1)))
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
71 (setq show-paren-mode on-p))))
4183
a5f0a739d87d (show-paren-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 4123
diff changeset
72
3917
00ea0fc45685 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 3913
diff changeset
73 ;; Find the place to show, if there is one,
00ea0fc45685 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 3913
diff changeset
74 ;; and show it until input arrives.
14706
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
75 (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
76 ;; 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
77 ;; 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
78 ;; Do nothing if input is pending.
12918
88c1220e3dec Use post-command-idle-hook.
Richard M. Stallman <rms@gnu.org>
parents: 12871
diff changeset
79 (if window-system
4059
66d33e1bf65b (show-paren-command-hook): Do nothing if not window-system.
Richard M. Stallman <rms@gnu.org>
parents: 3977
diff changeset
80 (let (pos dir mismatch (oldpos (point))
4183
a5f0a739d87d (show-paren-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 4123
diff changeset
81 (face show-paren-face))
8022
fcf805b27bc5 (show-paren-command-hook): Handle close paren rather than open paren
Richard M. Stallman <rms@gnu.org>
parents: 8019
diff changeset
82 (cond ((eq (char-syntax (preceding-char)) ?\))
fcf805b27bc5 (show-paren-command-hook): Handle close paren rather than open paren
Richard M. Stallman <rms@gnu.org>
parents: 8019
diff changeset
83 (setq dir -1))
fcf805b27bc5 (show-paren-command-hook): Handle close paren rather than open paren
Richard M. Stallman <rms@gnu.org>
parents: 8019
diff changeset
84 ((eq (char-syntax (following-char)) ?\()
fcf805b27bc5 (show-paren-command-hook): Handle close paren rather than open paren
Richard M. Stallman <rms@gnu.org>
parents: 8019
diff changeset
85 (setq dir 1)))
4123
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
86 (if dir
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
87 (save-excursion
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
88 (save-restriction
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
89 ;; Determine the range within which to look for a match.
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
90 (if blink-matching-paren-distance
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
91 (narrow-to-region (max (point-min)
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
92 (- (point) blink-matching-paren-distance))
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
93 (min (point-max)
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
94 (+ (point) blink-matching-paren-distance))))
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
95 ;; Scan across one sexp within that range.
16080
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
96 ;; Errors or nil mean there is a mismatch.
4123
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
97 (condition-case ()
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
98 (setq pos (scan-sexps (point) dir))
16080
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
99 (error (setq pos t
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
100 mismatch t)))
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
101 ;; If found a "matching" paren, see if it is the right
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
102 ;; kind of paren to match the one we started at.
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
103 (if (integerp pos)
4123
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
104 (let ((beg (min pos oldpos)) (end (max pos oldpos)))
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
105 (and (/= (char-syntax (char-after beg)) ?\$)
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
106 (setq mismatch
8510
8903669537b0 (show-paren-command-hook): Cope if matching-paren gives nil.
Richard M. Stallman <rms@gnu.org>
parents: 8050
diff changeset
107 (not (eq (char-after (1- end))
8903669537b0 (show-paren-command-hook): Cope if matching-paren gives nil.
Richard M. Stallman <rms@gnu.org>
parents: 8050
diff changeset
108 ;; This can give nil.
8903669537b0 (show-paren-command-hook): Cope if matching-paren gives nil.
Richard M. Stallman <rms@gnu.org>
parents: 8050
diff changeset
109 (matching-paren (char-after beg))))))))
4123
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
110 ;; If they don't properly match, use a different face,
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
111 ;; or print a message.
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
112 (if mismatch
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
113 (progn
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
114 (and (null show-paren-mismatch-face)
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
115 (x-display-color-p)
10380
6bf5b024dffb (show-paren-command-hook): Don't alter paren-mismatch face
Richard M. Stallman <rms@gnu.org>
parents: 8558
diff changeset
116 (progn
13492
24b73b514a8b (show-paren-command-hook): Don't list `paren-mismatch'
Karl Heuer <kwzh@gnu.org>
parents: 12918
diff changeset
117 (add-to-list 'facemenu-unlisted-faces
24b73b514a8b (show-paren-command-hook): Don't list `paren-mismatch'
Karl Heuer <kwzh@gnu.org>
parents: 12918
diff changeset
118 'paren-mismatch)
10380
6bf5b024dffb (show-paren-command-hook): Don't alter paren-mismatch face
Richard M. Stallman <rms@gnu.org>
parents: 8558
diff changeset
119 (make-face 'paren-mismatch)
6bf5b024dffb (show-paren-command-hook): Don't alter paren-mismatch face
Richard M. Stallman <rms@gnu.org>
parents: 8558
diff changeset
120 (or (face-nontrivial-p 'paren-mismatch t)
6bf5b024dffb (show-paren-command-hook): Don't alter paren-mismatch face
Richard M. Stallman <rms@gnu.org>
parents: 8558
diff changeset
121 (progn
6bf5b024dffb (show-paren-command-hook): Don't alter paren-mismatch face
Richard M. Stallman <rms@gnu.org>
parents: 8558
diff changeset
122 (set-face-background 'paren-mismatch
6bf5b024dffb (show-paren-command-hook): Don't alter paren-mismatch face
Richard M. Stallman <rms@gnu.org>
parents: 8558
diff changeset
123 "purple")
6bf5b024dffb (show-paren-command-hook): Don't alter paren-mismatch face
Richard M. Stallman <rms@gnu.org>
parents: 8558
diff changeset
124 (set-face-foreground 'paren-mismatch
6bf5b024dffb (show-paren-command-hook): Don't alter paren-mismatch face
Richard M. Stallman <rms@gnu.org>
parents: 8558
diff changeset
125 "white")))
6bf5b024dffb (show-paren-command-hook): Don't alter paren-mismatch face
Richard M. Stallman <rms@gnu.org>
parents: 8558
diff changeset
126 (setq show-paren-mismatch-face 'paren-mismatch)))
4123
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
127 (if show-paren-mismatch-face
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
128 (setq face show-paren-mismatch-face)
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
129 (message "Paren mismatch"))))
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
130 )))
4059
66d33e1bf65b (show-paren-command-hook): Do nothing if not window-system.
Richard M. Stallman <rms@gnu.org>
parents: 3977
diff changeset
131 (cond (pos
16080
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
132 (if (or (= dir -1)
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
133 (not (integerp pos)))
4123
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
134 ;; If matching backwards, highlight the closeparen
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
135 ;; before point as well as its matching open.
16080
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
136 ;; If matching forward, and the openparen is unbalanced,
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
137 ;; highlight the paren at point to indicate misbalance.
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
138 (let ((from (if (= dir 1)
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
139 (point)
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
140 (1- (point))))
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
141 (to (if (= dir 1)
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
142 (1+ (point))
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
143 (point))))
4123
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
144 (if show-paren-overlay-1
4353
d4e116f25030 (show-paren-command-hook): Specify buffer for move-overay.
Richard M. Stallman <rms@gnu.org>
parents: 4183
diff changeset
145 (move-overlay show-paren-overlay-1
16080
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
146 from to
4353
d4e116f25030 (show-paren-command-hook): Specify buffer for move-overay.
Richard M. Stallman <rms@gnu.org>
parents: 4183
diff changeset
147 (current-buffer))
4123
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
148 (setq show-paren-overlay-1
16080
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
149 (make-overlay from to)))
8558
30f91aa9b364 (show-paren-command-hook): Set the face of an overlay
Richard M. Stallman <rms@gnu.org>
parents: 8510
diff changeset
150 ;; Always set the overlay face, since it varies.
30f91aa9b364 (show-paren-command-hook): Set the face of an overlay
Richard M. Stallman <rms@gnu.org>
parents: 8510
diff changeset
151 (overlay-put show-paren-overlay-1 'face face))
4123
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
152 ;; Otherwise, turn off any such highlighting.
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
153 (and show-paren-overlay-1
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
154 (overlay-buffer show-paren-overlay-1)
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
155 (delete-overlay show-paren-overlay-1)))
16080
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
156 ;; Turn on highlighting for the matching paren, if found.
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
157 ;; If it's an unmatched paren, turn off any such highlighting.
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
158 (or (and (not (integerp pos))
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
159 (delete-overlay show-paren-overlay))
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
160 (if show-paren-overlay
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
161 (move-overlay show-paren-overlay (- pos dir) pos
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
162 (current-buffer))
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
163 (setq show-paren-overlay
11dadc34fd9a (show-paren-function): Handle unbalanced parens as
Richard M. Stallman <rms@gnu.org>
parents: 14709
diff changeset
164 (make-overlay (- pos dir) pos))))
8558
30f91aa9b364 (show-paren-command-hook): Set the face of an overlay
Richard M. Stallman <rms@gnu.org>
parents: 8510
diff changeset
165 ;; Always set the overlay face, since it varies.
30f91aa9b364 (show-paren-command-hook): Set the face of an overlay
Richard M. Stallman <rms@gnu.org>
parents: 8510
diff changeset
166 (overlay-put show-paren-overlay 'face face))
4059
66d33e1bf65b (show-paren-command-hook): Do nothing if not window-system.
Richard M. Stallman <rms@gnu.org>
parents: 3977
diff changeset
167 (t
4123
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
168 ;; If not at a paren that has a match,
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
169 ;; turn off any previous paren highlighting.
4059
66d33e1bf65b (show-paren-command-hook): Do nothing if not window-system.
Richard M. Stallman <rms@gnu.org>
parents: 3977
diff changeset
170 (and show-paren-overlay (overlay-buffer show-paren-overlay)
4123
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
171 (delete-overlay show-paren-overlay))
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
172 (and show-paren-overlay-1 (overlay-buffer show-paren-overlay-1)
b05c50e08993 Enable the hook only if window-system.
Richard M. Stallman <rms@gnu.org>
parents: 4059
diff changeset
173 (delete-overlay show-paren-overlay-1)))))))
3912
676fb29d1692 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174
14706
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
175 ;;; For back compatibility we turn ourselves on if we're dumped or loaded.
14709
ed8972248721 Don't toggle on window-setup-hook.
Simon Marshall <simon@gnu.org>
parents: 14706
diff changeset
176 (add-hook 'window-setup-hook '(lambda () (show-paren-mode t)))
14706
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
177 (show-paren-mode t)
e7352445b396 (show-paren-delay): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14624
diff changeset
178
3919
bbac27613cee *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 3917
diff changeset
179 (provide 'paren)
bbac27613cee *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 3917
diff changeset
180
bbac27613cee *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 3917
diff changeset
181 ;;; paren.el ends here