comparison lisp/packages/mic-paren.el @ 104:cf808b4c4290 r20-1b4

Import from CVS: tag r20-1b4
author cvs
date Mon, 13 Aug 2007 09:16:51 +0200
parents a145efe76779
children 360340f9fd5f
comparison
equal deleted inserted replaced
103:30eda07fe280 104:cf808b4c4290
1 ;;; mic-paren.el --- highlight matching parenthesises. 1 ;;; mic-paren.el --- highlight matching parenthesises.
2 ;;; Version 1.3 - 97-02-25 2 ;;; Version 1.3.1 - 97-02-27
3 ;;; Copyright (C) 1997 Mikael Sjödin (mic@docs.uu.se) 3 ;;; Copyright (C) 1997 Mikael Sjödin (mic@docs.uu.se)
4 ;;; 4 ;;;
5 ;;; Author: Mikael Sjödin -- mic@docs.uu.se 5 ;;; Author: Mikael Sjödin -- mic@docs.uu.se
6 ;;; Additional code by: Vinicius Jose Latorre <vinicius@cpqd.br> 6 ;;; Additional code by: Vinicius Jose Latorre <vinicius@cpqd.br>
7 ;;; Steven L Baur <steve@altair.xemacs.org> 7 ;;; Steven L Baur <steve@altair.xemacs.org>
70 ;;; This file can be obtained from http://www.docs.uu.se/~mic/emacs.html 70 ;;; This file can be obtained from http://www.docs.uu.se/~mic/emacs.html
71 71
72 ;;; ---------------------------------------------------------------------- 72 ;;; ----------------------------------------------------------------------
73 ;;; Versions: 73 ;;; Versions:
74 ;;; 74 ;;;
75 ;;; v1.3.1 Some spelling corrected (from Vinicius Jose Latorre
76 ;;; <vinicius@cpqd.br> and Steven L Baur <steve@altair.xemacs.org>)
77 ;;;
75 ;;; v1.3 Added code from Vinicius Jose Latorre <vinicius@cpqd.br> to 78 ;;; v1.3 Added code from Vinicius Jose Latorre <vinicius@cpqd.br> to
76 ;;; highlight unmathced parenthesises (useful in minibuffer) 79 ;;; highlight unmathced parenthesises (useful in minibuffer)
77 ;;; 80 ;;;
78 ;;; v1.2.1 Fixed stuff to work with OS/2 emx-emacs 81 ;;; v1.2.1 Fixed stuff to work with OS/2 emx-emacs
79 ;;; - checks if x-display-color-p is bound before calling it 82 ;;; - checks if x-display-color-p is bound before calling it
185 188
186 (defvar paren-dont-load-timer (not (string-match "XEmacs\\|Lucid" 189 (defvar paren-dont-load-timer (not (string-match "XEmacs\\|Lucid"
187 emacs-version)) 190 emacs-version))
188 "*If non-nil mic-paren will not try to load the timer-feature when loaded. 191 "*If non-nil mic-paren will not try to load the timer-feature when loaded.
189 192
190 (I have no idea why you'd ever want to set this to non-nil but I hate packages 193 (I have no idea why Emacs user ever want to set this to non-nil but I hate
191 which loads/activates stuff I don't want to use so I provide this way to prevent 194 packages which loads/activates stuff I don't want to use so I provide this way
192 the loading if someone doesn't want timers to be loaded.)") 195 to prevent the loading if someone doesn't want timers to be loaded.)")
193 196
194 ;;; ------------------------------ 197 ;;; ------------------------------
195 198
196 (defvar paren-face (if (and (fboundp 'x-display-color-p) 199 (defvar paren-face (if (and (fboundp 'x-display-color-p)
197 (x-display-color-p)) 200 (x-display-color-p))
355 (defun mic-paren-command-hook () 358 (defun mic-paren-command-hook ()
356 (or executing-kbd-macro 359 (or executing-kbd-macro
357 (input-pending-p) ;[This might cause trouble since the 360 (input-pending-p) ;[This might cause trouble since the
358 ; function is unreliable] 361 ; function is unreliable]
359 (condition-case paren-error 362 (condition-case paren-error
360 (mic-paren-highligt) 363 (mic-paren-highlight)
361 (error 364 (error
362 (if (not (window-minibuffer-p (selected-window))) 365 (if (not (window-minibuffer-p (selected-window)))
363 (message "mic-paren catched error (please report): %s" 366 (message "mic-paren catched error (please report): %s"
364 paren-error)))))) 367 paren-error))))))
365 368
366 (defun mic-paren-command-idle-hook () 369 (defun mic-paren-command-idle-hook ()
367 (condition-case paren-error 370 (condition-case paren-error
368 (mic-paren-highligt) 371 (mic-paren-highlight)
369 (error 372 (error
370 (if (not (window-minibuffer-p (selected-window))) 373 (if (not (window-minibuffer-p (selected-window)))
371 (message "mic-paren catched error (please report): %s" 374 (message "mic-paren catched error (please report): %s"
372 paren-error))))) 375 paren-error)))))
373 376
374 377
375 (defun mic-paren-highligt () 378 (defun mic-paren-highlight ()
376 "The main-function of mic-paren. Does all highlighting, dinging, messages, 379 "The main-function of mic-paren. Does all highlighting, dinging, messages,
377 cleaning-up." 380 cleaning-up."
378 ;; Remove any old highlighting 381 ;; Remove any old highlighting
379 (mic-delete-overlay mic-paren-forw-overlay) 382 (mic-delete-overlay mic-paren-forw-overlay)
380 (mic-delete-overlay mic-paren-point-overlay) 383 (mic-delete-overlay mic-paren-point-overlay)
412 (if open 415 (if open
413 (let ((mismatch (/= (matching-paren (preceding-char)) 416 (let ((mismatch (/= (matching-paren (preceding-char))
414 (char-after open))) 417 (char-after open)))
415 (visible (pos-visible-in-window-p open))) 418 (visible (pos-visible-in-window-p open)))
416 ;; If highlight is appropriate 419 ;; If highlight is appropriate
417 ;; highligt 420 ;; highlight
418 ;; else 421 ;; else
419 ;; remove any old highlight 422 ;; remove any old highlight
420 (if (or visible paren-highlight-offscreen paren-sexp-mode) 423 (if (or visible paren-highlight-offscreen paren-sexp-mode)
421 ;; If sexp-mode 424 ;; If sexp-mode
422 ;; highlight sexp 425 ;; highlight sexp
494 (setq close (scan-sexps (point) 1)) 497 (setq close (scan-sexps (point) 1))
495 (error nil)))) 498 (error nil))))
496 ;; If match found 499 ;; If match found
497 ;; highlight expression and/or print messages 500 ;; highlight expression and/or print messages
498 ;; else 501 ;; else
499 ;; highligt unmatched paren 502 ;; highlight unmatched paren
500 ;; print no-match message 503 ;; print no-match message
501 (if close 504 (if close
502 (let ((mismatch (/= (matching-paren (following-char)) 505 (let ((mismatch (/= (matching-paren (following-char))
503 (char-after (1- close)))) 506 (char-after (1- close))))
504 (visible (pos-visible-in-window-p close))) 507 (visible (pos-visible-in-window-p close)))
505 ;; If highlight is appropriate 508 ;; If highlight is appropriate
506 ;; highligt 509 ;; highlight
507 ;; else 510 ;; else
508 ;; remove any old highlight 511 ;; remove any old highlight
509 (if (or visible paren-highlight-offscreen paren-sexp-mode) 512 (if (or visible paren-highlight-offscreen paren-sexp-mode)
510 ;; If sexp-mode 513 ;; If sexp-mode
511 ;; highlight sexp 514 ;; highlight sexp