From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [Emacs-diffs] master 34d4720: Electric quotes: Improve support for Markdown mode (Bug#24709) Date: Mon, 03 Jul 2017 14:36:11 -0400 Message-ID: References: <20170702154850.22058.98643@vcs0.savannah.gnu.org> <20170702154852.1796522E35@vcs0.savannah.gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1499107045 20425 195.159.176.226 (3 Jul 2017 18:37:25 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 3 Jul 2017 18:37:25 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Philipp Stephani Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jul 03 20:37:21 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dS6Dl-0004sq-Gh for ged-emacs-devel@m.gmane.org; Mon, 03 Jul 2017 20:37:17 +0200 Original-Received: from localhost ([::1]:36720 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dS6Dp-0007rg-6H for ged-emacs-devel@m.gmane.org; Mon, 03 Jul 2017 14:37:21 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52895) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dS6Cr-0007qF-DM for emacs-devel@gnu.org; Mon, 03 Jul 2017 14:36:22 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dS6Ck-0007TS-LP for emacs-devel@gnu.org; Mon, 03 Jul 2017 14:36:21 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:28687) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dS6Ck-0007SC-Da for emacs-devel@gnu.org; Mon, 03 Jul 2017 14:36:14 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0D2BQA9jlpZ//MINJ1cHQEFAQsBg1mBcYMhi1eQfysBR5UKgTIDXIYWBAICgnpCFgECAQEBAQEBAWsohRgBAQEBAgEjMyMFCwsOAwMBAgMCGA4CAhQYDRYOExqKDQivd4Imi0QBAQEBBgIBJYELghyFLYJwNIRqgxOCYQWef4hRgjmLA4VKgz2HChOVHSYBMEw+MSEIMEmFSIFpJDaGTSqCFQEBAQ X-IPAS-Result: A0D2BQA9jlpZ//MINJ1cHQEFAQsBg1mBcYMhi1eQfysBR5UKgTIDXIYWBAICgnpCFgECAQEBAQEBAWsohRgBAQEBAgEjMyMFCwsOAwMBAgMCGA4CAhQYDRYOExqKDQivd4Imi0QBAQEBBgIBJYELghyFLYJwNIRqgxOCYQWef4hRgjmLA4VKgz2HChOVHSYBMEw+MSEIMEmFSIFpJDaGTSqCFQEBAQ X-IronPort-AV: E=Sophos;i="5.40,304,1496116800"; d="scan'208";a="319257668" Original-Received: from 157-52-8-243.cpe.teksavvy.com (HELO pastel.home) ([157.52.8.243]) by smtp.teksavvy.com with ESMTP; 03 Jul 2017 14:36:12 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id 731E862D4F; Mon, 3 Jul 2017 14:36:11 -0400 (EDT) In-Reply-To: (Philipp Stephani's message of "Mon, 03 Jul 2017 16:48:39 +0000") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.181 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:216142 Archived-At: > Good point, here's another patch. Looks good, thanks. Stefan > Google Germany GmbH > Erika-Mann-Stra=C3=9Fe 33 > 80636 M=C3=BCnchen > Registergericht und -nummer: Hamburg, HRB 86891 > Sitz der Gesellschaft: Hamburg > Gesch=C3=A4ftsf=C3=BChrer: Matthew Scott Sucherman, Paul Terence Manicle > Diese E-Mail ist vertraulich. Wenn Sie nicht der richtige Adressat sind, > leiten Sie diese bitte nicht weiter, informieren Sie den Absender und > l=C3=B6schen Sie die E-Mail und alle Anh=C3=A4nge. Vielen Dank. > This e-mail is confidential. If you are not the right addressee please do > not forward it, please inform the sender, and please erase this e-mail > including any attachments. Thanks. > From 287a333286f5441128a1169be75e89461823e3af Mon Sep 17 00:00:00 2001 > From: Philipp Stephani > Date: Mon, 3 Jul 2017 18:46:10 +0200 > Subject: [PATCH] Use hook instead of face list to inhibit electric quoting > This is more flexible and doesn't couple electric quoting to font > locking. > Give that 'electric-quote-code-faces' was just introduced, remove it > without formal deprecation. > * lisp/electric.el (electric-quote-inhibit-functions): New abnormal > hook variable. > (electric-quote-post-self-insert-function): Run the hook. Remove > use of old 'electric-quote-code-faces' variable. > * test/lisp/electric-tests.el (electric-quote-markdown-in-text) > (electric-quote-markdown-in-code): Adapt unit tests. > --- > etc/NEWS | 12 ++++++------ > lisp/electric.el | 19 ++++++++++++------- > test/lisp/electric-tests.el | 16 ++++++++++++---- > 3 files changed, 30 insertions(+), 17 deletions(-) > diff --git a/etc/NEWS b/etc/NEWS > index 2afed2d253..d21d9cd5ee 100644 > --- a/etc/NEWS > +++ b/etc/NEWS > @@ -138,12 +138,12 @@ line, after a whitespace character, and after an op= ening parenthesis; > and it will replace the apostrophe by a closing quote character in all > other cases. =20 > -** The new variable 'electric-quote-code-faces' controls when to > -disable electric quoting in text modes. Major modes can add faces to > -this list; Emacs will temporarily disable 'electric-quote-mode' > -whenever point is before a character having such a face. This is > -intended for major modes that derive from 'text-mode' but allow inline > -code segments, such as 'markdown-mode'. > +** The new variable 'electric-quote-inhibit-functions' controls when > +to disable electric quoting based on context. Major modes can add > +functions to this list; Emacs will temporarily disable > +'electric-quote-mode' whenever any of the functions returns non-nil. > +This can be used by major modes that derive from 'text-mode' but allow > +inline code segments, such as 'markdown-mode'. =20 > +++ > ** The new user variable 'dired-omit-case-fold' allows the user to > diff --git a/lisp/electric.el b/lisp/electric.el > index 1564df5949..4c1d9039d9 100644 > --- a/lisp/electric.el > +++ b/lisp/electric.el > @@ -451,8 +451,15 @@ electric-quote-context-sensitive > :version "26.1" > :type 'boolean :safe #'booleanp :group 'electricity) =20 > -(defvar electric-quote-code-faces () > - "List of faces to treat as inline code in `text-mode'.") > +(defvar electric-quote-inhibit-functions () > + "List of functions that should inhibit electric quoting. > +When the variable `electric-quote-mode' is non-nil, Emacs will > +call these functions in order after the user has typed an \\=3D` or > +\\=3D' character. If one of them returns non-nil, electric quote > +substitution is inhibited. The functions are called after the > +\\=3D` or \\=3D' character has been inserted with point directly > +after the inserted character. The functions in this hook should > +not move point or change the current buffer.") =20 > (defun electric-quote-post-self-insert-function () > "Function that `electric-quote-mode' adds to `post-self-insert-hook'. > @@ -460,7 +467,9 @@ electric-quote-post-self-insert-function > (when (and electric-quote-mode > (or (eq last-command-event ?\') > (and (not electric-quote-context-sensitive) > - (eq last-command-event ?\`)))) > + (eq last-command-event ?\`))) > + (not (run-hook-with-args-until-success > + 'electric-quote-inhibit-functions))) > (let ((start > (if (and comment-start comment-use-syntax) > (when (or electric-quote-comment electric-quote-string) > @@ -475,10 +484,6 @@ electric-quote-post-self-insert-function > (syntax-ppss (1- (point))))))))) > (and electric-quote-paragraph > (derived-mode-p 'text-mode) > - ;; FIXME: There should be a =E2=80=98cl-disjoint=E2=80= =99 function. > - (null (cl-intersection (face-at-point nil 'multiple) > - electric-quote-code-faces > - :test #'eq)) > ;; FIXME: Why is the next form there? It=E2=80=99s ne= ver > ;; nil. > (or (eq last-command-event ?\`) > diff --git a/test/lisp/electric-tests.el b/test/lisp/electric-tests.el > index 6f63d30e75..9dd27661d4 100644 > --- a/test/lisp/electric-tests.el > +++ b/test/lisp/electric-tests.el > @@ -697,16 +697,24 @@ electric-quote-context-sensitive-after-paren-double > (define-electric-pair-test electric-quote-markdown-in-text > "" "'" :expected-string "=E2=80=99" :expected-point 2 > :modes '(text-mode) > - :fixture-fn #'electric-quote-local-mode > - :bindings '((electric-quote-code-faces font-lock-constant-face)) > + :fixture-fn (lambda () > + (electric-quote-local-mode) > + (add-hook 'electric-quote-inhibit-functions > + (lambda () > + (save-excursion (search-backward "`" nil t))) > + nil :local)) > :test-in-comments nil :test-in-strings nil) =20 > (define-electric-pair-test electric-quote-markdown-in-code > #("`a`" 1 2 (face font-lock-constant-face)) "-'" > :expected-string "`'a`" :expected-point 3 > :modes '(text-mode) > - :fixture-fn #'electric-quote-local-mode > - :bindings '((electric-quote-code-faces font-lock-constant-face)) > + :fixture-fn (lambda () > + (electric-quote-local-mode) > + (add-hook 'electric-quote-inhibit-functions > + (lambda () > + (save-excursion (search-backward "`" nil t))) > + nil :local)) > :test-in-comments nil :test-in-strings nil) =20 > (provide 'electric-tests) > --=20 > 2.13.2.725.g09c95d1e9-goog