emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r113065: * lisp/electric.el (electric-pair-mode): Im


From: Stefan Monnier
Subject: [Emacs-diffs] trunk r113065: * lisp/electric.el (electric-pair-mode): Improve interaction with
Date: Wed, 19 Jun 2013 04:42:36 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 113065
revision-id: address@hidden
parent: address@hidden
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Wed 2013-06-19 00:42:32 -0400
message:
  * lisp/electric.el (electric-pair-mode): Improve interaction with
  electric-layout-mode.
  (electric-pair-default-inhibit): Don't assume (eq char (char-before)).
  (electric-pair-syntax): Use text-mode-syntax-table in comments and strings.
  (electric-pair--insert): New function.
  (electric-pair-post-self-insert-function): Use it and 
electric--after-char-pos.
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/electric.el               electric.el-20091113204419-o5vbwnq5f7feedwu-47
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-06-19 02:02:30 +0000
+++ b/lisp/ChangeLog    2013-06-19 04:42:32 +0000
@@ -1,3 +1,14 @@
+2013-06-19  Stefan Monnier  <address@hidden>
+
+       * electric.el (electric-pair-mode): Improve interaction with
+       electric-layout-mode.
+       (electric-pair-default-inhibit): Don't assume (eq char (char-before)).
+       (electric-pair-syntax): Use text-mode-syntax-table in comments
+       and strings.
+       (electric-pair--insert): New function.
+       (electric-pair-post-self-insert-function): Use it and
+       electric--after-char-pos.
+
 2013-06-19  Leo Liu  <address@hidden>
 
        * progmodes/octave.el (octave-help): Fix regexp.
@@ -19,8 +30,8 @@
        (eww-handle-link, eww-tag-link, eww-tag-a): New defuns.
        (eww-mode-map): Move "p" to "l".  Bind "p", "n", "t", and "u".
        (eww-back-url): Rename from eww-previous-url.
-       (eww-next-url, eww-previous-url, eww-up-url, eww-top-url): New
-       defuns.
+       (eww-next-url, eww-previous-url, eww-up-url, eww-top-url):
+       New defuns.
 
 2013-06-18  Dmitry Gutov  <address@hidden>
 

=== modified file 'lisp/electric.el'
--- a/lisp/electric.el  2013-04-04 03:42:10 +0000
+++ b/lisp/electric.el  2013-06-19 04:42:32 +0000
@@ -319,51 +319,63 @@
    ;; I find it more often preferable not to pair when the
    ;; same char is next.
    (eq char (char-after))
-   (eq char (char-before (1- (point))))
+   ;; Don't pair up when we insert the second of "" or of ((.
+   (and (eq char (char-before))
+       (eq char (char-before (1- (point)))))
    ;; I also find it often preferable not to pair next to a word.
    (eq (char-syntax (following-char)) ?w)))
 
 (defun electric-pair-syntax (command-event)
-  (and electric-pair-mode
-       (let ((x (assq command-event electric-pair-pairs)))
-        (cond
-         (x (if (eq (car x) (cdr x)) ?\" ?\())
-         ((rassq command-event electric-pair-pairs) ?\))
-         (t (char-syntax command-event))))))
+  (let ((x (assq command-event electric-pair-pairs)))
+    (cond
+     (x (if (eq (car x) (cdr x)) ?\" ?\())
+     ((rassq command-event electric-pair-pairs) ?\))
+     ((nth 8 (syntax-ppss))
+      (with-syntax-table text-mode-syntax-table (char-syntax command-event)))
+     (t (char-syntax command-event)))))
+
+(defun electric-pair--insert (char)
+  (let ((last-command-event char)
+       (blink-matching-paren nil)
+       (electric-pair-mode nil))
+    (self-insert-command 1)))
 
 (defun electric-pair-post-self-insert-function ()
-  (let* ((syntax (and (eq (char-before) last-command-event) ; Sanity check.
-                     (electric-pair-syntax last-command-event)))
-         ;; FIXME: when inserting the closer, we should maybe use
-         ;; self-insert-command, although it may prove tricky running
-         ;; post-self-insert-hook recursively, and we wouldn't want to trigger
-         ;; blink-matching-open.
+  (let* ((pos (and electric-pair-mode (electric--after-char-pos)))
+        (syntax (and pos (electric-pair-syntax last-command-event)))
          (closer (if (eq syntax ?\()
                      (cdr (or (assq last-command-event electric-pair-pairs)
                               (aref (syntax-table) last-command-event)))
                    last-command-event)))
     (cond
+     ((null pos) nil)
      ;; Wrap a pair around the active region.
      ((and (memq syntax '(?\( ?\" ?\$)) (use-region-p))
-      (if (> (mark) (point))
-          (goto-char (mark))
+      ;; FIXME: To do this right, we'd need a post-self-insert-function
+      ;; so we could add-function around it and insert the closer after
+      ;; all the rest of the hook has run.
+      (if (>= (mark) (point))
+         (goto-char (mark))
        ;; We already inserted the open-paren but at the end of the
        ;; region, so we have to remove it and start over.
-       (delete-char -1)
+       (delete-region (1- pos) (point))
        (save-excursion
           (goto-char (mark))
-         ;; Do not insert after `save-excursion' marker (Bug#11520).
-          (insert-before-markers last-command-event)))
+          (electric-pair--insert last-command-event)))
+      ;; Since we're right after the closer now, we could tell the rest of
+      ;; post-self-insert-hook that we inserted `closer', but then we'd get
+      ;; blink-paren to kick in, which is annoying.
+      ;;(setq last-command-event closer)
       (insert closer))
      ;; Backslash-escaped: no pairing, no skipping.
      ((save-excursion
-        (goto-char (1- (point)))
+        (goto-char (1- pos))
         (not (zerop (% (skip-syntax-backward "\\") 2))))
       nil)
      ;; Skip self.
      ((and (memq syntax '(?\) ?\" ?\$))
            electric-pair-skip-self
-           (eq (char-after) last-command-event))
+           (eq (char-after pos) last-command-event))
       ;; This is too late: rather than insert&delete we'd want to only skip (or
       ;; insert in overwrite mode).  The difference is in what goes in the
       ;; undo-log and in the intermediate state which might be visible to other
@@ -373,7 +385,7 @@
      ((not (or (not (memq syntax `(?\( ?\" ?\$)))
                overwrite-mode
                (funcall electric-pair-inhibit-predicate last-command-event)))
-      (save-excursion (insert closer))))))
+      (save-excursion (electric-pair--insert closer))))))
 
 (defun electric-pair-will-use-region ()
   (and (use-region-p)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]