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