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 02:26:15 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux)

Stefan Monnier <address@hidden> 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? 

=== modified file 'lisp/ChangeLog'
*** lisp/ChangeLog      2014-04-04 23:31:02 +0000
--- lisp/ChangeLog      2014-04-06 01:23:51 +0000
***************
*** 1,3 ****
--- 1,11 ----
+ 2014-04-06  João Távora  <address@hidden>
+ 
+       * elec-pair.el (electric-pair--skip-whitespace): With quote
+       syntax, ensure not outside string before insertion started. .
+       (electric-pair-post-self-insert-function): Pass char and syntax to
+       electric-pair--skip-whitespace. Save point instead of
+       `save-excursion'. (Bug#17183)
+ 
  2014-04-04  João Távora  <address@hidden>
  
        * elec-pair.el:

=== modified file 'lisp/elec-pair.el'
*** lisp/elec-pair.el   2014-04-04 23:31:02 +0000
--- lisp/elec-pair.el   2014-04-06 01:19:47 +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,171 ----
                        (const :tag "Newline" ?\n))
                   (list character)))
  
! (defun electric-pair--skip-whitespace (char 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 ?\")
!              (unwind-protect
!                  (progn
!                    (delete-char -1)
!                    (not (nth 3 (syntax-ppss))))
!                (insert-char char)))
!       (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.
***************
*** 502,521 ****
                         (if (functionp electric-pair-skip-self)
                             (funcall electric-pair-skip-self 
last-command-event)
                           electric-pair-skip-self))
!                    (save-excursion
                       (when (setq skip-whitespace-info
                                   (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
           ;; goes in the undo-log and in the intermediate state which might
           ;; 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))
--- 510,531 ----
                         (if (functionp electric-pair-skip-self)
                             (funcall electric-pair-skip-self 
last-command-event)
                           electric-pair-skip-self))
!                    (let ((saved (point)))
                       (when (setq skip-whitespace-info
                                   (if (functionp electric-pair-skip-whitespace)
                                       (funcall electric-pair-skip-whitespace)
                                     electric-pair-skip-whitespace))
!                        (electric-pair--skip-whitespace last-command-event 
syntax))
!                      (prog1
!                          (eq (char-after) last-command-event)
!                        (goto-char saved)))))
           ;; 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 post-self-insert-hook.  We'll just have to
           ;; live with it for now.
           (when skip-whitespace-info
!            (electric-pair--skip-whitespace last-command-event syntax))
           (delete-region (1- pos) (if (eq skip-whitespace-info 'chomp)
                                       (point)
                                     pos))






reply via email to

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