bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#17183: can't insert a quote pair before another


From: João Távora
Subject: bug#17183: can't insert a quote pair before another
Date: Sun, 06 Apr 2014 13:46:59 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux)

joaotavora@gmail.com (João Távora) writes:

> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
>> Package: Emacs
>> Version: 24.3.50
>
>> but instead I had to use C-q " twice, which was rather unpleasant.
>
> Yes seen it. Rather unpleasant indeed. How does this look?

Actually, this is slightly simpler. New tests should make my intention
clear as well

=== modified file 'lisp/ChangeLog'
*** lisp/ChangeLog      2014-04-05 18:33:55 +0000
--- lisp/ChangeLog      2014-04-06 12:43:30 +0000
***************
*** 1,3 ****
--- 1,10 ----
+ 2014-04-06  João Távora  <joaotavora@gmail.com>
+ 
+       * elec-pair.el (electric-pair--skip-whitespace): With quote
+       syntax, ensure not outside string before insertion started. .
+       (electric-pair-post-self-insert-function): Pass syntax to
+       electric-pair--skip-whitespace. (Bug#17183)
+ 
  2014-04-05  Glenn Morris  <rgm@gnu.org>
  
        * help.el (view-lossage): Doc tweak.

=== modified file 'lisp/elec-pair.el'
*** lisp/elec-pair.el   2014-02-23 00:19:11 +0000
--- lisp/elec-pair.el   2014-04-06 12:33:49 +0000
***************
*** 151,163 ****
                        (const :tag "Newline" ?\n))
                   (list character)))
  
! (defun electric-pair--skip-whitespace ()
    "Skip whitespace forward, not crossing comment or string boundaries."
!   (let ((saved (point))
!         (string-or-comment (nth 8 (syntax-ppss))))
!     (skip-chars-forward (apply #'string electric-pair-skip-whitespace-chars))
!     (unless (eq string-or-comment (nth 8 (syntax-ppss)))
!       (goto-char saved))))
  
  (defvar electric-pair-text-syntax-table prog-mode-syntax-table
    "Syntax table used when pairing inside comments and strings.
--- 151,168 ----
                        (const :tag "Newline" ?\n))
                   (list character)))
  
! (defun electric-pair--skip-whitespace (syntax)
    "Skip whitespace forward, not crossing comment or string boundaries."
!   (let* ((saved (point))
!          (ppss (syntax-ppss))
!          (string-or-comment (nth 8 ppss)))
!     (unless (and
!              (eq syntax ?\")
!              (not (nth 3 (save-excursion
!                            (syntax-ppss (1- (point)))))))
!       (skip-chars-forward (apply #'string 
electric-pair-skip-whitespace-chars))
!       (unless (eq string-or-comment (nth 8 (syntax-ppss)))
!         (goto-char saved)))))
  
  (defvar electric-pair-text-syntax-table prog-mode-syntax-table
    "Syntax table used when pairing inside comments and strings.
***************
*** 489,495 ****
                                   (if (functionp electric-pair-skip-whitespace)
                                       (funcall electric-pair-skip-whitespace)
                                     electric-pair-skip-whitespace))
!                        (electric-pair--skip-whitespace))
                       (eq (char-after) 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
--- 494,500 ----
                                   (if (functionp electric-pair-skip-whitespace)
                                       (funcall electric-pair-skip-whitespace)
                                     electric-pair-skip-whitespace))
!                        (electric-pair--skip-whitespace syntax))
                       (eq (char-after) 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
***************
*** 497,503 ****
           ;; be visible to other post-self-insert-hook.  We'll just have to
           ;; live with it for now.
           (when skip-whitespace-info
!            (electric-pair--skip-whitespace))
           (delete-region (1- pos) (if (eq skip-whitespace-info 'chomp)
                                       (point)
                                     pos))
--- 502,508 ----
           ;; be visible to other post-self-insert-hook.  We'll just have to
           ;; live with it for now.
           (when skip-whitespace-info
!            (electric-pair--skip-whitespace syntax))
           (delete-region (1- pos) (if (eq skip-whitespace-info 'chomp)
                                       (point)
                                     pos))

=== modified file 'test/ChangeLog'
*** test/ChangeLog      2014-03-25 07:34:30 +0000
--- test/ChangeLog      2014-04-06 12:44:19 +0000
***************
*** 1,3 ****
--- 1,11 ----
+ 2014-04-06  João Távora  <joaotavora@gmail.com>
+ 
+       * automated/electric-tests.el (electric-pair-define-test-form):
+       More readable test docstrings.
+       (whitespace-skipping-for-quotes-not-ouside)
+       (whitespace-skipping-for-quotes-only-inside)
+       (whitespace-skipping-for-quotes-in-text-mode): New tests.
+ 
  2014-03-24  Barry O'Reilly  <gundaetiapo@gmail.com>
  
        * automated/undo-tests.el (undo-test-marker-adjustment-nominal):

=== modified file 'test/automated/electric-tests.el'
*** test/automated/electric-tests.el    2014-01-01 07:43:34 +0000
--- test/automated/electric-tests.el    2014-04-06 12:41:35 +0000
***************
*** 114,121 ****
                                       mode
                                       extra-desc))
             ()
!          ,(format "With \"%s\", try input %c at point %d. \
! Should %s \"%s\" and point at %d"
                    fixture
                    char
                    (1+ pos)
--- 114,121 ----
                                       mode
                                       extra-desc))
             ()
!          ,(format "With |%s|, try input %c at point %d. \
! Should %s |%s| and point at %d"
                    fixture
                    char
                    (1+ pos)
***************
*** 341,346 ****
--- 341,371 ----
    :test-in-code nil
    :test-in-comments t)
  
+ (define-electric-pair-test whitespace-skipping-for-quotes-not-ouside
+   "  \"  \"" "\"-----" :expected-string "\"\"  \"  \""
+   :expected-point 2
+   :bindings '((electric-pair-skip-whitespace . chomp))
+   :test-in-strings nil
+   :test-in-code t
+   :test-in-comments nil)
+ 
+ (define-electric-pair-test whitespace-skipping-for-quotes-only-inside
+   "  \"  \"" "---\"--" :expected-string "  \"\""
+   :expected-point 5
+   :bindings '((electric-pair-skip-whitespace . chomp))
+   :test-in-strings nil
+   :test-in-code t
+   :test-in-comments nil)
+ 
+ (define-electric-pair-test whitespace-skipping-for-quotes-in-text-mode
+   "  \"  \"" "---\"--" :expected-string "  \"\"\"  \""
+   :expected-point 5
+   :modes '(text-mode)
+   :bindings '((electric-pair-skip-whitespace . chomp))
+   :test-in-strings nil
+   :test-in-code t
+   :test-in-comments nil)
+ 
  
  ;;; Pairing arbitrary characters
  ;;;







reply via email to

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