diff options
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/electric.el | 61 |
1 files changed, 36 insertions, 25 deletions
diff --git a/lisp/electric.el b/lisp/electric.el index c00e7c00a59..a45faf2dbb5 100644 --- a/lisp/electric.el +++ b/lisp/electric.el | |||
| @@ -260,32 +260,43 @@ or comment." | |||
| 260 | (or (memq act '(nil no-indent)) | 260 | (or (memq act '(nil no-indent)) |
| 261 | ;; In a string or comment. | 261 | ;; In a string or comment. |
| 262 | (unless (eq act 'do-indent) (nth 8 (syntax-ppss)))))))) | 262 | (unless (eq act 'do-indent) (nth 8 (syntax-ppss)))))))) |
| 263 | ;; For newline, we want to reindent both lines and basically behave like | 263 | ;; If we error during indent, silently give up since this is an |
| 264 | ;; reindent-then-newline-and-indent (whose code we hence copied). | 264 | ;; automatic action that the user didn't explicitly request. |
| 265 | (let ((at-newline (<= pos (line-beginning-position)))) | 265 | ;; But we don't want to suppress errors from elsewhere in *this* |
| 266 | (when at-newline | 266 | ;; function, hence the `condition-case' and `throw' (Bug#18764). |
| 267 | (let ((before (copy-marker (1- pos) t))) | 267 | (catch 'indent-error |
| 268 | (save-excursion | 268 | ;; For newline, we want to reindent both lines and basically |
| 269 | (unless (or (memq indent-line-function | 269 | ;; behave like reindent-then-newline-and-indent (whose code we |
| 270 | electric-indent-functions-without-reindent) | 270 | ;; hence copied). |
| 271 | electric-indent-inhibit) | 271 | (let ((at-newline (<= pos (line-beginning-position)))) |
| 272 | ;; Don't reindent the previous line if the indentation function | 272 | (when at-newline |
| 273 | ;; is not a real one. | 273 | (let ((before (copy-marker (1- pos) t))) |
| 274 | (save-excursion | ||
| 275 | (unless (or (memq indent-line-function | ||
| 276 | electric-indent-functions-without-reindent) | ||
| 277 | electric-indent-inhibit) | ||
| 278 | ;; Don't reindent the previous line if the | ||
| 279 | ;; indentation function is not a real one. | ||
| 280 | (goto-char before) | ||
| 281 | (condition-case-unless-debug () | ||
| 282 | (indent-according-to-mode) | ||
| 283 | (error (throw 'indent-error nil)))) | ||
| 284 | ;; We are at EOL before the call to | ||
| 285 | ;; `indent-according-to-mode', and after it we usually | ||
| 286 | ;; are as well, but not always. We tried to address | ||
| 287 | ;; it with `save-excursion' but that uses a normal | ||
| 288 | ;; marker whereas we need `move after insertion', so | ||
| 289 | ;; we do the save/restore by hand. | ||
| 274 | (goto-char before) | 290 | (goto-char before) |
| 275 | (indent-according-to-mode)) | 291 | (when (eolp) |
| 276 | ;; We are at EOL before the call to indent-according-to-mode, and | 292 | ;; Remove the trailing whitespace after indentation because |
| 277 | ;; after it we usually are as well, but not always. We tried to | 293 | ;; indentation may (re)introduce the whitespace. |
| 278 | ;; address it with `save-excursion' but that uses a normal marker | 294 | (delete-horizontal-space t))))) |
| 279 | ;; whereas we need `move after insertion', so we do the | 295 | (unless (and electric-indent-inhibit |
| 280 | ;; save/restore by hand. | 296 | (not at-newline)) |
| 281 | (goto-char before) | 297 | (condition-case-unless-debug () |
| 282 | (when (eolp) | 298 | (indent-according-to-mode) |
| 283 | ;; Remove the trailing whitespace after indentation because | 299 | (error (throw 'indent-error nil))))))))) |
| 284 | ;; indentation may (re)introduce the whitespace. | ||
| 285 | (delete-horizontal-space t))))) | ||
| 286 | (unless (and electric-indent-inhibit | ||
| 287 | (not at-newline)) | ||
| 288 | (indent-according-to-mode)))))) | ||
| 289 | 300 | ||
| 290 | (put 'electric-indent-post-self-insert-function 'priority 60) | 301 | (put 'electric-indent-post-self-insert-function 'priority 60) |
| 291 | 302 | ||