annotate lisp/packages/mic-paren.el @ 28:1917ad0d78d7 r19-15b97

Import from CVS: tag r19-15b97
author cvs
date Mon, 13 Aug 2007 08:51:55 +0200
parents 441bb1e64a06
children ec9a17fef872
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
1 ;;; mic-paren.el --- highlight matching parenthesises.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
2 ;;; Version 1.3.1 - 97-02-27
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
3 ;;; Copyright (C) 1997 Mikael Sjödin (mic@docs.uu.se)
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
4 ;;;
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 12
diff changeset
5 ;;; Author: Mikael Sjödin -- mic@docs.uu.se
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
6 ;;; Additional code by: Vinicius Jose Latorre <vinicius@cpqd.br>
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
7 ;;; Steven L Baur <steve@altair.xemacs.org>
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
8 ;;;
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
9 ;;; Keywords: languages, faces
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
10 ;;;
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
11 ;;; This file is NOT part of GNU Emacs.
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
12 ;;; You may however redistribute it and/or modify it under the terms of the GNU
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
13 ;;; General Public License as published by the Free Software Foundation; either
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
14 ;;; version 2, or (at your option) any later version.
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
15 ;;;
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
16 ;;; mic-paren is distributed in the hope that it will be useful,
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
17 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
18 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
19 ;;; GNU General Public License for more details.
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
20
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
21 ;;; ----------------------------------------------------------------------
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
22 ;;; Short Description:
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
23 ;;;
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
24 ;;; Load this file and Emacs will display highlighting on whatever
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
25 ;;; parenthesis matches the one before or after point. This is an extension to
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
26 ;;; the paren.el file distributed with Emacs. The default behaviour is similar
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
27 ;;; to paren.el but try the authors favourite options:
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
28 ;;; (setq paren-face 'bold)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
29 ;;; (setq paren-sexp-mode t)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
30
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
31 ;;; ----------------------------------------------------------------------
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
32 ;;; Installation:
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
33 ;;;
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
34 ;;; o Place this file in a directory in your 'load-path.
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
35 ;;; o Put the following in your .emacs file:
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
36 ;;; (if window-system
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
37 ;;; (require 'mic-paren))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
38 ;;; o Restart your Emacs. mic-paren is now installed and activated!
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
39 ;;; o To list the possible customisation enter `C-h f paren-activate'
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
40 ;;;
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
41
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
42 ;;; ----------------------------------------------------------------------
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
43 ;;; Long Description:
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
44 ;;;
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
45 ;;; mic-paren.el is an extension to the packages paren.el and stig-paren.el for
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
46 ;;; Emacs. When mic-paren is active (it is activated when loaded) Emacs normal
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
47 ;;; parenthesis matching is deactivated. Instead parenthesis matching will be
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
48 ;;; performed as soon as the cursor is positioned at a parenthesis. The
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
49 ;;; matching parenthesis (or the entire expression between the parenthesises)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
50 ;;; is highlighted until the cursor is moved away from the parenthesis.
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
51 ;;; Features include:
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 6
diff changeset
52 ;;; o Both forward and backward parenthesis matching (simultaneously if
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
53 ;;; cursor is between two expressions).
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
54 ;;; o Indication of mismatched parenthesises.
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 6
diff changeset
55 ;;; o Recognition of "escaped" parenthesises.
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
56 ;;; o Option to select if only the matching parenthesis or the entire
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
57 ;;; expression should be highlighted.
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
58 ;;; o Message describing the match when the matching parenthesis is
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
59 ;;; off-screen.
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
60 ;;; o Optional delayed highlighting (useful on slow systems),
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
61 ;;; o Functions to activate/deactivate mic-paren.el is provided.
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
62 ;;; o Numerous options to control the behaviour and appearance of
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
63 ;;; mic-paren.el.
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
64 ;;;
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 6
diff changeset
65 ;;; mic-paren.el is developed and tested under Emacs 19.28 - 19.34. It should
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 6
diff changeset
66 ;;; work on earlier and forthcoming Emacs versions. XEmacs compatibility has
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
67 ;;; been provided by Steven L Baur <steve@altair.xemacs.org>. Jan Dubois
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
68 ;;; (jaduboi@ibm.net) provided help to get mic-paren to work in OS/2.
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
69 ;;;
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
70 ;;; This file can be obtained from http://www.docs.uu.se/~mic/emacs.html
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
71
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
72 ;;; ----------------------------------------------------------------------
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
73 ;;; Versions:
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
74 ;;;
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
75 ;;; v1.3.1 Some spelling corrected (from Vinicius Jose Latorre
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
76 ;;; <vinicius@cpqd.br> and Steven L Baur <steve@altair.xemacs.org>)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
77 ;;;
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
78 ;;; v1.3 Added code from Vinicius Jose Latorre <vinicius@cpqd.br> to
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
79 ;;; highlight unmathced parenthesises (useful in minibuffer)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
80 ;;;
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
81 ;;; v1.2.1 Fixed stuff to work with OS/2 emx-emacs
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
82 ;;; - checks if x-display-color-p is bound before calling it
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
83 ;;; - changed how X/Lucid Emacs is deteced
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
84 ;;; Added automatic load of the timer-feature (+ variable to disable
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
85 ;;; the loading)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
86
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
87 ;;; ======================================================================
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
88 ;;; User Options:
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
89
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
90 (defvar paren-priority nil
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
91 "*Defines the behaviour of mic-paren when point is between a closing and an
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
92 opening parenthesis.
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
93
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
94 A value of 'close means highlight the parenthesis matching the
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
95 close-parenthesis before the point.
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
96
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
97 A value of 'open means highlight the parenthesis matching the open-parenthesis
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
98 after the point.
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
99
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
100 Any other value means highlight both parenthesis matching the parenthesis
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
101 beside the point.")
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
102
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
103
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
104 ;;; ------------------------------
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
105
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
106 (defvar paren-sexp-mode nil
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
107 "*If nil only the matching parenthesis is highlighted.
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
108 If non-nil the whole s-expression between the matching parenthesis is
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
109 highlighted.")
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
110
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
111 ;;; ------------------------------
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
112
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
113 (defvar paren-highlight-at-point t
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
114 "*If non-nil and point is after a close parenthesis, both the close and
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
115 open parenthesis is highlighted. If nil, only the open parenthesis is
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
116 highlighted.")
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
117
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
118 ;;; ------------------------------
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
119
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
120 (defvar paren-highlight-offscreen nil
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
121 "*If non-nil stig-paren will highlight text which is not visible in the
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
122 current buffer.
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
123
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
124 This is useful if you regularly display the current buffer in multiple windows
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
125 or frames. For instance if you use follow-mode (by andersl@csd.uu.se), however
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
126 it may slow down your Emacs.
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
127
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
128 (This variable is ignored (treated as non-nil) if you set paren-sexp-mode to
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
129 non-nil.)")
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
130
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
131 ;;; ------------------------------
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
132
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
133 (defvar paren-message-offscreen t
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
134 "*Display message if matching parenthesis is off-screen.")
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
135
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
136 ;;; ------------------------------
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
137
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
138 (defvar paren-message-no-match t
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
139 "*Display message if no matching parenthesis is found.")
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
140
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
141 ;;; ------------------------------
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
142
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
143 (defvar paren-ding-unmatched nil
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
144 "*Make noise if the cursor is at an unmatched parenthesis or no matching
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
145 parenthesis is found.
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
146
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
147 Even if nil, typing an unmatched parenthesis produces a ding.")
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
148
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
149 ;;; ------------------------------
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
150
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
151 (defvar paren-delay nil
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
152 "*This variable controls when highlighting is done. The variable has
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
153 different meaning in different versions of Emacs.
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
154
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
155 In Emacs 19.29 and below:
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
156 This variable is ignored.
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
157
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
158 In Emacs 19.30:
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
159 A value of nil will make highlighting happen immediately (this may slow down
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
160 your Emacs if running on a slow system). Any non-nil value will delay
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
161 highlighting for the time specified by post-command-idle-delay.
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
162
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
163 In Emacs 19.31 and above:
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
164 A value of nil will make highlighting happen immediately (this may slow down
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
165 your Emacs if running on a slow system). If not nil, the value should be a
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
166 number (possible a floating point number if your Emacs support floating point
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
167 numbers). The number is the delay before mic-paren performs highlighting.
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
168
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
169 If you change this variable when mic-paren is active you have to re-activate
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
170 (with M-x paren-activate) mic-paren for the change to take effect.")
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
171
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
172
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
173 ;;; ------------------------------
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
174
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
175 (defvar paren-dont-touch-blink nil
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
176 "*If non-nil mic-paren will not change the value of blink-matching-paren when
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
177 activated of deactivated.
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
178
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
179 If nil mic-paren turns of blinking when activated and turns on blinking when
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
180 deactivated.")
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
181
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
182 ;;; ------------------------------
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
183
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
184 (defvar paren-dont-activate-on-load nil
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
185 "*If non-nil mic-paren will not activate itself when loaded.")
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
186
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
187 ;;; ------------------------------
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
188
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
189 (defvar paren-dont-load-timer (not (string-match "XEmacs\\|Lucid"
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
190 emacs-version))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
191 "*If non-nil mic-paren will not try to load the timer-feature when loaded.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
192
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
193 (I have no idea why Emacs user ever want to set this to non-nil but I hate
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
194 packages which loads/activates stuff I don't want to use so I provide this way
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
195 to prevent the loading if someone doesn't want timers to be loaded.)")
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
196
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
197 ;;; ------------------------------
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
198
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
199 (defvar paren-face (if (and (fboundp 'x-display-color-p)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
200 (x-display-color-p))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
201 'highlight 'underline)
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
202 "*Face to use for showing the matching parenthesis.")
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
203
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
204 ;;; ------------------------------
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
205
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
206 (defvar paren-mismatch-face (if (and (fboundp 'x-display-color-p)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
207 (x-display-color-p))
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
208 (let ((fn 'paren-mismatch-face))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
209 (copy-face 'default fn)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
210 (set-face-background fn "DeepPink")
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
211 fn)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
212 'modeline)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
213 "*Face to use when highlighting a mismatched parenthesis.")
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
214
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
215 ;;; ------------------------------
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
216
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
217 (defvar paren-no-match-face (if (x-display-color-p)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
218 (let ((fn 'paren-no-match-face))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
219 (copy-face 'default fn)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
220 (set-face-background fn "yellow")
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
221 fn)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
222 'default)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
223 "*Face to use when highlighting an unmatched parenthesis.")
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
224
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
225 ;;; ======================================================================
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
226 ;;; User Functions:
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
227
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
228 ;; XEmacs compatibility (mainly by Steven L Baur <steve@altair.xemacs.org>)
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
229 (eval-and-compile
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
230 (if (string-match "\\(Lucid\\|XEmacs\\)" emacs-version)
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
231 (progn
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
232 (fset 'mic-make-overlay 'make-extent)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
233 (fset 'mic-delete-overlay 'delete-extent)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
234 (fset 'mic-overlay-put 'set-extent-property)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
235 (defun mic-cancel-timer (timer) (delete-itimer timer))
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
236 (fset 'mic-run-with-idle-timer 'start-itimer)
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
237 )
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
238 (fset 'mic-make-overlay 'make-overlay)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
239 (fset 'mic-delete-overlay 'delete-overlay)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
240 (fset 'mic-overlay-put 'overlay-put)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
241 (fset 'mic-cancel-timer 'cancel-timer)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
242 (fset 'mic-run-with-idle-timer 'run-with-idle-timer)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
243 ))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
244
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
245
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
246 (defun paren-activate ()
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
247 "Activates mic-paren parenthesis highlighting.
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
248 paren-activate deactivates the paren.el and stig-paren.el packages if they are
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
249 active
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
250 Options:
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
251 paren-priority
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
252 paren-sexp-mode
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
253 paren-highlight-at-point
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
254 paren-highlight-offscreen
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
255 paren-message-offscreen
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
256 paren-message-no-match
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
257 paren-ding-unmatched
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
258 paren-delay
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
259 paren-dont-touch-blink
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
260 paren-dont-activate-on-load
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
261 paren-face
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
262 paren-mismatch-face"
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
263 (interactive)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
264 ;; Deactivate mic-paren.el (To remove redundant hooks)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
265 (paren-deactivate)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
266 ;; Deactivate paren.el if loaded
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
267 (if (boundp 'post-command-idle-hook)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
268 (remove-hook 'post-command-idle-hook 'show-paren-command-hook))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
269 (remove-hook 'post-command-hook 'show-paren-command-hook)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
270 (and (boundp 'show-paren-overlay)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
271 show-paren-overlay
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
272 (mic-delete-overlay show-paren-overlay))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
273 (and (boundp 'show-paren-overlay-1)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
274 show-paren-overlay-1
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
275 (mic-delete-overlay show-paren-overlay-1))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
276 ;; Deactivate stig-paren.el if loaded
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
277 (if (boundp 'post-command-idle-hook)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
278 (remove-hook 'post-command-idle-hook 'stig-paren-command-hook))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
279 (remove-hook 'post-command-hook 'stig-paren-command-hook)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
280 (remove-hook 'post-command-hook 'stig-paren-safe-command-hook)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
281 (remove-hook 'pre-command-hook 'stig-paren-delete-overlay)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
282 ;; Deactivate Emacs standard parenthesis blinking
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
283 (or paren-dont-touch-blink
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
284 (setq blink-matching-paren nil))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
285
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 6
diff changeset
286 (cond(
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
287 ;; If timers are available use them
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
288 ;; (Emacs 19.31 and above)
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 6
diff changeset
289 (featurep 'timer)
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 6
diff changeset
290 (if (numberp paren-delay)
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 6
diff changeset
291 (setq mic-paren-idle-timer
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 6
diff changeset
292 (mic-run-with-idle-timer paren-delay t
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 6
diff changeset
293 'mic-paren-command-idle-hook))
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 6
diff changeset
294 (add-hook 'post-command-hook 'mic-paren-command-hook)))
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
295 ;; If the idle hook exists assume it is functioning and use it
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
296 ;; (Emacs 19.30)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
297 ((and (boundp 'post-command-idle-hook)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
298 (boundp 'post-command-idle-delay))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
299 (if paren-delay
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
300 (add-hook 'post-command-idle-hook 'mic-paren-command-idle-hook)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
301 (add-hook 'post-command-hook 'mic-paren-command-hook)))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
302 ;; Check if we (at least) have a post-comand-hook, and use it
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
303 ;; (Emacs 19.29 and below)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
304 ((boundp 'post-command-hook)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
305 (add-hook 'post-command-hook 'mic-paren-command-hook))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
306 ;; Not possible to install mic-paren hooks
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
307 (t (error "Cannot activate mic-paren in this Emacs version"))))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
308
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
309
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
310
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
311 (defun paren-deactivate ()
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
312 "Deactivates mic-paren parenthesis highlighting"
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
313 (interactive)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
314 ;; Deactivate (don't bother to check where/if mic-paren is acivte, just
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
315 ;; delete all possible hooks and timers)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
316 (if (boundp 'post-command-idle-hook)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
317 (remove-hook 'post-command-idle-hook 'mic-paren-command-idle-hook))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
318 (if mic-paren-idle-timer
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
319 (mic-cancel-timer mic-paren-idle-timer))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
320 (remove-hook 'post-command-hook 'mic-paren-command-hook)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
321
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
322 ;; Remove any old highlighs
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
323 (mic-delete-overlay mic-paren-backw-overlay)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
324 (mic-delete-overlay mic-paren-point-overlay)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
325 (mic-delete-overlay mic-paren-forw-overlay)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
326
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
327 ;; Reactivate Emacs standard parenthesis blinking
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
328 (or paren-dont-touch-blink
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
329 (setq blink-matching-paren t))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
330 )
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
331
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
332 ;;; ======================================================================
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
333 ;;; Internal variables:
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
334
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
335 (defvar mic-paren-backw-overlay (mic-make-overlay (point-min) (point-min))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
336 "Overlay for the open-paren which matches the close-paren before
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
337 point. When in sexp-mode this is the overlay for the expression before point.")
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
338
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
339 (defvar mic-paren-point-overlay (mic-make-overlay (point-min) (point-min))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
340 "Overlay for the close-paren before point.
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
341 (Not used when is sexp-mode.)")
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
342
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
343 (defvar mic-paren-forw-overlay (mic-make-overlay (point-min) (point-min))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
344 "Overlay for the close-paren which matches the open-paren after
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
345 point. When in sexp-mode this is the overlay for the expression after point.")
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
346
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
347 (defvar mic-paren-idle-timer nil
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
348 "Idle-timer. Used only in Emacs 19.31 and above (and if paren-delay is nil)")
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
349
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
350
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
351
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
352
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
353 ;;; ======================================================================
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
354 ;;; Internal function:
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
355
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
356
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
357
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
358 (defun mic-paren-command-hook ()
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
359 (or executing-kbd-macro
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
360 (input-pending-p) ;[This might cause trouble since the
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
361 ; function is unreliable]
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
362 (condition-case paren-error
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 12
diff changeset
363 (mic-paren-highlight)
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
364 (error
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
365 (if (not (window-minibuffer-p (selected-window)))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
366 (message "mic-paren catched error (please report): %s"
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
367 paren-error))))))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
368
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
369 (defun mic-paren-command-idle-hook ()
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
370 (condition-case paren-error
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 12
diff changeset
371 (mic-paren-highlight)
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
372 (error
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
373 (if (not (window-minibuffer-p (selected-window)))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
374 (message "mic-paren catched error (please report): %s"
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
375 paren-error)))))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
376
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
377
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 12
diff changeset
378 (defun mic-paren-highlight ()
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
379 "The main-function of mic-paren. Does all highlighting, dinging, messages,
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
380 cleaning-up."
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
381 ;; Remove any old highlighting
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
382 (mic-delete-overlay mic-paren-forw-overlay)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
383 (mic-delete-overlay mic-paren-point-overlay)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
384 (mic-delete-overlay mic-paren-backw-overlay)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
385
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
386 ;; Handle backward highlighting (when after a close-paren):
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
387 ;; If positioned after a close-paren, and
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
388 ;; not before an open-paren when priority=open, and
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
389 ;; the close-paren is not escaped then
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
390 ;; perform highlighting
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
391 ;; else
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
392 ;; remove any old backward highlights
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
393 (if (and (eq (char-syntax (preceding-char)) ?\))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
394 (not (and (eq (char-syntax (following-char)) ?\()
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
395 (eq paren-priority 'open)))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
396 (paren-evenp (paren-backslashes-before-char (1- (point)))))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
397 (let (open)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
398 ;; Find the position for the open-paren
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
399 (save-excursion
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
400 (save-restriction
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
401 (if blink-matching-paren-distance
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
402 (narrow-to-region
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
403 (max (point-min)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
404 (- (point) blink-matching-paren-distance))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
405 (point-max)))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
406 (condition-case ()
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
407 (setq open (scan-sexps (point) -1))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
408 (error nil))))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
409
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
410 ;; If match found
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
411 ;; highlight expression and/or print messages
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
412 ;; else
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
413 ;; highlight unmatched paren
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
414 ;; print no-match message
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
415 (if open
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
416 (let ((mismatch (/= (matching-paren (preceding-char))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
417 (char-after open)))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
418 (visible (pos-visible-in-window-p open)))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
419 ;; If highlight is appropriate
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 12
diff changeset
420 ;; highlight
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
421 ;; else
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
422 ;; remove any old highlight
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
423 (if (or visible paren-highlight-offscreen paren-sexp-mode)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
424 ;; If sexp-mode
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
425 ;; highlight sexp
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
426 ;; else
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
427 ;; highlight the two parens
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
428 (if paren-sexp-mode
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
429 (progn
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
430 (setq mic-paren-backw-overlay
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
431 (mic-make-overlay open (point)))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
432 (if mismatch
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
433 (mic-overlay-put mic-paren-backw-overlay
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
434 'face paren-mismatch-face)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
435 (mic-overlay-put mic-paren-backw-overlay
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
436 'face paren-face)))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
437 (setq mic-paren-backw-overlay
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
438 (mic-make-overlay open (1+ open)))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
439 (and paren-highlight-at-point
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
440 (setq mic-paren-point-overlay
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
441 (mic-make-overlay (1- (point)) (point))))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
442 (if mismatch
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
443 (progn
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
444 (mic-overlay-put mic-paren-backw-overlay
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
445 'face paren-mismatch-face)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
446 (and paren-highlight-at-point
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
447 (mic-overlay-put mic-paren-point-overlay
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
448 'face paren-mismatch-face)))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
449 (mic-overlay-put mic-paren-backw-overlay
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
450 'face paren-face)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
451 (and paren-highlight-at-point
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
452 (mic-overlay-put mic-paren-point-overlay
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
453 'face paren-face)))))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
454 ;; Print messages if match is offscreen
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
455 (and paren-message-offscreen
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
456 (not visible)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
457 (not (window-minibuffer-p (selected-window)))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
458 (message "%s %s"
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
459 (if mismatch "MISMATCH:" "Matches")
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
460 (mic-paren-get-matching-open-text open)))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
461 ;; Ding if mismatch
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
462 (and mismatch
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
463 paren-ding-unmatched
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
464 (ding)))
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
465 (setq mic-paren-backw-overlay
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
466 (mic-make-overlay (1- (point)) (point)))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
467 (mic-overlay-put mic-paren-backw-overlay
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
468 'face paren-no-match-face)
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
469 (and paren-message-no-match
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
470 (not (window-minibuffer-p (selected-window)))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
471 (message "No opening parenthesis found"))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
472 (and paren-message-no-match
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
473 paren-ding-unmatched
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
474 (ding)))))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
475
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
476 ;; Handle forward highlighting (when before an open-paren):
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
477 ;; If positioned before an open-paren, and
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
478 ;; not after a close-paren when priority=close, and
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
479 ;; the open-paren is not escaped then
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
480 ;; perform highlighting
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
481 ;; else
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
482 ;; remove any old forward highlights
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
483 (if (and (eq (char-syntax (following-char)) ?\()
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
484 (not (and (eq (char-syntax (preceding-char)) ?\))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
485 (eq paren-priority 'close)))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
486 (paren-evenp (paren-backslashes-before-char (point))))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
487 (let (close)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
488 ;; Find the position for the close-paren
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
489 (save-excursion
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
490 (save-restriction
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
491 (if blink-matching-paren-distance
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
492 (narrow-to-region
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
493 (point-min)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
494 (min (point-max)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
495 (+ (point) blink-matching-paren-distance))))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
496 (condition-case ()
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
497 (setq close (scan-sexps (point) 1))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
498 (error nil))))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
499 ;; If match found
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
500 ;; highlight expression and/or print messages
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
501 ;; else
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
502 ;; highlight unmatched paren
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
503 ;; print no-match message
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
504 (if close
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
505 (let ((mismatch (/= (matching-paren (following-char))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
506 (char-after (1- close))))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
507 (visible (pos-visible-in-window-p close)))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
508 ;; If highlight is appropriate
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 12
diff changeset
509 ;; highlight
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
510 ;; else
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
511 ;; remove any old highlight
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
512 (if (or visible paren-highlight-offscreen paren-sexp-mode)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
513 ;; If sexp-mode
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
514 ;; highlight sexp
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
515 ;; else
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
516 ;; highlight the two parens
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
517 (if paren-sexp-mode
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
518 (progn
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
519 (setq mic-paren-forw-overlay
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
520 (mic-make-overlay (point) close))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
521 (if mismatch
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
522 (mic-overlay-put mic-paren-forw-overlay
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
523 'face paren-mismatch-face)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
524 (mic-overlay-put mic-paren-forw-overlay
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
525 'face paren-face)))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
526 (setq mic-paren-forw-overlay
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
527 (mic-make-overlay (1- close) close))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
528 (if mismatch
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
529 (mic-overlay-put mic-paren-forw-overlay
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
530 'face paren-mismatch-face)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
531 (mic-overlay-put mic-paren-forw-overlay
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
532 'face paren-face))))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
533
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
534 ;; Print messages if match is offscreen
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
535 (and paren-message-offscreen
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
536 (not visible)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
537 (not (window-minibuffer-p (selected-window)))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
538 (message "%s %s"
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
539 (if mismatch "MISMATCH:" "Matches")
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
540 (mic-paren-get-matching-close-text close)))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
541 ;; Ding if mismatch
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
542 (and mismatch
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
543 paren-ding-unmatched
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
544 (ding)))
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
545 (setq mic-paren-forw-overlay
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
546 (mic-make-overlay (point) (1+ (point))))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
547 (mic-overlay-put mic-paren-forw-overlay
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
548 'face paren-no-match-face)
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
549 (and paren-message-no-match
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
550 (not (window-minibuffer-p (selected-window)))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
551 (message "No closing parenthesis found"))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
552 (and paren-message-no-match
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
553 paren-ding-unmatched
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
554 (ding))))))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
555
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
556 ;;; --------------------------------------------------
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
557
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
558 (defun mic-paren-get-matching-open-text (open)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
559 "Returns a string with the context around OPEN-paren."
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
560 ;; If there's stuff on this line preceding the paren, then display text from
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
561 ;; beginning of line to paren.
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
562 ;;
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
563 ;; If, however, the paren is at the beginning of a line, then skip whitespace
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
564 ;; forward and display text from paren to end of the next line containing
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
565 ;; non-space text.
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
566 ;;
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
567 ;; (Same as in stig-paren.el)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
568 (save-excursion
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
569 (goto-char open)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
570 (if (save-excursion
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
571 (skip-chars-backward " \t")
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
572 (not (bolp)))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
573 (progn
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
574 (beginning-of-line)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
575 (concat (buffer-substring (point) (1+ open)) "..."))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
576 (forward-char 1) ;From the beginning-of-line
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
577 (skip-chars-forward "\n \t")
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
578 (end-of-line)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
579 (buffer-substring open (point)))))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
580
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
581
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
582 (defun mic-paren-get-matching-close-text (close)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
583 "Returns a string with the context around CLOSE-paren."
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
584 ;; The whole line up until the close-paren with "..." appended if there are
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
585 ;; more text after the close-paren
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
586 (save-excursion
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
587 (goto-char close)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
588 (beginning-of-line)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
589 (concat
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
590 (buffer-substring (point) close)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
591 (progn
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
592 (goto-char close)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
593 (if (looking-at "[ \t]*$")
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
594 ""
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
595 "...")))))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
596
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
597
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
598 (defun paren-evenp (number)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
599 "Returns t if NUMBER is an even number, nil otherwise"
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
600 (eq 0 (% number 2)))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
601
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
602 (defun paren-backslashes-before-char (pnt)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
603 (setq pnt (1- pnt))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
604 (let ((n 0))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
605 (while (and (>= pnt (point-min))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
606 (eq (char-syntax (char-after pnt)) ?\\))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
607 (setq n (1+ n))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
608 (setq pnt (1- pnt)))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
609 n))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
610
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
611
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
612
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
613 ;;; ======================================================================
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
614 ;;; Initialisation when loading:
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
615
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
616 ;;; Try to load the timer feature if its not already loaded
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
617 (or paren-dont-load-timer
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
618 (featurep 'timer)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
619 (condition-case ()
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
620 (require 'timer)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
621 (error nil)))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
622
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
623
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
624 (or paren-dont-activate-on-load
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
625 (paren-activate))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
626
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
627 ;;; This is in case mic-paren.el is preloaded. [Does this work? /Mic]
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
628 (add-hook 'window-setup-hook
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
629 (function (lambda ()
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
630 (and window-system
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
631 (not paren-dont-activate-on-load)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
632 (paren-activate)))))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
633
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
634 (provide 'mic-paren)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents:
diff changeset
635 (provide 'paren)