0
|
1 ;;; -*- Mode: Emacs-Lisp -*-
|
|
2
|
|
3 ;;; ilisp-prn.el --
|
|
4
|
|
5 ;;; This file is part of ILISP.
|
|
6 ;;; Version: 5.7
|
|
7 ;;;
|
|
8 ;;; Copyright (C) 1990, 1991, 1992, 1993 Chris McConnell
|
|
9 ;;; 1993, 1994 Ivan Vasquez
|
|
10 ;;; 1994, 1995 Marco Antoniotti and Rick Busdiecker
|
|
11 ;;;
|
|
12 ;;; Other authors' names for which this Copyright notice also holds
|
|
13 ;;; may appear later in this file.
|
|
14 ;;;
|
|
15 ;;; Send mail to 'ilisp-request@lehman.com' to be included in the
|
|
16 ;;; ILISP mailing list. 'ilisp@lehman.com' is the general ILISP
|
|
17 ;;; mailing list were bugs and improvements are discussed.
|
|
18 ;;;
|
|
19 ;;; ILISP is freely redistributable under the terms found in the file
|
|
20 ;;; COPYING.
|
|
21
|
|
22
|
|
23
|
|
24 ;;;
|
|
25 ;;;
|
|
26 ;;; ILISP paren handling
|
|
27 ;;;
|
|
28 ;;;
|
|
29
|
|
30
|
|
31 ;;;%Unbalanced parentheses
|
|
32 (defun lisp-skip (end)
|
|
33 "Skip past whitespace, comments, backslashed characters and strings
|
|
34 in the current buffer as long as you are before END. This does move
|
|
35 the point."
|
|
36 (if (< (point) end)
|
|
37 (let ((comment (and comment-start (string-to-char comment-start)))
|
|
38 (done nil)
|
|
39 char)
|
|
40 (while (and (< (point) end)
|
|
41 (not done))
|
|
42 (skip-chars-forward "\n\t " end)
|
|
43 (setq char (char-after (point)))
|
|
44 (cond ((eq char ?\")
|
|
45 (forward-sexp))
|
|
46 ((eq char comment)
|
|
47 (forward-char)
|
|
48 (skip-chars-forward "^\n" end))
|
|
49 ((eq char ?\\)
|
|
50 (forward-char 2))
|
|
51 (t (setq done t)))))))
|
|
52
|
|
53 ;;;
|
|
54 (defun lisp-count-pairs (begin end left-delimiter right-delimiter)
|
|
55 "Return the number of top-level pairs of LEFT-DELIMITER and
|
|
56 RIGHT-DELIMITER between BEGIN and END. If they don't match, the point
|
|
57 will be placed on the offending entry."
|
|
58 (let ((old-point (point))
|
|
59 (sexp 0)
|
|
60 left)
|
|
61 (goto-char begin)
|
|
62 (lisp-skip end)
|
|
63 (while (< (point) end)
|
|
64 (let ((char (char-after (point))))
|
|
65 (cond ((or (eq char left-delimiter)
|
|
66 ;; For things other than lists
|
|
67 (eq (char-after (1- (point))) ?\n))
|
|
68 (setq sexp (1+ sexp))
|
|
69 (if (condition-case ()
|
|
70 (progn (forward-sexp) nil)
|
|
71 (error t))
|
|
72 (error "Extra %s" (char-to-string left-delimiter))))
|
|
73 ((eq char right-delimiter)
|
|
74 (error "Extra %s" (char-to-string right-delimiter)))
|
|
75 ((< (point) end) (forward-char))))
|
|
76 (lisp-skip end))
|
|
77 (goto-char old-point)
|
|
78 sexp))
|
|
79
|
|
80 ;;;
|
|
81 (defun find-unbalanced-region-lisp (start end)
|
|
82 "Go to the point in region where LEFT-DELIMITER and RIGHT-DELIMITER
|
|
83 become unbalanced. Point will be on the offending delimiter."
|
|
84 (interactive "r")
|
|
85 (lisp-count-pairs start end
|
|
86 (string-to-char left-delimiter)
|
|
87 (string-to-char right-delimiter))
|
|
88 (if (not ilisp-complete) (progn (beep) (message "Delimiters balance"))))
|
|
89
|
|
90 ;;;
|
|
91 (defun find-unbalanced-lisp (arg)
|
|
92 "Go to the point in buffer where LEFT-DELIMITER and RIGHT-DELIMITER
|
|
93 become unbalanced. Point will be on the offending delimiter. If
|
|
94 called with a prefix, use the current region."
|
|
95 (interactive "P")
|
|
96 (if arg
|
|
97 (call-interactively 'find-unbalanced-region-lisp)
|
|
98 (find-unbalanced-region-lisp (point-min) (point-max))))
|