annotate lisp/ilisp/ilisp-prn.el @ 0:376386a54a3c r19-14

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