diff options
| author | Noam Postavsky | 2018-06-20 20:12:23 -0400 |
|---|---|---|
| committer | Noam Postavsky | 2018-06-25 19:18:55 -0400 |
| commit | c71fb6b0cdb7043e2828a6843496ab20f4577cbb (patch) | |
| tree | f76b37a5355dc113bf6e9a6e9d3d82cc7b06686a | |
| parent | d0e2a341dd9a9a365fd311748df024ecb25b70ec (diff) | |
| download | emacs-c71fb6b0cdb7043e2828a6843496ab20f4577cbb.tar.gz emacs-c71fb6b0cdb7043e2828a6843496ab20f4577cbb.zip | |
Suppress indent errors during electric indentation (Bug#18764)
* lisp/electric.el (electric-indent-post-self-insert-function):
Suppress errors from indent code, but don't suppress errors from
elsewhere in this function. That way, if trouble is encountered with
electric indent "not working", the error should be reproducible by
calling indent directly (as is the case for Bug#18764), or else it's
from the electric indent code and will be reported normally.
| -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 | ||