annotate lisp/prim/lisp.el @ 163:0132846995bd r20-3b8

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