annotate lisp/ilisp/ilisp-prn.el @ 124:9b50b4588a93 r20-1b15

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