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

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

bug#50538: [PATCH] 28.0.50; electric-pair-mode fails to pair double quot


From: Jim Porter
Subject: bug#50538: [PATCH] 28.0.50; electric-pair-mode fails to pair double quotes in some cases in CC mode
Date: Sat, 11 Sep 2021 20:58:47 -0700

(Note: I've just updated my copyright assignment information, but haven't received confirmation that everything is in order, so this might need to wait until that's done for it to merge.)

There are a few related issues with pairing double quotes in CC mode while using `electric-pair-mode'. Hopefully the steps to reproduce below will explain the issues. In all the cases, I'd expect `electric-pair-mode' to insert a closing quote, but it doesn't. You can try similar steps in a `ruby-mode' buffer to see how it should work.

----------------------------------------

Common setup
------------

  $ cat foo.c
  "foobar"

  $ emacs -Q foo.c
  M-x electric-pair-mode

Note that | represents the point below.

1. Quote pairing in comments
----------------------------

  C-o   ;; to make a blank line
  // "  ;; type this

Expected: line 1 is // "|"
Actual:   line 1 is // "|

2. Inserting quote pairs before existing string
-----------------------------------------------

  "  ;; type this (point is at beginning of buffer, before "foobar")

Expected: line 1 is "|""foobar"
Actual:   line 1 is "|"foobar"

3. Splitting strings into two
-----------------------------

  "foo|bar"  ;; move point here
  "          ;; type this

Expected: line 1 is "foo"|"bar"
Actual:   line 1 is "foo"|bar"

----------------------------------------

This is because the logic in the patch for bug#36474 isn't quite right. Currently, `c-electric-pair-inhibit-predicate' checks if the newly-inserted quotation mark has "a string fence syntax-table text property" (i.e. if it's the start of a string literal not terminated on that line[1]). However, this fails in all three cases above: in (1) because we're in a comment, not a string literal; and in (2) and (3) because it's the *last* quotation mark on the line that's unterminated, not the one before point.

The attached patch fixes this by taking those cases into account. I also added `c-mode' to the list of modes to check in `test/lisp/electric-tests.el'. This required setting single-line comments as the default in those tests, since the tests expect single-line comments (I tried testing under `c++-mode', but the tests failed, I think due to <> being paren-like in C++).

[1] I think this is what it means, at least (or close to it).

Attachment: 0001-Improve-behavior-of-electric-pair-mode-in-cc-mode.patch
Description: Text document


reply via email to

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