all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: [Emacs-diffs] master 34d4720: Electric quotes: Improve support for Markdown mode (Bug#24709)
       [not found] ` <20170702154852.1796522E35@vcs0.savannah.gnu.org>
@ 2017-07-02 17:48   ` Stefan Monnier
  2017-07-03 16:48     ` Philipp Stephani
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2017-07-02 17:48 UTC (permalink / raw
  To: emacs-devel; +Cc: Philipp Stephani

>     Also introduce a new variable 'electric-quote-code-faces'.  Major
>     modes such as 'markdown-mode' can add faces to this list to treat text
>     as inline code and disable electric quoting.
    
Hmm... FWIW I don't like using faces for that (e.g. it means the
features doesn't work when the user disables font-lock-mode, even in
cases where it's easy to decide what to do based on syntax-ppss for
example).
Why not use a electric-quote-inhibit-function hook instead?


        Stefan



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Emacs-diffs] master 34d4720: Electric quotes: Improve support for Markdown mode (Bug#24709)
  2017-07-02 17:48   ` [Emacs-diffs] master 34d4720: Electric quotes: Improve support for Markdown mode (Bug#24709) Stefan Monnier
@ 2017-07-03 16:48     ` Philipp Stephani
  2017-07-03 18:36       ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Philipp Stephani @ 2017-07-03 16:48 UTC (permalink / raw
  To: Stefan Monnier, emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 1237 bytes --]

Stefan Monnier <monnier@iro.umontreal.ca> schrieb am So., 2. Juli 2017 um
19:48 Uhr:

> >     Also introduce a new variable 'electric-quote-code-faces'.  Major
> >     modes such as 'markdown-mode' can add faces to this list to treat
> text
> >     as inline code and disable electric quoting.
>
> Hmm... FWIW I don't like using faces for that (e.g. it means the
> features doesn't work when the user disables font-lock-mode, even in
> cases where it's easy to decide what to do based on syntax-ppss for
> example).
> Why not use a electric-quote-inhibit-function hook instead?
>
>
Good point, here's another patch.
-- 

Google Germany GmbH
Erika-Mann-Straße 33
80636 München

Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: 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öschen Sie die E-Mail und alle Anhänge. 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.

[-- Attachment #1.2: Type: text/html, Size: 1738 bytes --]

[-- Attachment #2: 0001-Use-hook-instead-of-face-list-to-inhibit-electric-quot.txt --]
[-- Type: text/plain, Size: 5795 bytes --]

From 287a333286f5441128a1169be75e89461823e3af Mon Sep 17 00:00:00 2001
From: Philipp Stephani <phst@google.com>
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 opening parenthesis;
 and it will replace the apostrophe by a closing quote character in all
 other cases.
 
-** 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'.
 
 +++
 ** 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)
 
-(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 \\=` or
+\\=' character.  If one of them returns non-nil, electric quote
+substitution is inhibited.  The functions are called after the
+\\=` or \\=' 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.")
 
 (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 ‘cl-disjoint’ function.
-                  (null (cl-intersection (face-at-point nil 'multiple)
-                                         electric-quote-code-faces
-                                         :test #'eq))
                   ;; FIXME: Why is the next form there?  It’s never
                   ;; 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 "’" :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)
 
 (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)
 
 (provide 'electric-tests)
-- 
2.13.2.725.g09c95d1e9-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Emacs-diffs] master 34d4720: Electric quotes: Improve support for Markdown mode (Bug#24709)
  2017-07-03 16:48     ` Philipp Stephani
@ 2017-07-03 18:36       ` Stefan Monnier
  2017-07-03 19:00         ` Philipp Stephani
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2017-07-03 18:36 UTC (permalink / raw
  To: Philipp Stephani; +Cc: emacs-devel

> Good point, here's another patch.

Looks good, thanks.


        Stefan


> Google Germany GmbH
> Erika-Mann-Straße 33
> 80636 München

> Registergericht und -nummer: Hamburg, HRB 86891
> Sitz der Gesellschaft: Hamburg
> Geschäftsführer: 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öschen Sie die E-Mail und alle Anhänge. 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 <phst@google.com>
> 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 opening parenthesis;
>  and it will replace the apostrophe by a closing quote character in all
>  other cases.
 
> -** 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'.
 
>  +++
>  ** 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)
 
> -(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 \\=` or
> +\\=' character.  If one of them returns non-nil, electric quote
> +substitution is inhibited.  The functions are called after the
> +\\=` or \\=' 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.")
 
>  (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 ‘cl-disjoint’ function.
> -                  (null (cl-intersection (face-at-point nil 'multiple)
> -                                         electric-quote-code-faces
> -                                         :test #'eq))
>                    ;; FIXME: Why is the next form there?  It’s never
>                    ;; 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 "’" :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)
 
>  (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)
 
>  (provide 'electric-tests)
> -- 
> 2.13.2.725.g09c95d1e9-goog





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Emacs-diffs] master 34d4720: Electric quotes: Improve support for Markdown mode (Bug#24709)
  2017-07-03 18:36       ` Stefan Monnier
@ 2017-07-03 19:00         ` Philipp Stephani
  0 siblings, 0 replies; 4+ messages in thread
From: Philipp Stephani @ 2017-07-03 19:00 UTC (permalink / raw
  To: Stefan Monnier; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 787 bytes --]

Stefan Monnier <monnier@iro.umontreal.ca> schrieb am Mo., 3. Juli 2017 um
20:36 Uhr:

> > Good point, here's another patch.
>
> Looks good, thanks.
>

Pushed as 4cd0db3d6e.
-- 

Google Germany GmbH
Erika-Mann-Straße 33
80636 München

Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: 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öschen Sie die E-Mail und alle Anhänge. 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.

[-- Attachment #2: Type: text/html, Size: 1228 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-07-03 19:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20170702154850.22058.98643@vcs0.savannah.gnu.org>
     [not found] ` <20170702154852.1796522E35@vcs0.savannah.gnu.org>
2017-07-02 17:48   ` [Emacs-diffs] master 34d4720: Electric quotes: Improve support for Markdown mode (Bug#24709) Stefan Monnier
2017-07-03 16:48     ` Philipp Stephani
2017-07-03 18:36       ` Stefan Monnier
2017-07-03 19:00         ` Philipp Stephani

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.