diff options
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/electric.el | 45 |
2 files changed, 28 insertions, 22 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index cd073cdb985..3f47c077f5c 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2014-05-09 Philipp Rumpf <prumpf@gmail.com> (tiny change) | ||
| 2 | |||
| 3 | * electric.el (electric-indent-post-self-insert-function): Don't use | ||
| 4 | `pos' after modifying the buffer (bug#17449). | ||
| 5 | |||
| 1 | 2014-05-09 Stefan Monnier <monnier@iro.umontreal.ca> | 6 | 2014-05-09 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 7 | ||
| 3 | * subr.el (function-put): Add function. | 8 | * subr.el (function-put): Add function. |
diff --git a/lisp/electric.el b/lisp/electric.el index e8ceaa6406c..bf73dbb256f 100644 --- a/lisp/electric.el +++ b/lisp/electric.el | |||
| @@ -259,29 +259,30 @@ or comment." | |||
| 259 | (unless (eq act 'do-indent) (nth 8 (syntax-ppss)))))))) | 259 | (unless (eq act 'do-indent) (nth 8 (syntax-ppss)))))))) |
| 260 | ;; For newline, we want to reindent both lines and basically behave like | 260 | ;; For newline, we want to reindent both lines and basically behave like |
| 261 | ;; reindent-then-newline-and-indent (whose code we hence copied). | 261 | ;; reindent-then-newline-and-indent (whose code we hence copied). |
| 262 | (when (<= pos (line-beginning-position)) | 262 | (let ((at-newline (<= pos (line-beginning-position)))) |
| 263 | (let ((before (copy-marker (1- pos) t))) | 263 | (when at-newline |
| 264 | (save-excursion | 264 | (let ((before (copy-marker (1- pos) t))) |
| 265 | (unless (or (memq indent-line-function | 265 | (save-excursion |
| 266 | electric-indent-functions-without-reindent) | 266 | (unless (or (memq indent-line-function |
| 267 | electric-indent-inhibit) | 267 | electric-indent-functions-without-reindent) |
| 268 | ;; Don't reindent the previous line if the indentation function | 268 | electric-indent-inhibit) |
| 269 | ;; is not a real one. | 269 | ;; Don't reindent the previous line if the indentation function |
| 270 | ;; is not a real one. | ||
| 271 | (goto-char before) | ||
| 272 | (indent-according-to-mode)) | ||
| 273 | ;; We are at EOL before the call to indent-according-to-mode, and | ||
| 274 | ;; after it we usually are as well, but not always. We tried to | ||
| 275 | ;; address it with `save-excursion' but that uses a normal marker | ||
| 276 | ;; whereas we need `move after insertion', so we do the | ||
| 277 | ;; save/restore by hand. | ||
| 270 | (goto-char before) | 278 | (goto-char before) |
| 271 | (indent-according-to-mode)) | 279 | (when (eolp) |
| 272 | ;; We are at EOL before the call to indent-according-to-mode, and | 280 | ;; Remove the trailing whitespace after indentation because |
| 273 | ;; after it we usually are as well, but not always. We tried to | 281 | ;; indentation may (re)introduce the whitespace. |
| 274 | ;; address it with `save-excursion' but that uses a normal marker | 282 | (delete-horizontal-space t))))) |
| 275 | ;; whereas we need `move after insertion', so we do the | 283 | (unless (and electric-indent-inhibit |
| 276 | ;; save/restore by hand. | 284 | (not at-newline)) |
| 277 | (goto-char before) | 285 | (indent-according-to-mode)))))) |
| 278 | (when (eolp) | ||
| 279 | ;; Remove the trailing whitespace after indentation because | ||
| 280 | ;; indentation may (re)introduce the whitespace. | ||
| 281 | (delete-horizontal-space t))))) | ||
| 282 | (unless (and electric-indent-inhibit | ||
| 283 | (> pos (line-beginning-position))) | ||
| 284 | (indent-according-to-mode))))) | ||
| 285 | 286 | ||
| 286 | (put 'electric-indent-post-self-insert-function 'priority 60) | 287 | (put 'electric-indent-post-self-insert-function 'priority 60) |
| 287 | 288 | ||