Mercurial > emacs
comparison lisp/emacs-lisp/lisp.el @ 99958:42c2049ff2f6
(forward-sexp, backward-sexp, mark-sexp)
(forward-list, backward-list, down-list, backward-up-list)
(up-list, kill-sexp, backward-kill-sexp, kill-backward-up-list)
(insert-pair, insert-parentheses): State that the
command assumes that point is not in a string or comment.
author | Alan Mackenzie <acm@muc.de> |
---|---|
date | Wed, 26 Nov 2008 10:30:53 +0000 |
parents | bcaacb72ee0e |
children | b1b204eafe54 |
comparison
equal
deleted
inserted
replaced
99957:c419b54d9ae6 | 99958:42c2049ff2f6 |
---|---|
49 Should take the same arguments and behave similarly to `forward-sexp'.") | 49 Should take the same arguments and behave similarly to `forward-sexp'.") |
50 | 50 |
51 (defun forward-sexp (&optional arg) | 51 (defun forward-sexp (&optional arg) |
52 "Move forward across one balanced expression (sexp). | 52 "Move forward across one balanced expression (sexp). |
53 With ARG, do it that many times. Negative arg -N means | 53 With ARG, do it that many times. Negative arg -N means |
54 move backward across N balanced expressions." | 54 move backward across N balanced expressions. |
55 (interactive "p") | 55 This command assumes point is not in a string or comment." |
56 (Interactive "p") | |
56 (or arg (setq arg 1)) | 57 (or arg (setq arg 1)) |
57 (if forward-sexp-function | 58 (if forward-sexp-function |
58 (funcall forward-sexp-function arg) | 59 (funcall forward-sexp-function arg) |
59 (goto-char (or (scan-sexps (point) arg) (buffer-end arg))) | 60 (goto-char (or (scan-sexps (point) arg) (buffer-end arg))) |
60 (if (< arg 0) (backward-prefix-chars)))) | 61 (if (< arg 0) (backward-prefix-chars)))) |
61 | 62 |
62 (defun backward-sexp (&optional arg) | 63 (defun backward-sexp (&optional arg) |
63 "Move backward across one balanced expression (sexp). | 64 "Move backward across one balanced expression (sexp). |
64 With ARG, do it that many times. Negative arg -N means | 65 With ARG, do it that many times. Negative arg -N means |
65 move forward across N balanced expressions." | 66 move forward across N balanced expressions. |
67 This command assumes point is not in a string or comment." | |
66 (interactive "p") | 68 (interactive "p") |
67 (or arg (setq arg 1)) | 69 (or arg (setq arg 1)) |
68 (forward-sexp (- arg))) | 70 (forward-sexp (- arg))) |
69 | 71 |
70 (defun mark-sexp (&optional arg allow-extend) | 72 (defun mark-sexp (&optional arg allow-extend) |
71 "Set mark ARG sexps from point. | 73 "Set mark ARG sexps from point. |
72 The place mark goes is the same place \\[forward-sexp] would | 74 The place mark goes is the same place \\[forward-sexp] would |
73 move to with the same argument. | 75 move to with the same argument. |
74 Interactively, if this command is repeated | 76 Interactively, if this command is repeated |
75 or (in Transient Mark mode) if the mark is active, | 77 or (in Transient Mark mode) if the mark is active, |
76 it marks the next ARG sexps after the ones already marked." | 78 it marks the next ARG sexps after the ones already marked. |
79 This command assumes point is not in a string or comment." | |
77 (interactive "P\np") | 80 (interactive "P\np") |
78 (cond ((and allow-extend | 81 (cond ((and allow-extend |
79 (or (and (eq last-command this-command) (mark t)) | 82 (or (and (eq last-command this-command) (mark t)) |
80 (and transient-mark-mode mark-active))) | 83 (and transient-mark-mode mark-active))) |
81 (setq arg (if arg (prefix-numeric-value arg) | 84 (setq arg (if arg (prefix-numeric-value arg) |
93 nil t)))) | 96 nil t)))) |
94 | 97 |
95 (defun forward-list (&optional arg) | 98 (defun forward-list (&optional arg) |
96 "Move forward across one balanced group of parentheses. | 99 "Move forward across one balanced group of parentheses. |
97 With ARG, do it that many times. | 100 With ARG, do it that many times. |
98 Negative arg -N means move backward across N groups of parentheses." | 101 Negative arg -N means move backward across N groups of parentheses. |
102 This command assumes point is not in a string or comment." | |
99 (interactive "p") | 103 (interactive "p") |
100 (or arg (setq arg 1)) | 104 (or arg (setq arg 1)) |
101 (goto-char (or (scan-lists (point) arg 0) (buffer-end arg)))) | 105 (goto-char (or (scan-lists (point) arg 0) (buffer-end arg)))) |
102 | 106 |
103 (defun backward-list (&optional arg) | 107 (defun backward-list (&optional arg) |
104 "Move backward across one balanced group of parentheses. | 108 "Move backward across one balanced group of parentheses. |
105 With ARG, do it that many times. | 109 With ARG, do it that many times. |
106 Negative arg -N means move forward across N groups of parentheses." | 110 Negative arg -N means move forward across N groups of parentheses. |
111 This command assumes point is not in a string or comment." | |
107 (interactive "p") | 112 (interactive "p") |
108 (or arg (setq arg 1)) | 113 (or arg (setq arg 1)) |
109 (forward-list (- arg))) | 114 (forward-list (- arg))) |
110 | 115 |
111 (defun down-list (&optional arg) | 116 (defun down-list (&optional arg) |
112 "Move forward down one level of parentheses. | 117 "Move forward down one level of parentheses. |
113 With ARG, do this that many times. | 118 With ARG, do this that many times. |
114 A negative argument means move backward but still go down a level." | 119 A negative argument means move backward but still go down a level. |
120 This command assumes point is not in a string or comment." | |
115 (interactive "p") | 121 (interactive "p") |
116 (or arg (setq arg 1)) | 122 (or arg (setq arg 1)) |
117 (let ((inc (if (> arg 0) 1 -1))) | 123 (let ((inc (if (> arg 0) 1 -1))) |
118 (while (/= arg 0) | 124 (while (/= arg 0) |
119 (goto-char (or (scan-lists (point) inc -1) (buffer-end arg))) | 125 (goto-char (or (scan-lists (point) inc -1) (buffer-end arg))) |
120 (setq arg (- arg inc))))) | 126 (setq arg (- arg inc))))) |
121 | 127 |
122 (defun backward-up-list (&optional arg) | 128 (defun backward-up-list (&optional arg) |
123 "Move backward out of one level of parentheses. | 129 "Move backward out of one level of parentheses. |
124 With ARG, do this that many times. | 130 With ARG, do this that many times. |
125 A negative argument means move forward but still to a less deep spot." | 131 A negative argument means move forward but still to a less deep spot. |
132 This command assumes point is not in a string or comment." | |
126 (interactive "p") | 133 (interactive "p") |
127 (up-list (- (or arg 1)))) | 134 (up-list (- (or arg 1)))) |
128 | 135 |
129 (defun up-list (&optional arg) | 136 (defun up-list (&optional arg) |
130 "Move forward out of one level of parentheses. | 137 "Move forward out of one level of parentheses. |
131 With ARG, do this that many times. | 138 With ARG, do this that many times. |
132 A negative argument means move backward but still to a less deep spot." | 139 A negative argument means move backward but still to a less deep spot. |
140 This command assumes point is not in a string or comment." | |
133 (interactive "p") | 141 (interactive "p") |
134 (or arg (setq arg 1)) | 142 (or arg (setq arg 1)) |
135 (let ((inc (if (> arg 0) 1 -1))) | 143 (let ((inc (if (> arg 0) 1 -1))) |
136 (while (/= arg 0) | 144 (while (/= arg 0) |
137 (goto-char (or (scan-lists (point) inc 1) (buffer-end arg))) | 145 (goto-char (or (scan-lists (point) inc 1) (buffer-end arg))) |
138 (setq arg (- arg inc))))) | 146 (setq arg (- arg inc))))) |
139 | 147 |
140 (defun kill-sexp (&optional arg) | 148 (defun kill-sexp (&optional arg) |
141 "Kill the sexp (balanced expression) following point. | 149 "Kill the sexp (balanced expression) following point. |
142 With ARG, kill that many sexps after point. | 150 With ARG, kill that many sexps after point. |
143 Negative arg -N means kill N sexps before point." | 151 Negative arg -N means kill N sexps before point. |
152 This command assumes point is not in a string or comment." | |
144 (interactive "p") | 153 (interactive "p") |
145 (let ((opoint (point))) | 154 (let ((opoint (point))) |
146 (forward-sexp (or arg 1)) | 155 (forward-sexp (or arg 1)) |
147 (kill-region opoint (point)))) | 156 (kill-region opoint (point)))) |
148 | 157 |
149 (defun backward-kill-sexp (&optional arg) | 158 (defun backward-kill-sexp (&optional arg) |
150 "Kill the sexp (balanced expression) preceding point. | 159 "Kill the sexp (balanced expression) preceding point. |
151 With ARG, kill that many sexps before point. | 160 With ARG, kill that many sexps before point. |
152 Negative arg -N means kill N sexps after point." | 161 Negative arg -N means kill N sexps after point. |
162 This command assumes point is not in a string or comment." | |
153 (interactive "p") | 163 (interactive "p") |
154 (kill-sexp (- (or arg 1)))) | 164 (kill-sexp (- (or arg 1)))) |
155 | 165 |
156 ;; After Zmacs: | 166 ;; After Zmacs: |
157 (defun kill-backward-up-list (&optional arg) | 167 (defun kill-backward-up-list (&optional arg) |
158 "Kill the form containing the current sexp, leaving the sexp itself. | 168 "Kill the form containing the current sexp, leaving the sexp itself. |
159 A prefix argument ARG causes the relevant number of surrounding | 169 A prefix argument ARG causes the relevant number of surrounding |
160 forms to be removed." | 170 forms to be removed. |
171 This command assumes point is not in a string or comment." | |
161 (interactive "*p") | 172 (interactive "*p") |
162 (let ((current-sexp (thing-at-point 'sexp))) | 173 (let ((current-sexp (thing-at-point 'sexp))) |
163 (if current-sexp | 174 (if current-sexp |
164 (save-excursion | 175 (save-excursion |
165 (backward-up-list arg) | 176 (backward-up-list arg) |
456 | 467 |
457 If arguments OPEN and CLOSE are nil, the character pair is found | 468 If arguments OPEN and CLOSE are nil, the character pair is found |
458 from the variable `insert-pair-alist' according to the last input | 469 from the variable `insert-pair-alist' according to the last input |
459 character with or without modifiers. If no character pair is | 470 character with or without modifiers. If no character pair is |
460 found in the variable `insert-pair-alist', then the last input | 471 found in the variable `insert-pair-alist', then the last input |
461 character is inserted ARG times." | 472 character is inserted ARG times. |
473 | |
474 This command assumes point is not in a string or comment." | |
462 (interactive "P") | 475 (interactive "P") |
463 (if (not (and open close)) | 476 (if (not (and open close)) |
464 (let ((pair (or (assq last-command-char insert-pair-alist) | 477 (let ((pair (or (assq last-command-char insert-pair-alist) |
465 (assq (event-basic-type last-command-event) | 478 (assq (event-basic-type last-command-event) |
466 insert-pair-alist)))) | 479 insert-pair-alist)))) |
497 Leave point after open-paren. | 510 Leave point after open-paren. |
498 A negative ARG encloses the preceding ARG sexps instead. | 511 A negative ARG encloses the preceding ARG sexps instead. |
499 No argument is equivalent to zero: just insert `()' and leave point between. | 512 No argument is equivalent to zero: just insert `()' and leave point between. |
500 If `parens-require-spaces' is non-nil, this command also inserts a space | 513 If `parens-require-spaces' is non-nil, this command also inserts a space |
501 before and after, depending on the surrounding characters. | 514 before and after, depending on the surrounding characters. |
502 If region is active, insert enclosing characters at region boundaries." | 515 If region is active, insert enclosing characters at region boundaries. |
516 | |
517 This command assumes point is not in a string or comment." | |
503 (interactive "P") | 518 (interactive "P") |
504 (insert-pair arg ?\( ?\))) | 519 (insert-pair arg ?\( ?\))) |
505 | 520 |
506 (defun delete-pair () | 521 (defun delete-pair () |
507 "Delete a pair of characters enclosing the sexp that follows point." | 522 "Delete a pair of characters enclosing the sexp that follows point." |