all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: joaotavora@gmail.com (João Távora)
To: 17192@debbugs.gnu.org
Subject: bug#17192: 24.4.50; python-mode's python-electric-pair-string-delimiter inserts an extra quote
Date: Sat, 05 Apr 2014 13:22:06 +0100	[thread overview]
Message-ID: <87bnwgq841.fsf@kitaj.lan> (raw)

Hi maintainers,

    emacs -Q
    M-x electric-pair-mode RET
    M-x python-mode RET
    M-x erase-buffer RET !
    Press double quotes (") twice

Buffer contents are 7 double quotes instead of 6, with point correctly
at 4.

This is fixed by the patch attached.
João

Using changes with id "2".
Message: python-triple-quote-fixes
 M  lisp/ChangeLog
 M  lisp/progmodes/python.el
 M  test/ChangeLog
 M  test/automated/python-tests.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog	2014-04-05 11:15:07 +0000
+++ b/lisp/ChangeLog	2014-04-05 12:15:08 +0000
@@ -1,3 +1,8 @@
+2014-04-05  João Távora  <joaotavora@gmail.com>
+
+	* progmodes/python.el (python-electric-pair-string-delimiter): Fix
+	triple-quoting electricity.
+
 2014-04-04  João Távora  <joaotavora@gmail.com>
 
 	* elec-pair.el:

=== modified file 'lisp/progmodes/python.el'
--- a/lisp/progmodes/python.el	2014-04-05 11:15:07 +0000
+++ b/lisp/progmodes/python.el	2014-04-05 12:15:08 +0000
@@ -3651,8 +3651,9 @@
              (let ((count 0))
                (while (eq (char-before (- (point) count)) last-command-event)
                  (cl-incf count))
-               (= count 3)))
-    (save-excursion (insert (make-string 3 last-command-event)))))
+               (= count 3))
+             (eq (char-after) last-command-event))
+    (save-excursion (insert (make-string 2 last-command-event)))))
 
 (defvar electric-indent-inhibit)
 

=== modified file 'test/ChangeLog'
--- a/test/ChangeLog	2014-04-05 11:15:07 +0000
+++ b/test/ChangeLog	2014-04-05 12:15:08 +0000
@@ -1,3 +1,8 @@
+2014-04-05  João Távora  <joaotavora@gmail.com>
+
+	* automated/python-tests.el (python-triple-quote-pairing): New test.
+	(python-syntax-after-python-backspace): New test.
+
 2014-04-04  João Távora  <joaotavora@gmail.com>
 
 	* automated/electric-tests.el (define-electric-pair-test): Don't

=== modified file 'test/automated/python-tests.el'
--- a/test/automated/python-tests.el	2014-04-05 11:15:07 +0000
+++ b/test/automated/python-tests.el	2014-04-05 12:15:08 +0000
@@ -134,6 +134,16 @@
 \f
 ;;; Font-lock and syntax
 
+(ert-deftest python-syntax-after-python-backspace ()
+  ;; `python-indent-dedent-line-backspace' garbles syntax
+  :expected-result :failed
+  (python-tests-with-temp-buffer
+      "\"\"\""
+    (goto-char (point-max))
+    (python-indent-dedent-line-backspace 1)
+    (should (string= (buffer-string) "\"\""))
+    (should (null (nth 3 (syntax-ppss))))))
+
 \f
 ;;; Indentation
 
@@ -2696,6 +2706,9 @@
         (equal (symbol-value (car ccons)) (cdr ccons)))))
     (kill-buffer buffer)))
 
+\f
+;;; Electricity
+
 (ert-deftest python-util-forward-comment-1 ()
   (python-tests-with-temp-buffer
    (concat
@@ -2708,6 +2721,32 @@
    (python-util-forward-comment -1)
    (should (= (point) (point-min)))))
 
+(ert-deftest python-triple-quote-pairing ()
+  (python-tests-with-temp-buffer
+      "\"\"\n"
+    (goto-char (1- (point-max)))
+    (let ((last-command-event ?\"))
+      (call-interactively 'self-insert-command))
+    (should (string= (buffer-string)
+                     "\"\"\"\"\"\"\n"))
+    (should (= (point) 4)))
+  (python-tests-with-temp-buffer
+      "\n"
+    (let ((last-command-event ?\"))
+      (dotimes (i 3)
+        (call-interactively 'self-insert-command)))
+    (should (string= (buffer-string)
+                     "\"\"\"\"\"\"\n"))
+    (should (= (point) 4)))
+  (python-tests-with-temp-buffer
+      "\"\n\"\"\n"
+    (goto-char (1- (point-max)))
+    (let ((last-command-event ?\"))
+      (call-interactively 'self-insert-command))
+    (should (= (point) (1- (point-max))))
+    (should (string= (buffer-string)
+                     "\"\n\"\"\"\n"))))
+
 
 (provide 'python-tests)
 






             reply	other threads:[~2014-04-05 12:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-05 12:22 João Távora [this message]
2014-04-05 15:50 ` bug#17192: 24.4.50; python-mode's python-electric-pair-string-delimiter inserts an extra quote Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bnwgq841.fsf@kitaj.lan \
    --to=joaotavora@gmail.com \
    --cc=17192@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.