* bug#17183: can't insert a quote pair before another @ 2014-04-04 15:03 Stefan Monnier 2014-04-06 1:26 ` João Távora 0 siblings, 1 reply; 6+ messages in thread From: Stefan Monnier @ 2014-04-04 15:03 UTC (permalink / raw) To: 17183 Package: Emacs Version: 24.3.50 emacs -Q -f electric-pair-mode -f text-mode SPC SPC SPC " C-a " The first " inserts a pair of double quotes, like I expect, but the second refuses to insert anything and instead it jumps forward to after the first double quote. Maybe there are cases where that makes sense, but that's much too clever for me. The situation where I bumped into it was that I had the text I suggest you write "blabla" instead of and I wanted to turn it into I suggest you write "blibli" and "blabla" instead of so I put point after "write" and wanted to type SPC "blibli" SPC and but instead I had to use C-q " twice, which was rather unpleasant. Stefan In GNU Emacs 24.3.50.1 (i686-pc-linux-gnu, GTK+ Version 2.24.22) of 2014-01-07 on faina ^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#17183: can't insert a quote pair before another 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 12:46 ` João Távora 0 siblings, 2 replies; 6+ messages in thread From: João Távora @ 2014-04-06 1:26 UTC (permalink / raw) To: Stefan Monnier; +Cc: 17183 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? === 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 <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 char and syntax to + electric-pair--skip-whitespace. Save point instead of + `save-excursion'. (Bug#17183) + 2014-04-04 João Távora <joaotavora@gmail.com> * 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)) ^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#17183: can't insert a quote pair before another 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 1 sibling, 1 reply; 6+ messages in thread From: Stefan Monnier @ 2014-04-06 12:39 UTC (permalink / raw) To: João Távora; +Cc: 17183 > + (unwind-protect > + (progn > + (delete-char -1) > + (not (nth 3 (syntax-ppss)))) > + (insert-char char))) Yuck! Why not (save-excursion (not (nth 3 (syntax-ppss (-1 (point))))))? Stefan ^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#17183: can't insert a quote pair before another 2014-04-06 12:39 ` Stefan Monnier @ 2014-04-06 15:01 ` João Távora 0 siblings, 0 replies; 6+ messages in thread From: João Távora @ 2014-04-06 15:01 UTC (permalink / raw) To: Stefan Monnier; +Cc: 17183 That's precisely what I proposed in my last message that didn't yet make it to you (gmane authorization). Also, we should probably use electric-pair--syntax-ppss so that the trick works inside comments, too. On Sun, Apr 6, 2014 at 1:39 PM, Stefan Monnier <monnier@iro.umontreal.ca> wrote: >> + (unwind-protect >> + (progn >> + (delete-char -1) >> + (not (nth 3 (syntax-ppss)))) >> + (insert-char char))) > > Yuck! Why not (save-excursion (not (nth 3 (syntax-ppss (-1 (point))))))? > > > Stefan -- João Távora ^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#17183: can't insert a quote pair before another 2014-04-06 1:26 ` João Távora 2014-04-06 12:39 ` Stefan Monnier @ 2014-04-06 12:46 ` João Távora 2014-04-06 19:39 ` Stefan Monnier 1 sibling, 1 reply; 6+ messages in thread From: João Távora @ 2014-04-06 12:46 UTC (permalink / raw) To: 17183 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 ;;; ^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#17183: can't insert a quote pair before another 2014-04-06 12:46 ` João Távora @ 2014-04-06 19:39 ` Stefan Monnier 0 siblings, 0 replies; 6+ messages in thread From: Stefan Monnier @ 2014-04-06 19:39 UTC (permalink / raw) To: João Távora; +Cc: 17183 > Actually, this is slightly simpler. New tests should make my intention > clear as well Looks good, thanks, Stefan ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-04-06 19:39 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 2014-04-06 19:39 ` Stefan Monnier
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).