annotate lisp/ilisp/ilisp-ext.el @ 58:8b0bdfdf0cf0 r19-16-pre4

Import from CVS: tag r19-16-pre4
author cvs
date Mon, 13 Aug 2007 08:58:37 +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-ext.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 ;;; Lisp mode extensions from the ILISP package.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Copyright (C) 1990, 1991, 1992 Chris McConnell, ccm@cs.cmu.edu.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; This file may become part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; but WITHOUT ANY WARRANTY. No author or distributor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; accepts responsibility to anyone for the consequences of using it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; or for whether it serves any particular purpose or works at all,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; unless he says so in writing. Refer to the GNU Emacs General Public
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;; License for full details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;; Everyone is granted permission to copy, modify and redistribute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;; GNU Emacs, but only under the conditions described in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;; GNU Emacs General Public License. A copy of this license is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;; supposed to have been given to you along with GNU Emacs so you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;; can know your rights and responsibilities. It should be in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;; file named COPYING. Among other things, the copyright notice
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;; and this notice must be preserved on all copies.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;; When loaded this file adds new functionality to emacs lisp mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;; and lisp mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;; Default bindings:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;;; M-x find-unbalanced-lisp find unbalanced parens in the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;;; buffer. With a prefix in the current region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;;; ] Close all open parentheses back to the start of the containing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;; sexp, or to a previous left bracket which will be converted to a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;; left paren.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;; M-q Reindent comments or strings in paragraph chunks or reindent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;;; the containing sexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;;; M-x comment-region-lisp inserts prefix copies of the comment-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;;; character before lines in the region and the comment-end character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;;; at the end of each line. If called with a negative prefix, that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;;; many copies are removed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;;; C-M-r repositions the first line of the current defun to the top
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;;; of the current window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;;; C-M-l switches the current window to the previously seen buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;;; EXAMPLE .emacs:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;;; (setq ilisp-ext-load-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;;; '(lambda () (define-key global-map "\C-\M-l" 'previous-buffer-lisp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;;; (require 'ilisp-ext)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;;;%Syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;;; This makes it so that .'s are treated as normal characters so that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;;; 3.141 gets treated as a single lisp token. This does cause dotted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;;; pairs to be treated weird though.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (modify-syntax-entry ?. "_" lisp-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;;; Brackets match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (modify-syntax-entry ?\[ "(]" lisp-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (modify-syntax-entry ?\] ")[" lisp-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;;;%Superbrackets
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (defun close-all-lisp (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 "Unless you are in a string, insert right parentheses as necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 to balance unmatched left parentheses back to the start of the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 defun or to a previous left bracket which is then replaced with a left
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 parentheses. If there are too many right parentheses, remove them
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 unless there is text after the extra right parentheses. If called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 with a prefix, the entire expression will be closed and all open left
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 brackets will be replaced with left parentheses."
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 (let* ((point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (begin (lisp-defun-begin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (end (lisp-end-defun-text))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 inserted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (closed nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (goto-char point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (if (or (car (cdr (cdr (lisp-in-string begin end))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (save-excursion (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (looking-at "[ \t]*;")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (insert "]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (if (= begin end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (error "No sexp to close.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (narrow-to-region begin end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (if (< point begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (setq point begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (if (> point end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (setq point end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;; Add parens at point until either the defun is closed, or we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;; hit a square bracket.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (goto-char point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (insert ?\)) ;So we have an sexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (while (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (setq inserted (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (progn (backward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (or arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (not (eq (char-after (point)) ?\[))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (error (setq closed t) nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;; With an arg replace all left brackets
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (if (and arg (= (char-after (point)) ?\[))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (insert ?\()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (backward-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (forward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (insert ?\)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (if (< (point) point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;; We are at a left bracket
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (let ((left (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (insert ?\()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (backward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (forward-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;; There was not an open left bracket so close at end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (delete-region point inserted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (goto-char begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (if (condition-case () (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (forward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (<= (point) end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ;; Delete extra right parens
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (let ((point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (skip-chars-forward " \t)\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (if (or (bolp) (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (skip-chars-backward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (delete-region point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 "There is text after the last right parentheses.")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ;; Insert parens at end changing any left brackets
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (insert ?\))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (progn (backward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (if (= (char-after (point)) ?\[)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (insert ?\()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (backward-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (> (point) begin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (error (delete-backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 nil))))))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ;;;%Reindentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (defun reindent-lisp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 "Indents code depending partially on context (comments or strings).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 If in a comment, indent the comment paragraph bounded by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 non-comments, blank lines or empty comment lines. If in a string,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 indent the paragraph bounded by string delimiters or blank lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 Otherwise go to the containing defun, close it and reindent the code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 block."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (let ((region (lisp-in-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (comment (concat "[ \t]*" comment-start "+[ \t]*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (set-marker lisp-fill-marker (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (cond (region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (or (= (char-after (point)) ?\")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (and (< (point) (car region)) (goto-char (car region)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (re-search-backward "^$" (car region) 'end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (let ((begin (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (end (car (cdr region)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (fill-prefix nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (re-search-forward "^$" end 'end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (if (= (point) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (progn (skip-chars-forward "^\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (if (not (eobp)) (forward-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (fill-region-as-paragraph begin (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ((looking-at comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (let ((fill-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (buffer-substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (progn (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (while (and (not (bobp)) (lisp-in-comment comment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (if (not (bobp)) (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (let ((begin (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (while (and (lisp-in-comment comment) (not (eobp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (replace-match fill-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (if (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (progn (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (forward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (fill-region-as-paragraph begin (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (goto-char lisp-fill-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (close-all-lisp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (lisp-defun-begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (indent-sexp-ilisp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (goto-char lisp-fill-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (set-marker lisp-fill-marker nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (message "Done")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 ;;;%Comment region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (defun comment-region-lisp (start end prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 "If prefix is positive, insert prefix copies of comment-start at the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 start and comment-end at the end of each line in region. If prefix is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 negative, remove all comment-start and comment-end strings from the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 region."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (interactive "r\np")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (if (and (not (= start end)) (bolp)) (setq end (1- end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (set-marker ilisp-comment-marker (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (untabify start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (let* ((count 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (comment comment-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (comment-end (if (not (equal comment-end "")) comment-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (if (> prefix 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (while (< count prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (setq comment (concat comment-start comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 count (1+ count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (while (<= (point) ilisp-comment-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (insert comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (if comment-end (progn (end-of-line) (insert comment-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (setq comment (concat comment "+"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (while (<= (point) ilisp-comment-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (if (looking-at comment) (replace-match ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (if comment-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (re-search-backward comment-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (replace-match "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (set-marker ilisp-comment-marker nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 ;;;%Movement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 ;;; beginning-of-defun-lisp and end-of-defun-lisp are overloaded by ilisp.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (defun beginning-of-defun-lisp (&optional stay)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 "Go to the next left paren that starts at the left margin."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (beginning-of-defun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (defun end-of-defun-lisp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 "Go to the next left paren that starts at the left margin."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (let ((point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (re-search-forward "^[ \t\n]*[^; \t\n]" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (if (not (bolp)) (beginning-of-defun-lisp t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (lisp-end-defun-text t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (if (= point (point)) ;Already at end so move to next end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (lisp-skip (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (if (not (or (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (= (char-after (point)) ?\n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (lisp-end-defun-text t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 ;;;%%Reposition-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (defun count-screen-lines-lisp (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 "Return the number of screen lines between start and end."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (narrow-to-region start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (vertical-motion (- (point-max) (point-min))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (defun count-screen-lines-signed-lisp (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 "Return number of screen lines between START and END; returns a negative
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 number if END precedes START."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (let ((lines (count-screen-lines-lisp start end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (if (< start end) lines (- lines))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 ;;; This was written by Michael D. Ernst
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (defun reposition-window-lisp (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 "Make the current definition and/or comment visible, move it to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 top of the window, or toggle the visibility of comments that precede
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 it. Leaves point unchanged unless supplied with prefix ARG. If the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 definition is fully onscreen, it is moved to the top of the window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 If it is partly offscreen, the window is scrolled to get the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 definition \(or as much as will fit) onscreen, unless point is in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 comment which is also partly offscreen, in which case the scrolling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 attempts to get as much of the comment onscreen as possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 Initially reposition-window attempts to make both the definition and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 preceding comments visible. Further invocations toggle the visibility
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 of the comment lines. If ARG is non-nil, point may move in order to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 make the whole defun visible \(if only part could otherwise be made
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 so), to make the defun line visible \(if point is in code and it could
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 not be made so, or if only comments, including the first comment line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 are visible), or to make the first comment line visible \(if point is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 in a comment)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (let* ((here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 ;; change this name once I've gotten rid of references to ht.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 ;; this is actually the number of the last screen line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (ht (- (window-height (selected-window)) 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (line (count-screen-lines-lisp (window-start) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (comment-height
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 ;; The max deals with the case of cursor between defuns.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (max 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (count-screen-lines-signed-lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 ;; the beginning of the preceding comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (if (not (and (bolp) (eq (char-after (point)) ?\()))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (beginning-of-defun-lisp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (beginning-of-defun-lisp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (end-of-defun-lisp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 ;; Skip whitespace, newlines, and form feeds.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (re-search-forward "[^\\s \n\014]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 here)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (defun-height
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (count-screen-lines-signed-lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (end-of-defun-lisp) ;associate comment with next defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (beginning-of-defun-lisp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 ;; This must be positive, so don't use the signed version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (defun-depth
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (count-screen-lines-lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (save-excursion (end-of-defun-lisp) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (defun-line-onscreen-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (and (<= defun-height line) (<= (- line defun-height) ht))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (cond ((or (= comment-height line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (and (= line ht)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (> comment-height line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 ;; if defun line offscreen, we should be in case 4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 defun-line-onscreen-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 ;; Either first comment line is at top of screen or (point at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 ;; bottom of screen, defun line onscreen, and first comment line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 ;; off top of screen). That is, it looks like we just did
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 ;; recenter-definition, trying to fit as much of the comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 ;; onscreen as possible. Put defun line at top of screen; that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 ;; is, show as much code, and as few comments, as possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (if (and arg (> defun-depth (1+ ht)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 ;; Can't fit whole defun onscreen without moving point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (progn (end-of-defun-lisp) (beginning-of-defun-lisp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (recenter 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (recenter (max defun-height 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 ((or (= defun-height line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (= line 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (and (< line comment-height)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (< defun-height 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 ;; Defun line or cursor at top of screen, OR cursor in comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 ;; whose first line is offscreen.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 ;; Avoid moving definition up even if defun runs offscreen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 ;; we care more about getting the comment onscreen.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (cond ((= line ht)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 ;; cursor on last screen line (and so in a comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (if arg (progn (end-of-defun-lisp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (beginning-of-defun-lisp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (recenter 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 ;; This condition, copied from case 4, may not be quite right
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 ((and arg (< ht comment-height))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 ;; Can't get first comment line onscreen.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 ;; Go there and try again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (forward-line (- comment-height))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 ;; was (reposition-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (recenter 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (recenter (min ht comment-height))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 ;; (recenter (min ht comment-height))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 ((and (> (+ line defun-depth -1) ht)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 defun-line-onscreen-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 ;; Defun runs off the bottom of the screen and the defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 ;; line is onscreen. Move the defun up.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (recenter (max 0 (1+ (- ht defun-depth)) defun-height)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 ;; If on the bottom line and comment start is offscreen
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 ;; then just move all comments offscreen, or at least as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 ;; far as they'll go. Try to get as much of the comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 ;; onscreen as possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (if (and arg (< ht comment-height))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 ;; Can't get defun line onscreen; go there and try again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (progn (forward-line (- defun-height))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (reposition-window-lisp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (recenter (min ht comment-height)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (defun previous-buffer-lisp (n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 "Switch to Nth previously selected buffer. N defaults to the number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 of windows plus 1. That is, no argument switches to the most recently
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 selected buffer that is not visible. If N is 1, repeated calls will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 cycle through all buffers; -1 cycles the other way. If N is greater
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 than 1, the first N buffers on the buffer list are rotated."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (if (not n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (switch-to-buffer nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (let ((buffer-list (buffer-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (setq n (prefix-numeric-value n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (cond ((= n 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (bury-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (setq n 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 ((< n 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (setq buffer-list (nreverse buffer-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 n (- n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (t nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (while (and (> n 1) buffer-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (setq n (1- n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 buffer-list (cdr buffer-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (while (eq (elt (buffer-name (car buffer-list)) 0) ? )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (setq buffer-list (cdr buffer-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (if buffer-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (switch-to-buffer (car buffer-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (error "There aren't that many buffers")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 ;;;%Bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (define-key emacs-lisp-mode-map "\M-q" 'reindent-lisp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (define-key emacs-lisp-mode-map "\M-\C-a" 'beginning-of-defun-lisp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (define-key emacs-lisp-mode-map "\M-\C-e" 'end-of-defun-lisp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (define-key emacs-lisp-mode-map "\C-\M-r" 'reposition-window-lisp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (define-key emacs-lisp-mode-map "]" 'close-all-lisp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (define-key lisp-mode-map "\M-q" 'reindent-lisp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (define-key lisp-mode-map "\C-\M-r" 'reposition-window-lisp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (define-key lisp-mode-map "]" 'close-all-lisp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (define-key global-map "\M-\C-l" 'previous-buffer-lisp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (run-hooks 'ilisp-ext-load-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (provide 'ilisp-ext)