annotate lisp/prim/lisp.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 1986, 1994 Free Software Foundation, Inc.
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Synched up with: FSF 19.30.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; Lisp editing commands to go with Lisp major mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; Note that this variable is used by non-lisp modes too.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (defvar defun-prompt-regexp nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 "*Non-nil => regexp to ignore, before the character that starts a defun.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 This is only necessary if the opening paren or brace is not in column 0.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 See `beginning-of-defun'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (make-variable-buffer-local 'defun-prompt-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (defvar parens-require-spaces t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 "Non-nil => `insert-parentheses' should insert whitespace as needed.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (defun forward-sexp (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 "Move forward across one balanced expression (sexp).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 With argument, do it that many times.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 Negative arg -N means move backward across N balanced expressions."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (interactive "_p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (or arg (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;; #### evil hack! The other half of the evil hack below.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (if (and (> arg 0) (looking-at "#s("))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (goto-char (+ (point) 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (goto-char (or (scan-sexps (point) arg) (buffer-end arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (if (< arg 0) (backward-prefix-chars))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; #### evil hack! Skip back over #s so that structures are read properly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; the current cheesified syntax tables just aren't up to this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (if (and (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (eq (char-after (point)) ?\()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (>= (- (point) (point-min)) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (eq (char-after (- (point) 1)) ?s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (eq (char-after (- (point) 2)) ?#))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (goto-char (- (point) 2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (defun backward-sexp (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 "Move backward across one balanced expression (sexp).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 With argument, do it that many times.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 Negative arg -N means move forward across N balanced expressions."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (interactive "_p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (or arg (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (forward-sexp (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (defun mark-sexp (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 "Set mark ARG sexps from point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 The place mark goes is the same place \\[forward-sexp] would move to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 with the same argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 Repeat this command to mark more sexps in the same direction."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (mark-something 'mark-sexp 'forward-sexp arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (defun forward-list (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 "Move forward across one balanced group of parentheses.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 With argument, do it that many times.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 Negative arg -N means move backward across N groups of parentheses."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (interactive "_p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (or arg (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (goto-char (or (scan-lists (point) arg 0) (buffer-end arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (defun backward-list (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 "Move backward across one balanced group of parentheses.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 With argument, do it that many times.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 Negative arg -N means move forward across N groups of parentheses."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (interactive "_p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (or arg (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (forward-list (- 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 down-list (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 "Move forward down one level of parentheses.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 With argument, do this that many times.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 A negative argument means move backward but still go down a level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 In Lisp programs, an argument is required."
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 (let ((inc (if (> arg 0) 1 -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (while (/= arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (goto-char (or (scan-lists (point) inc -1) (buffer-end arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (setq arg (- arg inc)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (defun backward-up-list (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 "Move backward out of one level of parentheses.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 With argument, do this that many times.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 A negative argument means move forward but still to a less deep spot.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 In Lisp programs, an argument is required."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (up-list (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (defun up-list (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 "Move forward out of one level of parentheses.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 With argument, do this that many times.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 A negative argument means move backward but still to a less deep spot.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 In Lisp programs, an argument is required."
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 kill-sexp (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 "Kill the sexp (balanced expression) following the cursor.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 With argument, kill that many sexps after the cursor.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 Negative arg -N means kill N sexps before the cursor."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (let ((opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (forward-sexp arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (kill-region opoint (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (defun backward-kill-sexp (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 "Kill the sexp (balanced expression) preceding the cursor.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 With argument, kill that many sexps before the cursor.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 Negative arg -N means kill N sexps after the cursor."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (kill-sexp (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (defun beginning-of-defun (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 "Move backward to the beginning of a defun.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 With argument, do it that many times. Negative arg -N
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 means move forward to Nth following beginning of defun.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 Returns t unless search stops due to beginning or end of buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 Normally a defun starts when there is an char with open-parenthesis
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 syntax at the beginning of a line. If `defun-prompt-regexp' is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 non-nil, then a string which matches that regexp may precede the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 open-parenthesis, and point ends up at the beginning of the line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (interactive "_p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (and (beginning-of-defun-raw arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (progn (beginning-of-line) t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (defun beginning-of-defun-raw (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 "Move point to the character that starts a defun.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 This is identical to beginning-of-defun, except that point does not move
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 to the beginning of the line when `defun-prompt-regexp' is non-nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (and arg (< arg 0) (not (eobp)) (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (and (re-search-backward (if defun-prompt-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (concat "^\\s(\\|"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 "\\(" defun-prompt-regexp "\\)\\s(")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 "^\\s(")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 nil 'move (or arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (progn (goto-char (1- (match-end 0)))) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (defun buffer-end (arg &optional buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 "Return `point-max' of BUFFER if ARG is > 0; return `point-min' otherwise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 BUFFER defaults to the current buffer if omitted."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (if (> arg 0) (point-max buffer) (point-min buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (defun end-of-defun (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 "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
174 Negative argument -N means move back to Nth preceding end of defun.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 An end of a defun occurs right after the close-parenthesis that matches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 the open-parenthesis that starts a defun; see `beginning-of-defun'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (interactive "_p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (if (or (null arg) (= arg 0)) (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (let ((first t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (while (and (> arg 0) (< (point) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (let ((pos (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (while (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (if (and first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (end-of-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (beginning-of-defun-raw 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (or (bobp) (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (beginning-of-defun-raw -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (setq first nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (forward-list 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (if (looking-at "\\s<\\|\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (<= (point) pos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (setq arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (while (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (let ((pos (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (beginning-of-defun-raw 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (if (>= (point) pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (if (beginning-of-defun-raw 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (forward-list 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (if (looking-at "\\s<\\|\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (goto-char (point-min)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (setq arg (1+ arg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (defun mark-defun ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 "Put mark at end of this defun, point at beginning.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 The defun marked is the one that contains point or follows point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (push-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (end-of-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (push-mark (point) nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (beginning-of-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (re-search-backward "^\n" (- (point) 1) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (defun insert-parentheses (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 "Put parentheses around next ARG sexps. Leave point after open-paren.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 No argument is equivalent to zero: just insert `()' and leave point between.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 If `parens-require-spaces' is non-nil, this command also inserts a space
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 before and after, depending on the surrounding characters."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (if arg (setq arg (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (setq arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (or (eq arg 0) (skip-chars-forward " \t"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (and parens-require-spaces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (not (bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (memq (char-syntax (preceding-char)) '(?w ?_ ?\) ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (insert " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (insert ?\()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (or (eq arg 0) (forward-sexp arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (insert ?\))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (and parens-require-spaces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (memq (char-syntax (following-char)) '(?w ?_ ?\( ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (insert " "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (defun move-past-close-and-reindent ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 "Move past next `)', delete indentation before it, then indent after it."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (up-list 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (while (save-excursion ; this is my contribution
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (let ((before-paren (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (= (point) before-paren)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (delete-indentation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (newline-and-indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (defun lisp-complete-symbol ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 "Perform completion on Lisp symbol preceding point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 That symbol is compared against the symbols that exist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 and any additional characters determined by what is there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 are inserted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 If the symbol starts just after an open-parenthesis,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 only symbols with function definitions are considered.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 Otherwise, all symbols with function definitions, values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 or properties are considered."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (let* ((end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (buffer-syntax (syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (beg (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (if emacs-lisp-mode-syntax-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (set-syntax-table emacs-lisp-mode-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (backward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (while (= (char-syntax (following-char)) ?\')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (set-syntax-table buffer-syntax)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (pattern (buffer-substring beg end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (predicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (if (eq (char-after (1- beg)) ?\()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 'fboundp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 #'(lambda (sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (or (boundp sym) (fboundp sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (symbol-plist sym)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (completion (try-completion pattern obarray predicate)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (cond ((eq completion t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 ((null completion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (message "Can't find completion for \"%s\"" pattern)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (ding))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 ((not (string= pattern completion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (delete-region beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (insert completion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (message "Making completion list...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (let ((list (all-completions pattern obarray predicate))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 ;FSFmacs crock unnecessary in XEmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 ;see minibuf.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 ;(completion-fixup-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 ; #'(lambda () (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 ; (goto-char (max (point-min)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 ; (- (point) 4)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 ; (looking-at " <f>"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 ; (forward-char -4))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (or (eq predicate 'fboundp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (let (new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (while list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (setq new (cons (if (fboundp (intern (car list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (list (car list) " <f>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (car list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 new))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (setq list (cdr list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (setq list (nreverse new))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (with-output-to-temp-buffer "*Completions*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (display-completion-list list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (message "Making completion list...done")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 ;;; lisp.el ends here