diff options
| author | Stefan Monnier | 2010-11-12 08:33:44 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2010-11-12 08:33:44 -0500 |
| commit | 4490f87580a8f9ade324ea1d3a095dddca8ecf1d (patch) | |
| tree | 7b4531540354aaec750d7902498825e72c60739f | |
| parent | c156a63bb337b2bc2ce19b06e0175fbd75a790cc (diff) | |
| download | emacs-4490f87580a8f9ade324ea1d3a095dddca8ecf1d.tar.gz emacs-4490f87580a8f9ade324ea1d3a095dddca8ecf1d.zip | |
* lisp/skeleton.el (skeleton-newline): New function.
(skeleton-internal-1): Use it.
(skeleton-read): Don't use `newline' since it may strip trailing space.
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/skeleton.el | 19 |
2 files changed, 21 insertions, 3 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 46eacc2de31..64c52eebc7b 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,10 @@ | |||
| 1 | 2010-11-12 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2010-11-12 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * skeleton.el (skeleton-read): Don't use `newline' since it may strip | ||
| 4 | trailing space. | ||
| 5 | (skeleton-newline): New function. | ||
| 6 | (skeleton-internal-1): Use it. | ||
| 7 | |||
| 3 | * simple.el (open-line): `newline' may strip trailing space. | 8 | * simple.el (open-line): `newline' may strip trailing space. |
| 4 | 9 | ||
| 5 | 2010-11-12 Kevin Ryde <user42@zip.com.au> | 10 | 2010-11-12 Kevin Ryde <user42@zip.com.au> |
diff --git a/lisp/skeleton.el b/lisp/skeleton.el index c98e06fe76f..0c3e0e8c413 100644 --- a/lisp/skeleton.el +++ b/lisp/skeleton.el | |||
| @@ -299,7 +299,10 @@ automatically, and you are prompted to fill in the variable parts."))) | |||
| 299 | (eolp (eolp))) | 299 | (eolp (eolp))) |
| 300 | ;; since Emacs doesn't show main window's cursor, do something noticeable | 300 | ;; since Emacs doesn't show main window's cursor, do something noticeable |
| 301 | (or eolp | 301 | (or eolp |
| 302 | (open-line 1)) | 302 | ;; We used open-line before, but that can do a lot more than we want, |
| 303 | ;; since it runs self-insert-command. E.g. it may remove spaces | ||
| 304 | ;; before point. | ||
| 305 | (save-excursion (insert "\n"))) | ||
| 303 | (unwind-protect | 306 | (unwind-protect |
| 304 | (setq prompt (if (stringp prompt) | 307 | (setq prompt (if (stringp prompt) |
| 305 | (read-string (format prompt skeleton-subprompt) | 308 | (read-string (format prompt skeleton-subprompt) |
| @@ -352,6 +355,16 @@ automatically, and you are prompted to fill in the variable parts."))) | |||
| 352 | (signal 'quit 'recursive) | 355 | (signal 'quit 'recursive) |
| 353 | recursive)) | 356 | recursive)) |
| 354 | 357 | ||
| 358 | (defun skeleton-newline () | ||
| 359 | (if (or (eq (point) skeleton-point) | ||
| 360 | (eq (point) (car skeleton-positions))) | ||
| 361 | ;; If point is recorded, avoid `newline' since it may do things like | ||
| 362 | ;; strip trailing spaces, and since recorded points are commonly placed | ||
| 363 | ;; right after a trailing space, calling `newline' can destroy the | ||
| 364 | ;; position and renders the recorded position incorrect. | ||
| 365 | (insert "\n") | ||
| 366 | (newline))) | ||
| 367 | |||
| 355 | (defun skeleton-internal-1 (element &optional literal recursive) | 368 | (defun skeleton-internal-1 (element &optional literal recursive) |
| 356 | (cond | 369 | (cond |
| 357 | ((or (integerp element) (stringp element)) | 370 | ((or (integerp element) (stringp element)) |
| @@ -379,13 +392,13 @@ automatically, and you are prompted to fill in the variable parts."))) | |||
| 379 | (if pos (indent-according-to-mode))) | 392 | (if pos (indent-according-to-mode))) |
| 380 | (skeleton-newline-indent-rigidly | 393 | (skeleton-newline-indent-rigidly |
| 381 | (let ((pt (point))) | 394 | (let ((pt (point))) |
| 382 | (newline) | 395 | (skeleton-newline) |
| 383 | (indent-to (save-excursion | 396 | (indent-to (save-excursion |
| 384 | (goto-char pt) | 397 | (goto-char pt) |
| 385 | (if pos (indent-according-to-mode)) | 398 | (if pos (indent-according-to-mode)) |
| 386 | (current-indentation))))) | 399 | (current-indentation))))) |
| 387 | (t (if pos (reindent-then-newline-and-indent) | 400 | (t (if pos (reindent-then-newline-and-indent) |
| 388 | (newline) | 401 | (skeleton-newline) |
| 389 | (indent-according-to-mode)))))) | 402 | (indent-according-to-mode)))))) |
| 390 | ((eq element '>) | 403 | ((eq element '>) |
| 391 | (if (and skeleton-regions (eq (nth 1 skeleton-il) '_)) | 404 | (if (and skeleton-regions (eq (nth 1 skeleton-il) '_)) |