diff options
author | Tassilo Horn <tsdh@gnu.org> | 2019-02-20 16:58:57 +0100 |
---|---|---|
committer | Tassilo Horn <tsdh@gnu.org> | 2019-02-20 16:58:57 +0100 |
commit | e5c99a1757c281953257ac2548fb77702af75c86 (patch) | |
tree | 4820116244ad6650f53208bc792ca248ccc630fb /lisp/elec-pair.el | |
parent | bfa10b704ebe71c91d5e5eb28e407a02d2d88863 (diff) | |
parent | ae77728d14e58054bdaee3c6965979947c778208 (diff) | |
download | emacs-scratch/replace-region-contents.tar.gz |
Merge branch 'master' into scratch/replace-region-contentsscratch/replace-region-contents
Diffstat (limited to 'lisp/elec-pair.el')
-rw-r--r-- | lisp/elec-pair.el | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el index b5ec492930e..3be09d87b4f 100644 --- a/lisp/elec-pair.el +++ b/lisp/elec-pair.el @@ -429,20 +429,25 @@ some list calculations, finally restoring the situation as if nothing happened." (pcase (electric-pair-syntax-info char) (`(,syntax ,pair ,_ ,s-or-c) - (unwind-protect - (progn - (delete-char -1) - (cond ((eq ?\( syntax) - (let* ((pair-data - (electric-pair--balance-info 1 s-or-c)) - (outermost (cdr pair-data))) - (cond ((car outermost) - nil) - (t - (eq (cdr outermost) pair))))) - ((eq syntax ?\") - (electric-pair--unbalanced-strings-p char)))) - (insert char))))) + (catch 'done + ;; FIXME: modify+undo is *very* tricky business. We used to + ;; use `delete-char' followed by `insert', but this changed the + ;; position some markers. The real fix would be to compute the + ;; result without having to modify the buffer at all. + (atomic-change-group + (delete-char -1) + (throw + 'done + (cond ((eq ?\( syntax) + (let* ((pair-data + (electric-pair--balance-info 1 s-or-c)) + (outermost (cdr pair-data))) + (cond ((car outermost) + nil) + (t + (eq (cdr outermost) pair))))) + ((eq syntax ?\") + (electric-pair--unbalanced-strings-p char))))))))) (defun electric-pair-skip-if-helps-balance (char) "Return non-nil if skipping CHAR would benefit parentheses' balance. |