annotate lisp/lisp.el @ 400:a86b2b5e0111 r21-2-30

Import from CVS: tag r21-2-30
author cvs
date Mon, 13 Aug 2007 11:14:34 +0200
parents 966663fcf606
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1 ;;; lisp.el --- Lisp editing commands for XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 1986, 1994, 1997 Free Software Foundation, Inc.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
5 ;; Maintainer: FSF
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
6 ;; Keywords: lisp, languages, dumped
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
7
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
9
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
13 ;; any later version.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
14
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
18 ;; General Public License for more details.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
19
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
23 ;; 02111-1307, USA.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
24
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
25 ;;; Synched up with: Emacs/Mule zeta.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
26
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
27 ;;; Commentary:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
28
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
29 ;; This file is dumped with XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
30
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
31 ;; Lisp editing commands to go with Lisp major mode.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
32
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
33 ;; 06/11/1997 - Use char-(after|before) instead of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
34 ;; (following|preceding)-char. -slb
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
35
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
36 ;;; Code:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
37
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
38 ;; Note that this variable is used by non-lisp modes too.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
39 (defcustom defun-prompt-regexp nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
40 "*Non-nil => regexp to ignore, before the character that starts a defun.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
41 This is only necessary if the opening paren or brace is not in column 0.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
42 See `beginning-of-defun'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
43 :type '(choice (const :tag "none" nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
44 regexp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
45 :group 'lisp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
46
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
47 (make-variable-buffer-local 'defun-prompt-regexp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
48
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
49 (defcustom parens-require-spaces t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
50 "Non-nil => `insert-parentheses' should insert whitespace as needed."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
51 :type 'boolean
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
52 :group 'editing-basics
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
53 :group 'lisp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
54
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
55 (defun forward-sexp (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
56 "Move forward across one balanced expression (sexp).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
57 With argument, do it that many times. Negative arg -N means
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
58 move backward across N balanced expressions."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
59 ;; XEmacs change (for zmacs regions)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
60 (interactive "_p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
61 (or arg (setq arg 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
62 ;; XEmacs: evil hack! The other half of the evil hack below.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
63 (if (and (> arg 0) (looking-at "#s("))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
64 (goto-char (+ (point) 2)))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 265
diff changeset
65 (goto-char (or (scan-sexps (point) arg) (buffer-end arg)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
66 (if (< arg 0) (backward-prefix-chars))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
67 ;; XEmacs: evil hack! Skip back over #s so that structures are read
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
68 ;; properly. the current cheesified syntax tables just aren't up to
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
69 ;; this.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
70 (if (and (< arg 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
71 (eq (char-after (point)) ?\()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
72 (>= (- (point) (point-min)) 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
73 (eq (char-after (- (point) 1)) ?s)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
74 (eq (char-after (- (point) 2)) ?#))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
75 (goto-char (- (point) 2))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
76
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
77 (defun backward-sexp (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
78 "Move backward across one balanced expression (sexp).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
79 With argument, do it that many times. Negative arg -N means
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
80 move forward across N balanced expressions."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
81 ;; XEmacs change (for zmacs regions)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
82 (interactive "_p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
83 (or arg (setq arg 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
84 (forward-sexp (- arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
85
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
86 (defun mark-sexp (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
87 "Set mark ARG sexps from point.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
88 The place mark goes is the same place \\[forward-sexp] would
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
89 move to with the same argument.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
90 Repeat this command to mark more sexps in the same direction."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
91 (interactive "p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
92 ;; XEmacs change
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
93 (mark-something 'mark-sexp 'forward-sexp arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
94
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
95 (defun forward-list (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
96 "Move forward across one balanced group of parentheses.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
97 With argument, do it that many times.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
98 Negative arg -N means move backward across N groups of parentheses."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
99 ;; XEmacs change
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
100 (interactive "_p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
101 (or arg (setq arg 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
102 (goto-char (or (scan-lists (point) arg 0) (buffer-end arg))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
103
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
104 (defun backward-list (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
105 "Move backward across one balanced group of parentheses.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
106 With argument, do it that many times.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
107 Negative arg -N means move forward across N groups of parentheses."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
108 ;; XEmacs change (for zmacs regions)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
109 (interactive "_p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
110 (or arg (setq arg 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
111 (forward-list (- arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
112
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
113 (defun down-list (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
114 "Move forward down one level of parentheses.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
115 With argument, do this that many times.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
116 A negative argument means move backward but still go down a level.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
117 In Lisp programs, an argument is required."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
118 ;; XEmacs change (for zmacs regions)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
119 (interactive "_p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
120 (let ((inc (if (> arg 0) 1 -1)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
121 (while (/= arg 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
122 (goto-char (or (scan-lists (point) inc -1) (buffer-end arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
123 (setq arg (- arg inc)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
124
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
125 (defun backward-up-list (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
126 "Move backward out of one level of parentheses.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
127 With argument, do this that many times.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
128 A negative argument means move forward but still to a less deep spot.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
129 In Lisp programs, an argument is required."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
130 (interactive "_p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
131 (up-list (- arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
132
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
133 (defun up-list (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
134 "Move forward out of one level of parentheses.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
135 With argument, do this that many times.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
136 A negative argument means move backward but still to a less deep spot.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
137 In Lisp programs, an argument is required."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
138 ;; XEmacs change (for zmacs regions)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
139 (interactive "_p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
140 (let ((inc (if (> arg 0) 1 -1)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
141 (while (/= arg 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
142 (goto-char (or (scan-lists (point) inc 1) (buffer-end arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
143 (setq arg (- arg inc)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
144
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
145 (defun kill-sexp (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
146 "Kill the sexp (balanced expression) following the cursor.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
147 With argument, kill that many sexps after the cursor.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
148 Negative arg -N means kill N sexps before the cursor."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
149 (interactive "p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
150 (let ((opoint (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
151 (forward-sexp arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
152 (kill-region opoint (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
153
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
154 (defun backward-kill-sexp (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
155 "Kill the sexp (balanced expression) preceding the cursor.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
156 With argument, kill that many sexps before the cursor.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
157 Negative arg -N means kill N sexps after the cursor."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
158 (interactive "p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
159 (kill-sexp (- arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
160
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
161 (defun beginning-of-defun (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
162 "Move backward to the beginning of a defun.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
163 With argument, do it that many times. Negative arg -N
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
164 means move forward to Nth following beginning of defun.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
165 Returns t unless search stops due to beginning or end of buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
166
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
167 Normally a defun starts when there is an char with open-parenthesis
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
168 syntax at the beginning of a line. If `defun-prompt-regexp' is
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
169 non-nil, then a string which matches that regexp may precede the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
170 open-parenthesis, and point ends up at the beginning of the line."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
171 ;; XEmacs change (for zmacs regions)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
172 (interactive "_p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
173 (and (beginning-of-defun-raw arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
174 (progn (beginning-of-line) t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
175
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
176 (defun beginning-of-defun-raw (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
177 "Move point to the character that starts a defun.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
178 This is identical to beginning-of-defun, except that point does not move
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
179 to the beginning of the line when `defun-prompt-regexp' is non-nil."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
180 (interactive "p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
181 (and arg (< arg 0) (not (eobp)) (forward-char 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
182 (and (re-search-backward (if defun-prompt-regexp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
183 (concat "^\\s(\\|"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
184 "\\(" defun-prompt-regexp "\\)\\s(")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
185 "^\\s(")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
186 nil 'move (or arg 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
187 (progn (goto-char (1- (match-end 0)))) t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
188
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
189 ;; XEmacs change (optional buffer parameter)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
190 (defun buffer-end (arg &optional buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
191 "Return `point-max' of BUFFER if ARG is > 0; return `point-min' otherwise.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
192 BUFFER defaults to the current buffer if omitted."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
193 (if (> arg 0) (point-max buffer) (point-min buffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
194
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
195 (defun end-of-defun (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
196 "Move forward to next end of defun. With argument, do it that many times.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
197 Negative argument -N means move back to Nth preceding end of defun.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
198
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
199 An end of a defun occurs right after the close-parenthesis that matches
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
200 the open-parenthesis that starts a defun; see `beginning-of-defun'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
201 ;; XEmacs change (for zmacs regions)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
202 (interactive "_p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
203 (if (or (null arg) (= arg 0)) (setq arg 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
204 (let ((first t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
205 (while (and (> arg 0) (< (point) (point-max)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
206 (let ((pos (point))) ; XEmacs -- remove unused npos.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
207 (while (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
208 (if (and first
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
209 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
210 (end-of-line 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
211 (beginning-of-defun-raw 1)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
212 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
213 (or (bobp) (forward-char -1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
214 (beginning-of-defun-raw -1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
215 (setq first nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
216 (forward-list 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
217 (skip-chars-forward " \t")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
218 (if (looking-at "\\s<\\|\n")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
219 (forward-line 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
220 (<= (point) pos))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
221 (setq arg (1- arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
222 (while (< arg 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
223 (let ((pos (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
224 (beginning-of-defun-raw 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
225 (forward-sexp 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
226 (forward-line 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
227 (if (>= (point) pos)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
228 (if (beginning-of-defun-raw 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
229 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
230 (forward-list 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
231 (skip-chars-forward " \t")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
232 (if (looking-at "\\s<\\|\n")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
233 (forward-line 1)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
234 (goto-char (point-min)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
235 (setq arg (1+ arg)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
236
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
237 (defun mark-defun ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
238 "Put mark at end of this defun, point at beginning.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
239 The defun marked is the one that contains point or follows point."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
240 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
241 (push-mark (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
242 (end-of-defun)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
243 (push-mark (point) nil t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
244 (beginning-of-defun)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
245 (re-search-backward "^\n" (- (point) 1) t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
246
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
247 (defun narrow-to-defun (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
248 "Make text outside current defun invisible.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
249 The defun visible is the one that contains point or follows point."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
250 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
251 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
252 (widen)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
253 (end-of-defun)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
254 (let ((end (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
255 (beginning-of-defun)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
256 (narrow-to-region (point) end))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
257
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
258 (defun insert-parentheses (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
259 "Enclose following ARG sexps in parentheses. Leave point after open-paren.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
260 A negative ARG encloses the preceding ARG sexps instead.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
261 No argument is equivalent to zero: just insert `()' and leave point between.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
262 If `parens-require-spaces' is non-nil, this command also inserts a space
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
263 before and after, depending on the surrounding characters."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
264 (interactive "P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
265 (if arg (setq arg (prefix-numeric-value arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
266 (setq arg 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
267 (cond ((> arg 0) (skip-chars-forward " \t"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
268 ((< arg 0) (forward-sexp arg) (setq arg (- arg))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
269 (and parens-require-spaces
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
270 (not (bobp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
271 (memq (char-syntax (char-before (point))) '(?w ?_ ?\) ))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
272 (insert " "))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
273 (insert ?\()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
274 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
275 (or (eq arg 0) (forward-sexp arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
276 (insert ?\))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
277 (and parens-require-spaces
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
278 (not (eobp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
279 (memq (char-syntax (char-after (point))) '(?w ?_ ?\( ))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
280 (insert " "))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
281
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
282 (defun move-past-close-and-reindent ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
283 "Move past next `)', delete indentation before it, then indent after it."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
284 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
285 (up-list 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
286 (forward-char -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
287 (while (save-excursion ; this is my contribution
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
288 (let ((before-paren (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
289 (back-to-indentation)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
290 (= (point) before-paren)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
291 (delete-indentation))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
292 (forward-char 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
293 (newline-and-indent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
294
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
295 (defun lisp-complete-symbol ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
296 "Perform completion on Lisp symbol preceding point.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
297 Compare that symbol against the known Lisp symbols.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
298
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
299 The context determines which symbols are considered.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
300 If the symbol starts just after an open-parenthesis, only symbols
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
301 with function definitions are considered. Otherwise, all symbols with
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
302 function definitions, values or properties are considered."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
303 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
304 (let* ((end (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
305 (buffer-syntax (syntax-table))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
306 (beg (unwind-protect
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
307 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
308 ;; XEmacs change
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
309 (if emacs-lisp-mode-syntax-table
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
310 (set-syntax-table emacs-lisp-mode-syntax-table))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
311 (backward-sexp 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
312 (while (eq (char-syntax (char-after (point))) ?\')
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
313 (forward-char 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
314 (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
315 (set-syntax-table buffer-syntax)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
316 (pattern (buffer-substring beg end))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
317 (predicate
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
318 (if (eq (char-after (1- beg)) ?\()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
319 'fboundp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
320 ;; XEmacs change
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
321 #'(lambda (sym)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
322 (or (boundp sym) (fboundp sym)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
323 (symbol-plist sym)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
324 (completion (try-completion pattern obarray predicate)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
325 (cond ((eq completion t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
326 ((null completion)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
327 (message "Can't find completion for \"%s\"" pattern)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
328 (ding))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
329 ((not (string= pattern completion))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
330 (delete-region beg end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
331 (insert completion))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
332 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
333 (message "Making completion list...")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
334 (let ((list (all-completions pattern obarray predicate))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
335 ;FSFmacs crock unnecessary in XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
336 ;see minibuf.el
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
337 ;(completion-fixup-function
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
338 ; (function (lambda () (if (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
339 ; (goto-char (max (point-min)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
340 ; (- (point) 4)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
341 ; (looking-at " <f>"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
342 ; (forward-char -4))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
343 )
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
344 (or (eq predicate 'fboundp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
345 (let (new)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
346 (while list
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
347 (setq new (cons (if (fboundp (intern (car list)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
348 (list (car list) " <f>")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
349 (car list))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
350 new))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
351 (setq list (cdr list)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
352 (setq list (nreverse new))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
353 (with-output-to-temp-buffer "*Completions*"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
354 (display-completion-list list)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
355 (message "Making completion list...%s" "done")))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
356
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
357 ;;; lisp.el ends here