diff options
| author | Juri Linkov | 2004-05-01 03:58:43 +0000 |
|---|---|---|
| committer | Juri Linkov | 2004-05-01 03:58:43 +0000 |
| commit | 5891bf24d99843c76f56ec6f540b98d83d942426 (patch) | |
| tree | 158d9b7046c0c32336e6a3802d0478e0405643d3 | |
| parent | bdd9ab6e687fe884a7d905d25fe62d73521c79df (diff) | |
| download | emacs-5891bf24d99843c76f56ec6f540b98d83d942426.tar.gz emacs-5891bf24d99843c76f56ec6f540b98d83d942426.zip | |
(beginning-of-defun, end-of-defun):
Push mark on the first call of successive command calls.
(insert-pair): New fun created from `insert-parentheses' with
`open' and `close' arguments added. Enclose active regions
in paired characters. Compare adjacent characters syntax with
inserted characters syntax before inserting a space.
(insert-parentheses): Call `insert-pair' with ?\( ?\).
| -rw-r--r-- | lisp/emacs-lisp/lisp.el | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el index e1ed508b865..8fe839b474d 100644 --- a/lisp/emacs-lisp/lisp.el +++ b/lisp/emacs-lisp/lisp.el | |||
| @@ -175,6 +175,8 @@ open-parenthesis, and point ends up at the beginning of the line. | |||
| 175 | If variable `beginning-of-defun-function' is non-nil, its value | 175 | If variable `beginning-of-defun-function' is non-nil, its value |
| 176 | is called as a function to find the defun's beginning." | 176 | is called as a function to find the defun's beginning." |
| 177 | (interactive "p") | 177 | (interactive "p") |
| 178 | (and (eq this-command 'beginning-of-defun) | ||
| 179 | (or (eq last-command 'beginning-of-defun) (push-mark))) | ||
| 178 | (and (beginning-of-defun-raw arg) | 180 | (and (beginning-of-defun-raw arg) |
| 179 | (progn (beginning-of-line) t))) | 181 | (progn (beginning-of-line) t))) |
| 180 | 182 | ||
| @@ -223,6 +225,8 @@ matches the open-parenthesis that starts a defun; see function | |||
| 223 | If variable `end-of-defun-function' is non-nil, its value | 225 | If variable `end-of-defun-function' is non-nil, its value |
| 224 | is called as a function to find the defun's end." | 226 | is called as a function to find the defun's end." |
| 225 | (interactive "p") | 227 | (interactive "p") |
| 228 | (and (eq this-command 'end-of-defun) | ||
| 229 | (or (eq last-command 'end-of-defun) (push-mark))) | ||
| 226 | (if (or (null arg) (= arg 0)) (setq arg 1)) | 230 | (if (or (null arg) (= arg 0)) (setq arg 1)) |
| 227 | (if end-of-defun-function | 231 | (if end-of-defun-function |
| 228 | (if (> arg 0) | 232 | (if (> arg 0) |
| @@ -302,29 +306,48 @@ Optional ARG is ignored." | |||
| 302 | (end-of-defun) | 306 | (end-of-defun) |
| 303 | (narrow-to-region beg (point))))) | 307 | (narrow-to-region beg (point))))) |
| 304 | 308 | ||
| 305 | (defun insert-parentheses (arg) | 309 | (defun insert-pair (arg &optional open close) |
| 306 | "Enclose following ARG sexps in parentheses. Leave point after open-paren. | 310 | "Enclose following ARG sexps in a pair of OPEN and CLOSE characters. |
| 311 | Leave point after the first character. | ||
| 307 | A negative ARG encloses the preceding ARG sexps instead. | 312 | A negative ARG encloses the preceding ARG sexps instead. |
| 308 | No argument is equivalent to zero: just insert `()' and leave point between. | 313 | No argument is equivalent to zero: just insert characters |
| 314 | and leave point between. | ||
| 309 | If `parens-require-spaces' is non-nil, this command also inserts a space | 315 | If `parens-require-spaces' is non-nil, this command also inserts a space |
| 310 | before and after, depending on the surrounding characters." | 316 | before and after, depending on the surrounding characters. |
| 317 | If region is active, insert enclosing characters at region boundaries." | ||
| 311 | (interactive "P") | 318 | (interactive "P") |
| 312 | (if arg (setq arg (prefix-numeric-value arg)) | 319 | (if arg (setq arg (prefix-numeric-value arg)) |
| 313 | (setq arg 0)) | 320 | (setq arg 0)) |
| 314 | (cond ((> arg 0) (skip-chars-forward " \t")) | 321 | (or open (setq open ?\()) |
| 315 | ((< arg 0) (forward-sexp arg) (setq arg (- arg)))) | 322 | (or close (setq close ?\))) |
| 316 | (and parens-require-spaces | 323 | (if (and transient-mark-mode mark-active) |
| 317 | (not (bobp)) | 324 | (progn |
| 318 | (memq (char-syntax (preceding-char)) '(?w ?_ ?\) )) | 325 | (save-excursion (goto-char (region-end)) (insert close)) |
| 319 | (insert " ")) | 326 | (save-excursion (goto-char (region-beginning)) (insert open))) |
| 320 | (insert ?\() | 327 | (cond ((> arg 0) (skip-chars-forward " \t")) |
| 321 | (save-excursion | 328 | ((< arg 0) (forward-sexp arg) (setq arg (- arg)))) |
| 322 | (or (eq arg 0) (forward-sexp arg)) | ||
| 323 | (insert ?\)) | ||
| 324 | (and parens-require-spaces | 329 | (and parens-require-spaces |
| 325 | (not (eobp)) | 330 | (not (bobp)) |
| 326 | (memq (char-syntax (following-char)) '(?w ?_ ?\( )) | 331 | (memq (char-syntax (preceding-char)) (list ?w ?_ (char-syntax close))) |
| 327 | (insert " ")))) | 332 | (insert " ")) |
| 333 | (insert open) | ||
| 334 | (save-excursion | ||
| 335 | (or (eq arg 0) (forward-sexp arg)) | ||
| 336 | (insert close) | ||
| 337 | (and parens-require-spaces | ||
| 338 | (not (eobp)) | ||
| 339 | (memq (char-syntax (following-char)) (list ?w ?_ (char-syntax open))) | ||
| 340 | (insert " "))))) | ||
| 341 | |||
| 342 | (defun insert-parentheses (arg) | ||
| 343 | "Enclose following ARG sexps in parentheses. Leave point after open-paren. | ||
| 344 | A negative ARG encloses the preceding ARG sexps instead. | ||
| 345 | No argument is equivalent to zero: just insert `()' and leave point between. | ||
| 346 | If `parens-require-spaces' is non-nil, this command also inserts a space | ||
| 347 | before and after, depending on the surrounding characters. | ||
| 348 | If region is active, insert enclosing characters at region boundaries." | ||
| 349 | (interactive "P") | ||
| 350 | (insert-pair arg ?\( ?\))) | ||
| 328 | 351 | ||
| 329 | (defun move-past-close-and-reindent () | 352 | (defun move-past-close-and-reindent () |
| 330 | "Move past next `)', delete indentation before it, then indent after it." | 353 | "Move past next `)', delete indentation before it, then indent after it." |