From: joaotavora@gmail.com (João Távora)
To: 17183@debbugs.gnu.org
Subject: bug#17183: can't insert a quote pair before another
Date: Sun, 06 Apr 2014 13:46:59 +0100 [thread overview]
Message-ID: <87vbum7hh8.fsf@kitaj.lan> (raw)
In-Reply-To: <jwveh1dyw56.fsf@faina.iro.umontreal.ca>
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)
+
\f
;;; Pairing arbitrary characters
;;;
next prev parent reply other threads:[~2014-04-06 12:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-04 15:03 bug#17183: can't insert a quote pair before another Stefan Monnier
2014-04-06 1:26 ` João Távora
2014-04-06 12:39 ` Stefan Monnier
2014-04-06 15:01 ` João Távora
2014-04-06 12:46 ` João Távora [this message]
2014-04-06 19:39 ` 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=87vbum7hh8.fsf@kitaj.lan \
--to=joaotavora@gmail.com \
--cc=17183@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.