diff options
| author | Stefan Monnier | 2003-05-23 00:59:12 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2003-05-23 00:59:12 +0000 |
| commit | 8fb7ff735cfa4760d9bd43f5e142d5e2547364f2 (patch) | |
| tree | 0ed947a9b9f92d77aafbdc90d2c2594d47490998 | |
| parent | 9ac97b346fdaf7938b8eac21dead8195c35d20d0 (diff) | |
| download | emacs-8fb7ff735cfa4760d9bd43f5e142d5e2547364f2.tar.gz emacs-8fb7ff735cfa4760d9bd43f5e142d5e2547364f2.zip | |
(define-skeleton): Use the `no-self-insert' property.
(skeleton-proxy-new): Fix docstring. Remove broken interactive spec.
Rely on use `no-self-insert' rather than `skeleton-abbrev-cleanup'.
(skeleton-internal-1): Add a `recursive' argument.
(skeleton-internal-list): Use it to propagate `recursive'.
| -rw-r--r-- | lisp/skeleton.el | 96 |
1 files changed, 42 insertions, 54 deletions
diff --git a/lisp/skeleton.el b/lisp/skeleton.el index 17acbbe4f20..6ba478f708e 100644 --- a/lisp/skeleton.el +++ b/lisp/skeleton.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; skeleton.el --- Lisp language extension for writing statement skeletons | 1 | ;;; skeleton.el --- Lisp language extension for writing statement skeletons |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1993, 1994, 1995, 1996 by Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1993, 1994, 1995, 1996, 2003 by Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: Daniel Pfeiffer <occitan@esperanto.org> | 5 | ;; Author: Daniel Pfeiffer <occitan@esperanto.org> |
| 6 | ;; Maintainer: FSF | 6 | ;; Maintainer: FSF |
| @@ -119,15 +119,17 @@ are integer buffer positions in the reverse order of the insertion order.") | |||
| 119 | ;;;###autoload | 119 | ;;;###autoload |
| 120 | (defmacro define-skeleton (command documentation &rest skeleton) | 120 | (defmacro define-skeleton (command documentation &rest skeleton) |
| 121 | "Define a user-configurable COMMAND that enters a statement skeleton. | 121 | "Define a user-configurable COMMAND that enters a statement skeleton. |
| 122 | DOCUMENTATION is that of the command, while the variable of the same name, | 122 | DOCUMENTATION is that of the command. |
| 123 | which contains the skeleton, has a documentation to that effect. | 123 | SKELETON is as defined under `skeleton-insert'." |
| 124 | INTERACTOR and ELEMENT ... are as defined under `skeleton-insert'." | ||
| 125 | (if skeleton-debug | 124 | (if skeleton-debug |
| 126 | (set command skeleton)) | 125 | (set command skeleton)) |
| 127 | `(progn | 126 | `(progn |
| 127 | ;; Tell self-insert-command that this function, if called by an | ||
| 128 | ;; abbrev, should cause the self-insert to be skipped. | ||
| 129 | (put ',command 'no-self-insert t) | ||
| 128 | (defun ,command (&optional str arg) | 130 | (defun ,command (&optional str arg) |
| 129 | ,(concat documentation | 131 | ,(concat documentation |
| 130 | (if (string-match "\n\\>" documentation) | 132 | (if (string-match "\n\\'" documentation) |
| 131 | "" "\n") | 133 | "" "\n") |
| 132 | "\n" | 134 | "\n" |
| 133 | "This is a skeleton command (see `skeleton-insert'). | 135 | "This is a skeleton command (see `skeleton-insert'). |
| @@ -144,42 +146,29 @@ This is a way of overriding the use of a highlighted region.") | |||
| 144 | 146 | ||
| 145 | ;;;###autoload | 147 | ;;;###autoload |
| 146 | (defun skeleton-proxy-new (skeleton &optional str arg) | 148 | (defun skeleton-proxy-new (skeleton &optional str arg) |
| 147 | "Insert skeleton defined by variable of same name (see `skeleton-insert'). | 149 | "Insert SKELETON. |
| 148 | Prefix ARG allows wrapping around words or regions (see `skeleton-insert'). | 150 | Prefix ARG allows wrapping around words or regions (see `skeleton-insert'). |
| 149 | If no ARG was given, but the region is visible, ARG defaults to -1 depending | 151 | If no ARG was given, but the region is visible, ARG defaults to -1 depending |
| 150 | on `skeleton-autowrap'. An ARG of M-0 will prevent this just for once. | 152 | on `skeleton-autowrap'. An ARG of M-0 will prevent this just for once. |
| 151 | This command can also be an abbrev expansion (3rd and 4th columns in | 153 | This command can also be an abbrev expansion (3rd and 4th columns in |
| 152 | \\[edit-abbrevs] buffer: \"\" command-name). | 154 | \\[edit-abbrevs] buffer: \"\" command-name). |
| 153 | 155 | ||
| 154 | When called as a function, optional first argument STR may also be a string | 156 | Optional first argument STR may also be a string which will be the value |
| 155 | which will be the value of `str' whereas the skeleton's interactor is then | 157 | of `str' whereas the skeleton's interactor is then ignored." |
| 156 | ignored." | 158 | (skeleton-insert (funcall skeleton-filter skeleton) |
| 157 | (interactive "*P\nP") | 159 | ;; Pretend C-x a e passed its prefix arg to us |
| 158 | (setq skeleton (funcall skeleton-filter skeleton)) | 160 | (if (or arg current-prefix-arg) |
| 159 | (if (not skeleton) | 161 | (prefix-numeric-value (or arg |
| 160 | (if (memq this-command '(self-insert-command | 162 | current-prefix-arg)) |
| 161 | skeleton-pair-insert-maybe | 163 | (and skeleton-autowrap |
| 162 | expand-abbrev)) | 164 | (or (eq last-command 'mouse-drag-region) |
| 163 | (setq buffer-undo-list (primitive-undo 1 buffer-undo-list))) | 165 | (and transient-mark-mode mark-active)) |
| 164 | (skeleton-insert skeleton | 166 | -1)) |
| 165 | (if (setq skeleton-abbrev-cleanup | 167 | (if (stringp str) |
| 166 | (or (eq this-command 'self-insert-command) | 168 | str)) |
| 167 | (eq this-command | 169 | ;; Return non-nil to tell expand-abbrev that expansion has happened. |
| 168 | 'skeleton-pair-insert-maybe))) | 170 | ;; Otherwise the no-self-insert is ignored. |
| 169 | () | 171 | t) |
| 170 | ;; Pretend C-x a e passed its prefix arg to us | ||
| 171 | (if (or arg current-prefix-arg) | ||
| 172 | (prefix-numeric-value (or arg | ||
| 173 | current-prefix-arg)) | ||
| 174 | (and skeleton-autowrap | ||
| 175 | (or (eq last-command 'mouse-drag-region) | ||
| 176 | (and transient-mark-mode mark-active)) | ||
| 177 | -1))) | ||
| 178 | (if (stringp str) | ||
| 179 | str)) | ||
| 180 | (and skeleton-abbrev-cleanup | ||
| 181 | (setq skeleton-abbrev-cleanup (point)) | ||
| 182 | (add-hook 'post-command-hook 'skeleton-abbrev-cleanup nil t)))) | ||
| 183 | 172 | ||
| 184 | ;; This command isn't meant to be called, only its aliases with meaningful | 173 | ;; This command isn't meant to be called, only its aliases with meaningful |
| 185 | ;; names are. | 174 | ;; names are. |
| @@ -390,7 +379,7 @@ automatically, and you are prompted to fill in the variable parts."))) | |||
| 390 | opoint (point) | 379 | opoint (point) |
| 391 | skeleton (cdr skeleton)) | 380 | skeleton (cdr skeleton)) |
| 392 | (condition-case quit | 381 | (condition-case quit |
| 393 | (skeleton-internal-1 (car skeleton)) | 382 | (skeleton-internal-1 (car skeleton) nil recursive) |
| 394 | (quit | 383 | (quit |
| 395 | (if (eq (cdr quit) 'recursive) | 384 | (if (eq (cdr quit) 'recursive) |
| 396 | (setq recursive 'quit | 385 | (setq recursive 'quit |
| @@ -410,7 +399,7 @@ automatically, and you are prompted to fill in the variable parts."))) | |||
| 410 | (signal 'quit 'recursive) | 399 | (signal 'quit 'recursive) |
| 411 | recursive)) | 400 | recursive)) |
| 412 | 401 | ||
| 413 | (defun skeleton-internal-1 (element &optional literal) | 402 | (defun skeleton-internal-1 (element &optional literal recursive) |
| 414 | (cond | 403 | (cond |
| 415 | ((char-or-string-p element) | 404 | ((char-or-string-p element) |
| 416 | (if (and (integerp element) ; -num | 405 | (if (and (integerp element) ; -num |
| @@ -418,8 +407,7 @@ automatically, and you are prompted to fill in the variable parts."))) | |||
| 418 | (if skeleton-untabify | 407 | (if skeleton-untabify |
| 419 | (backward-delete-char-untabify (- element)) | 408 | (backward-delete-char-untabify (- element)) |
| 420 | (delete-backward-char (- element))) | 409 | (delete-backward-char (- element))) |
| 421 | (insert (if (and skeleton-transformation | 410 | (insert (if (not literal) |
| 422 | (not literal)) | ||
| 423 | (funcall skeleton-transformation element) | 411 | (funcall skeleton-transformation element) |
| 424 | element)))) | 412 | element)))) |
| 425 | ((or (eq element '\n) ; actually (eq '\n 'n) | 413 | ((or (eq element '\n) ; actually (eq '\n 'n) |
| @@ -457,20 +445,20 @@ automatically, and you are prompted to fill in the variable parts."))) | |||
| 457 | (goto-char (pop skeleton-regions)) | 445 | (goto-char (pop skeleton-regions)) |
| 458 | (and (<= (current-column) (current-indentation)) | 446 | (and (<= (current-column) (current-indentation)) |
| 459 | (eq (nth 1 skeleton) '\n) | 447 | (eq (nth 1 skeleton) '\n) |
| 460 | (end-of-line 0))) | 448 | (end-of-line 0))) |
| 461 | (or skeleton-point | 449 | (or skeleton-point |
| 462 | (setq skeleton-point (point))))) | 450 | (setq skeleton-point (point))))) |
| 463 | ((eq element '-) | 451 | ((eq element '-) |
| 464 | (setq skeleton-point (point))) | 452 | (setq skeleton-point (point))) |
| 465 | ((eq element '&) | 453 | ((eq element '&) |
| 466 | (when skeleton-modified (pop skeleton))) | 454 | (when skeleton-modified (pop skeleton))) |
| 467 | ((eq element '|) | 455 | ((eq element '|) |
| 468 | (unless skeleton-modified (pop skeleton))) | 456 | (unless skeleton-modified (pop skeleton))) |
| 469 | ((eq element '@) | 457 | ((eq element '@) |
| 470 | (push (point) skeleton-positions)) | 458 | (push (point) skeleton-positions)) |
| 471 | ((eq 'quote (car-safe element)) | 459 | ((eq 'quote (car-safe element)) |
| 472 | (eval (nth 1 element))) | 460 | (eval (nth 1 element))) |
| 473 | ((or (stringp (car-safe element)) | 461 | ((or (stringp (car-safe element)) |
| 474 | (consp (car-safe element))) | 462 | (consp (car-safe element))) |
| 475 | (if (symbolp (car-safe (car element))) | 463 | (if (symbolp (car-safe (car element))) |
| 476 | (while (skeleton-internal-list element nil t)) | 464 | (while (skeleton-internal-list element nil t)) |
| @@ -479,7 +467,7 @@ automatically, and you are prompted to fill in the variable parts."))) | |||
| 479 | (skeleton-internal-list element (car literal)) | 467 | (skeleton-internal-list element (car literal)) |
| 480 | (setq literal (cdr literal))))) | 468 | (setq literal (cdr literal))))) |
| 481 | ((null element)) | 469 | ((null element)) |
| 482 | (t (skeleton-internal-1 (eval element) t)))) | 470 | (t (skeleton-internal-1 (eval element) t recursive)))) |
| 483 | 471 | ||
| 484 | ;; Maybe belongs into simple.el or elsewhere | 472 | ;; Maybe belongs into simple.el or elsewhere |
| 485 | ;; ;;;###autoload | 473 | ;; ;;;###autoload |