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