Mercurial > hg > xemacs-beta
comparison lisp/ilisp/ilisp-mov.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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
1 ;;; -*- Mode: Emacs-Lisp -*- | |
2 | |
3 ;;; ilisp-mov.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 ;;;%%Movement | |
25 (defun bol-ilisp (arg) | |
26 "Goes to the beginning of line, then skips past the prompt, if any. | |
27 If a prefix argument is given (\\[universal-argument]), then no prompt skip | |
28 -- go straight to column 0. | |
29 | |
30 The prompt skip is done by skipping text matching the regular expression | |
31 comint-prompt-regexp or ilisp-other-prompt, both buffer local variables." | |
32 (interactive "P") | |
33 (beginning-of-line) | |
34 (if (null arg) | |
35 (or (comint-skip-prompt) | |
36 (if ilisp-other-prompt | |
37 (let ((comint-prompt-regexp ilisp-other-prompt)) | |
38 (comint-skip-prompt)))))) | |
39 | |
40 ;;; | |
41 (defun beginning-of-defun-lisp (&optional stay) | |
42 "Go to the next left paren that starts at the left margin or after a | |
43 prompt in an ILISP buffer. If optional STAY, then do not move to | |
44 prior defun if at the start of one in an ilisp mode." | |
45 (interactive) | |
46 (if (memq major-mode ilisp-modes) | |
47 (let ((point (point))) | |
48 (if (and (not stay) (= point (lisp-input-start))) | |
49 (progn (forward-line -1) (lisp-input-start)))) | |
50 (beginning-of-defun))) | |
51 | |
52 ;;; | |
53 (defun end-of-defun-lisp () | |
54 "Go to the next left paren that starts at the left margin or after a | |
55 prompt in an ILISP buffer and go to the end of the expression." | |
56 (interactive) | |
57 (let ((point (point))) | |
58 (if (memq major-mode ilisp-modes) | |
59 (beginning-of-defun-lisp t) | |
60 (if (or (lisp-in-string) | |
61 (progn (beginning-of-line) | |
62 (re-search-forward "^[ \t\n]*[^; \t\n]" nil t) | |
63 (back-to-indentation) | |
64 (not (bolp)))) | |
65 (beginning-of-defun-lisp t))) | |
66 (lisp-end-defun-text t) | |
67 (if (= point (point)) ;Already at end so move to next end | |
68 (progn | |
69 (if (memq major-mode ilisp-modes) | |
70 (re-search-forward comint-prompt-regexp (point-max) t) | |
71 (lisp-skip (point-max))) | |
72 (if (not (or (eobp) | |
73 (= (char-after (point)) ?\n))) | |
74 (lisp-end-defun-text t)))))) | |
75 | |
76 ;;; | |
77 (defun lisp-defun-begin () | |
78 "Go to the start of the containing defun and return point." | |
79 (let (begin) | |
80 (if (memq major-mode ilisp-modes) | |
81 (lisp-input-start) | |
82 (if (or (eobp) (not (and (bolp) (= (char-after (point)) ?\()))) | |
83 (beginning-of-defun)) | |
84 (point)))) | |
85 | |
86 ;;; | |
87 (defun lisp-defun-end (&optional no-errorp at-beginp) | |
88 "Go to the end of the containing defun and return point or nil if | |
89 there is no end." | |
90 (if (not at-beginp) (lisp-defun-begin)) | |
91 (condition-case () | |
92 (progn | |
93 (lisp-skip (point-max)) ;To skip comments on defun-end | |
94 (forward-sexp) | |
95 (point)) | |
96 (error (if no-errorp nil (error "Unbalanced parentheses"))))) | |
97 | |
98 ;;; | |
99 (defun lisp-find-next-start () | |
100 "Find the start of the next line at the left margin that starts with | |
101 a character besides whitespace, a \) or ;;; and return the | |
102 point." | |
103 (if (eobp) | |
104 (point-max) | |
105 (save-excursion | |
106 (forward-char) | |
107 (if (re-search-forward "^\\(\\(;;;\\)\\|\\([^ \t\n\);]\\)\\)" nil t) | |
108 (match-beginning 0) | |
109 (point-max))))) | |
110 | |
111 ;;; | |
112 (defun lisp-end-defun-text (&optional at-start) | |
113 "Go the end of the text associated with the current defun and return | |
114 point. The end is the last character before whitespace leading to | |
115 a left paren or ;;; at the left margin unless it is in a string." | |
116 (if (not at-start) (lisp-defun-begin)) | |
117 (let ((point (point)) | |
118 (boundary (lisp-find-next-start)) | |
119 (final (save-excursion | |
120 (condition-case () | |
121 (progn (forward-sexp) (point)) | |
122 (error (point-max)))))) | |
123 ;; Find the next line starting at the left margin and then check | |
124 ;; to see if it is in a string. | |
125 (while (progn | |
126 (skip-chars-forward "^\"" boundary) ;To the next string | |
127 (if (= (point) boundary) | |
128 nil ;No quote found and at limit | |
129 (let ((string-boundary ;Start of next defun | |
130 (save-excursion | |
131 (if (re-search-forward "^\(\\|^;;;" nil t) | |
132 (match-beginning 0) | |
133 (point-max))))) | |
134 (if (condition-case () | |
135 (progn (forward-sexp) t) | |
136 (error (goto-char string-boundary) nil)) | |
137 (if (>= (point) boundary) | |
138 ;; Boundary was in string | |
139 (if (> (point) string-boundary) | |
140 (progn ;String ended in next defun | |
141 (goto-char string-boundary) | |
142 nil) | |
143 (if (> (setq boundary | |
144 (lisp-find-next-start)) | |
145 final) | |
146 ;; Normal defun | |
147 (progn (goto-char final) nil) | |
148 t)) | |
149 t) | |
150 ;; Unclosed string | |
151 nil))))) | |
152 (re-search-backward "^[^; \t\n]\\|^[^;\n][ \t]*[^ \t\n]" point t) | |
153 (end-of-line) | |
154 (skip-chars-backward " \t") | |
155 (if (< (point) point) | |
156 (goto-char point) | |
157 (if (save-excursion | |
158 (let ((point (point))) | |
159 (beginning-of-line) | |
160 (if comment-start (search-forward comment-start point t)))) | |
161 (progn (next-line 1) (indent-line-ilisp))) | |
162 (point)))) | |
163 | |
164 ;;; | |
165 (defun lisp-in-comment (test) | |
166 "Return T if you are in a comment." | |
167 (beginning-of-line) | |
168 (and (looking-at test) | |
169 (not (= (match-end 0) | |
170 (progn (end-of-line) (point)))))) | |
171 | |
172 ;;; | |
173 (defun lisp-in-string (&optional begin end) | |
174 "Return the string region that immediately follows/precedes point or | |
175 that contains point in optional region BEGIN to END. If point is in | |
176 region, T will be returned as well." | |
177 (save-excursion | |
178 (if (not begin) | |
179 (save-excursion | |
180 (setq end (lisp-end-defun-text) | |
181 begin (lisp-defun-begin)))) | |
182 (let* ((point (progn (skip-chars-forward " \t") (point))) | |
183 (done nil)) | |
184 (goto-char begin) | |
185 (while (and (< (point) end) (not done)) | |
186 (skip-chars-forward "^\"" end) | |
187 (setq begin (point)) | |
188 (if (< begin end) | |
189 (if (and (not (bobp)) (= (char-after (1- begin)) ??)) | |
190 (forward-char) | |
191 (if (condition-case () (progn (forward-sexp) (<= (point) end)) | |
192 (error nil)) | |
193 (progn ;After string | |
194 (skip-chars-forward " \t") | |
195 (if (or (= begin point) (= point (point))) | |
196 (setq done (list begin (point) nil)) | |
197 (if (and (< begin point) (< point (point))) | |
198 (setq done (list begin (point) t))))) | |
199 ;; In string at end of buffer | |
200 (setq done (list begin end t)))))) | |
201 done))) |