all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Interface of prog-prettification
@ 2013-06-16  1:56 Juanma Barranquero
  2013-06-16  9:24 ` Ted Zlatanov
  0 siblings, 1 reply; 20+ messages in thread
From: Juanma Barranquero @ 2013-06-16  1:56 UTC (permalink / raw)
  To: Emacs developers

A few questions about the new prog-prettification.

- prog--prettify-font-lock-compose-symbol's docstring says:
  "Compose a sequence of ascii chars into a symbol."

It is really true that it must be a sequence of ASCII characters? Why?

- Docstring of prog-prettify-symbols says:
  "When set to an alist in the form `((STRING . CHARACTER)...)'"

But in fact, instead of CHARACTER you can use a string, and its
characters will be "composed" (stacked) together.

- I don't fully understand how the user is supposed to extend the
default modes' prog-prettification. What is the expected interface?
Customizing prog-prettify-symbols sets the value for all prog-derived
modes, but what if I want to use different prettifications for
different modes?

I tried adding (set (make-local-variable 'prog-prettify-symbols)
'(("my-symbol" . ?MYCHAR))) to the relevant mode-hook, but that does
not work.

pushing '("my-symbol" . ?MYCHAR) to the corresponding mode-specific
alist (lisp--prettify-symbols-alist,
cfengine3--prettify-symbols-alist, perl--prettify-symbols-alist, etc.)
works, but on one hand, these are internal, non-documented constants;
on the other hand, that does not help to separate lisp-mode from
emacs-lisp-mode, which are initialized from the same alist.

   Juanma



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

* Re: Interface of prog-prettification
  2013-06-16  1:56 Interface of prog-prettification Juanma Barranquero
@ 2013-06-16  9:24 ` Ted Zlatanov
  2013-06-16  9:58   ` Juanma Barranquero
  2013-06-16 22:58   ` Stefan Monnier
  0 siblings, 2 replies; 20+ messages in thread
From: Ted Zlatanov @ 2013-06-16  9:24 UTC (permalink / raw)
  To: emacs-devel

On Sun, 16 Jun 2013 03:56:12 +0200 Juanma Barranquero <lekktu@gmail.com> wrote: 

JB> A few questions about the new prog-prettification.
JB> - prog--prettify-font-lock-compose-symbol's docstring says:
JB>   "Compose a sequence of ascii chars into a symbol."

JB> It is really true that it must be a sequence of ASCII characters? Why?

The original `perl-mode' implementation of the above said that.

JB> - Docstring of prog-prettify-symbols says:
JB>   "When set to an alist in the form `((STRING . CHARACTER)...)'"

JB> But in fact, instead of CHARACTER you can use a string, and its
JB> characters will be "composed" (stacked) together.

Yes.  Handa-san explained how composition works in that case and I
intend to document it, but it's neither explained nor supported right
now.  I think (as already suggested here) that an arbitrary string
should also be supported.

JB> - I don't fully understand how the user is supposed to extend the
JB> default modes' prog-prettification. What is the expected interface?

The user is not supposed to extend it.  I had that originally IIRC but
for simplicity we decided to make it one setting for all prog-modes.
The assumption is that if you like to prettify lambdas as symbols, you
won't mind it everywhere.

JB> Customizing prog-prettify-symbols sets the value for all prog-derived
JB> modes, but what if I want to use different prettifications for
JB> different modes?

JB> I tried adding (set (make-local-variable 'prog-prettify-symbols)
JB> '(("my-symbol" . ?MYCHAR))) to the relevant mode-hook, but that does
JB> not work.

Maybe a mode load hook call to `prog-prettify-install'?  I think
complicating the defcustom might be less user-friendly.  Suggestions
welcome.

JB> pushing '("my-symbol" . ?MYCHAR) to the corresponding mode-specific
JB> alist (lisp--prettify-symbols-alist,
JB> cfengine3--prettify-symbols-alist, perl--prettify-symbols-alist, etc.)
JB> works, but on one hand, these are internal, non-documented constants;
JB> on the other hand, that does not help to separate lisp-mode from
JB> emacs-lisp-mode, which are initialized from the same alist.

Right.  I think these complications, especially the inheritance aspect,
indicate it's better to let the user decide in the load hook than to try
to provide it in a more complicated data structure.

Ted




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

* Re: Interface of prog-prettification
  2013-06-16  9:24 ` Ted Zlatanov
@ 2013-06-16  9:58   ` Juanma Barranquero
  2013-06-16 22:58   ` Stefan Monnier
  1 sibling, 0 replies; 20+ messages in thread
From: Juanma Barranquero @ 2013-06-16  9:58 UTC (permalink / raw)
  To: Emacs developers

On Sun, Jun 16, 2013 at 11:24 AM, Ted Zlatanov <tzz@lifelogs.com> wrote:

> The original `perl-mode' implementation of the above said that.

Well, I haven't tried having a non-ASCII keyword and prettifying it,
but I would be very surprised if it didn't work.

> I think (as already suggested here) that an arbitrary string
> should also be supported.

Yes.

> The user is not supposed to extend it.  I had that originally IIRC but
> for simplicity we decided to make it one setting for all prog-modes.
> The assumption is that if you like to prettify lambdas as symbols, you
> won't mind it everywhere.

That's a strange assumption for an Emacs feature ;-)

> Maybe a mode load hook call to `prog-prettify-install'?  I think
> complicating the defcustom might be less user-friendly.  Suggestions
> welcome.

Do you mean a hook run from prog-prettify-install? Yes, that would work.

As for defcustom, agreed.

> Right.  I think these complications, especially the inheritance aspect,
> indicate it's better to let the user decide in the load hook than to try
> to provide it in a more complicated data structure.

Yes. Though having these variables as user options (not necessarily
defcustoms, but at the very least non-internal) would be nice.

Thanks,

    J



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

* Re: Interface of prog-prettification
  2013-06-16  9:24 ` Ted Zlatanov
  2013-06-16  9:58   ` Juanma Barranquero
@ 2013-06-16 22:58   ` Stefan Monnier
  2013-06-16 23:41     ` Juanma Barranquero
                       ` (2 more replies)
  1 sibling, 3 replies; 20+ messages in thread
From: Stefan Monnier @ 2013-06-16 22:58 UTC (permalink / raw)
  To: emacs-devel

> now.  I think (as already suggested here) that an arbitrary string
> should also be supported.

I'd wait until a concrete use case comes up for it, tho.

JB> - I don't fully understand how the user is supposed to extend the
JB> default modes' prog-prettification. What is the expected interface?

There is no interface for it.

> The assumption is that if you like to prettify lambdas as symbols, you
> won't mind it everywhere.

Oh, I hadn't noticed you made prog-prettify-symbols into a defcustom.
I think that's a mistake.


        Stefan



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

* Re: Interface of prog-prettification
  2013-06-16 22:58   ` Stefan Monnier
@ 2013-06-16 23:41     ` Juanma Barranquero
  2013-06-17  1:00       ` Stefan Monnier
  2013-06-16 23:46     ` Juanma Barranquero
  2013-06-17  6:27     ` Ted Zlatanov
  2 siblings, 1 reply; 20+ messages in thread
From: Juanma Barranquero @ 2013-06-16 23:41 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs developers

On Mon, Jun 17, 2013 at 12:58 AM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:

> There is no interface for it.

Fair enough, though the docstring of prog-prettify-symbols suggests otherwise:

  "Whether symbols should be prettified.
When set to an alist in the form `((STRING . CHARACTER)...)' it
will augment the mode's native prettify alist."

> Oh, I hadn't noticed you made prog-prettify-symbols into a defcustom.
> I think that's a mistake.

Agreed about defcustom, but allowing the user to extend it (via lisp
code) seems useful.

   J



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

* Re: Interface of prog-prettification
  2013-06-16 22:58   ` Stefan Monnier
  2013-06-16 23:41     ` Juanma Barranquero
@ 2013-06-16 23:46     ` Juanma Barranquero
  2013-06-17  6:27     ` Ted Zlatanov
  2 siblings, 0 replies; 20+ messages in thread
From: Juanma Barranquero @ 2013-06-16 23:46 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs developers

On Mon, Jun 17, 2013 at 12:58 AM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:

> There is no interface for it.

Fair enough, though the docstring of prog-prettify-symbols suggests otherwise:

  "Whether symbols should be prettified.
When set to an alist in the form `((STRING . CHARACTER)...)' it
will augment the mode's native prettify alist."

> Oh, I hadn't noticed you made prog-prettify-symbols into a defcustom.
> I think that's a mistake.

Agreed about defcustom, but allowing the user to extend it seems useful.

   J



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

* Re: Interface of prog-prettification
  2013-06-16 23:41     ` Juanma Barranquero
@ 2013-06-17  1:00       ` Stefan Monnier
  2013-06-17  6:25         ` Ted Zlatanov
  0 siblings, 1 reply; 20+ messages in thread
From: Stefan Monnier @ 2013-06-17  1:00 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: Emacs developers

>> Oh, I hadn't noticed you made prog-prettify-symbols into a defcustom.
>> I think that's a mistake.
> Agreed about defcustom, but allowing the user to extend it (via lisp
> code) seems useful.

That would be OK, indeed.  Maybe prog-prettify-install should add to
prog-prettify-symbols-alist rather than just set it.
Or maybe we should just throw away prog-prettify-symbols-alist and pass
the alist to prog-prettify-font-lock-symbols-keywords instead.


        Stefan



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

* Re: Interface of prog-prettification
  2013-06-17  1:00       ` Stefan Monnier
@ 2013-06-17  6:25         ` Ted Zlatanov
  0 siblings, 0 replies; 20+ messages in thread
From: Ted Zlatanov @ 2013-06-17  6:25 UTC (permalink / raw)
  To: emacs-devel

On Sun, 16 Jun 2013 21:00:03 -0400 Stefan Monnier <monnier@iro.umontreal.ca> wrote: 

>>> Oh, I hadn't noticed you made prog-prettify-symbols into a defcustom.
>>> I think that's a mistake.
>> Agreed about defcustom, but allowing the user to extend it (via lisp
>> code) seems useful.

SM> That would be OK, indeed.  Maybe prog-prettify-install should add to
SM> prog-prettify-symbols-alist rather than just set it.
SM> Or maybe we should just throw away prog-prettify-symbols-alist and pass
SM> the alist to prog-prettify-font-lock-symbols-keywords instead.

Perhaps it's for lack of coffee, but I am not sure what you're
suggesting.  Could you show the user-level interface (defcustom or
whatever) and an example of how `emacs-lisp-mode' would use the
facility?

Ted




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

* Re: Interface of prog-prettification
  2013-06-16 22:58   ` Stefan Monnier
  2013-06-16 23:41     ` Juanma Barranquero
  2013-06-16 23:46     ` Juanma Barranquero
@ 2013-06-17  6:27     ` Ted Zlatanov
  2013-06-17 14:31       ` Stefan Monnier
  2 siblings, 1 reply; 20+ messages in thread
From: Ted Zlatanov @ 2013-06-17  6:27 UTC (permalink / raw)
  To: emacs-devel

On Sun, 16 Jun 2013 18:58:16 -0400 Stefan Monnier <monnier@iro.umontreal.ca> wrote: 

>> now.  I think (as already suggested here) that an arbitrary string
>> should also be supported.

SM> I'd wait until a concrete use case comes up for it, tho.

I have 3 concrete use cases: Tassilo, Juanma, and my own.

My use case is that I like "TODO" and "README" to have special treatment
in all programming buffers.

Ted




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

* Re: Interface of prog-prettification
  2013-06-17  6:27     ` Ted Zlatanov
@ 2013-06-17 14:31       ` Stefan Monnier
  2013-06-17 16:04         ` Juanma Barranquero
  0 siblings, 1 reply; 20+ messages in thread
From: Stefan Monnier @ 2013-06-17 14:31 UTC (permalink / raw)
  To: emacs-devel

> I have 3 concrete use cases: Tassilo, Juanma, and my own.
> My use case is that I like "TODO" and "README" to have special treatment
> in all programming buffers.

That is a claim that 3 people have a use case for it and that one of
those use cases involves the words TODO and README.

But I don't see any description of a concrete use case here.


        Stefan



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

* Re: Interface of prog-prettification
  2013-06-17 14:31       ` Stefan Monnier
@ 2013-06-17 16:04         ` Juanma Barranquero
  2013-06-17 16:27           ` Stefan Monnier
  2013-06-17 19:13           ` Ted Zlatanov
  0 siblings, 2 replies; 20+ messages in thread
From: Juanma Barranquero @ 2013-06-17 16:04 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs developers

On Mon, Jun 17, 2013 at 4:31 PM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:

> That is a claim that 3 people have a use case for it and that one of
> those use cases involves the words TODO and README.
>
> But I don't see any description of a concrete use case here.

Truth be told, I don't have a use case, and Ted's comment about my
position is a misunderstanding, I think. I just pointed out that
composition can compose to strings, not just characters (but that is
not the same that substituting one string of chars by another one).

That said, a facility for making that ("visually" replacing one string
by another) could be useful (via composition, display specs, or
whatever) but I don't think it is something specifically related to
prog mode or symbol prettification. Seems like some sort of
as-yet-unimplemented minor mode to me.

Speaking of which... Why is this symbol prettification some
semi-obscure feature of programming modes, instead of a minor mode to
be enabled by the user however he sees fit?

   J



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

* Re: Interface of prog-prettification
  2013-06-17 16:04         ` Juanma Barranquero
@ 2013-06-17 16:27           ` Stefan Monnier
  2013-06-17 23:08             ` Juanma Barranquero
  2013-06-17 19:13           ` Ted Zlatanov
  1 sibling, 1 reply; 20+ messages in thread
From: Stefan Monnier @ 2013-06-17 16:27 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: Emacs developers

> Speaking of which... Why is this symbol prettification some
> semi-obscure feature of programming modes, instead of a minor mode to
> be enabled by the user however he sees fit?

Accident, mostly.  Feel free to make it into a minor mode.

The important part is that the actual symbols to handle vary
between languages (e.g. mapping \ to λ makes sense for Haskell, but not
for most other languages).


        Stefan



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

* Re: Interface of prog-prettification
  2013-06-17 16:04         ` Juanma Barranquero
  2013-06-17 16:27           ` Stefan Monnier
@ 2013-06-17 19:13           ` Ted Zlatanov
  1 sibling, 0 replies; 20+ messages in thread
From: Ted Zlatanov @ 2013-06-17 19:13 UTC (permalink / raw)
  To: emacs-devel

On Mon, 17 Jun 2013 18:04:40 +0200 Juanma Barranquero <lekktu@gmail.com> wrote: 

JB> On Mon, Jun 17, 2013 at 4:31 PM, Stefan Monnier
JB> <monnier@iro.umontreal.ca> wrote:

>> That is a claim that 3 people have a use case for it and that one of
>> those use cases involves the words TODO and README.
>> 
>> But I don't see any description of a concrete use case here.

JB> a facility for ["visually" replacing one string by another]) could
JB> be useful (via composition, display specs, or whatever) but I don't
JB> think it is something specifically related to prog mode or symbol
JB> prettification. Seems like some sort of as-yet-unimplemented minor
JB> mode to me.

OK.

JB> Speaking of which... Why is this symbol prettification some
JB> semi-obscure feature of programming modes, instead of a minor mode to
JB> be enabled by the user however he sees fit?

Because most non-programming modes don't deal with symbols, and all the
use cases I knew were for programming modes.  But it would work as a
minor mode, sure.  If you'd like to implement it that way, feel free.
Just remove the old defcustom and whatever else you don't need anymore.

Ted




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

* Re: Interface of prog-prettification
  2013-06-17 16:27           ` Stefan Monnier
@ 2013-06-17 23:08             ` Juanma Barranquero
  2013-06-18  1:00               ` Stefan Monnier
  0 siblings, 1 reply; 20+ messages in thread
From: Juanma Barranquero @ 2013-06-17 23:08 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Ted Zlatanov, Emacs developers

On Mon, Jun 17, 2013 at 6:27 PM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:

> Accident, mostly.  Feel free to make it into a minor mode.
>
> The important part is that the actual symbols to handle vary
> between languages (e.g. mapping \ to λ makes sense for Haskell, but not
> for most other languages).


On Mon, Jun 17, 2013 at 9:13 PM, Ted Zlatanov <tzz@lifelogs.com> wrote:

> But it would work as a
> minor mode, sure.  If you'd like to implement it that way, feel free.
> Just remove the old defcustom and whatever else you don't need anymore.


Without ChangeLogs (and prettify-symbols-mode is still in
prog-mode.el, though it is not really prog-mode specific).


=== modified file 'etc/NEWS'
--- etc/NEWS 2013-06-17 15:28:22 +0000
+++ etc/NEWS 2013-06-17 22:33:14 +0000
@@ -2873,10 +2873,9 @@
 modes, e.g. (add-hook 'prog-mode-hook 'flyspell-prog-mode) to enable
 on-the-fly spell checking for comments and strings.

-**** New option, `prog-prettify-symbols' lets the user control symbol
-prettify (replacing a string like "lambda" with the Greek lambda
-character).  The mode derived from `prog-mode' must call
-`prog-prettify-install' with its own custom alist, which can be empty.
+**** New minor mode, `prettify-symbols-mode', lets the user enable
+symbol prettification (replacing a string like "lambda" with the Greek
+lambda character).

 *** New hook `change-major-mode-after-body-hook', run by
 `run-mode-hooks' just before any other mode hooks.

=== modified file 'lisp/emacs-lisp/lisp-mode.el'
--- lisp/emacs-lisp/lisp-mode.el 2013-06-15 09:16:49 +0000
+++ lisp/emacs-lisp/lisp-mode.el 2013-06-17 22:53:23 +0000
@@ -231,7 +231,7 @@
   (font-lock-mark-block-function . mark-defun)
   (font-lock-syntactic-face-function
    . lisp-font-lock-syntactic-face-function)))
-  (prog-prettify-install lisp--prettify-symbols-alist))
+  (setq prettify-symbols-alist lisp--prettify-symbols-alist))

 (defun lisp-outline-level ()
   "Lisp mode `outline-level' function."

=== modified file 'lisp/progmodes/cfengine.el'
--- lisp/progmodes/cfengine.el 2013-06-05 17:48:50 +0000
+++ lisp/progmodes/cfengine.el 2013-06-17 22:53:51 +0000
@@ -547,7 +547,7 @@
   (setq font-lock-defaults
         '(cfengine3-font-lock-keywords
           nil nil nil beginning-of-defun))
-  (prog-prettify-install cfengine3--prettify-symbols-alist)
+  (setq prettify-symbols-alist cfengine3--prettify-symbols-alist)

   ;; Use defuns as the essential syntax block.
   (set (make-local-variable 'beginning-of-defun-function)

=== modified file 'lisp/progmodes/perl-mode.el'
--- lisp/progmodes/perl-mode.el 2013-06-05 17:48:50 +0000
+++ lisp/progmodes/perl-mode.el 2013-06-17 22:52:38 +0000
@@ -658,7 +658,7 @@
                              nil nil ((?\_ . "w")) nil
                              (font-lock-syntactic-face-function
                               . perl-font-lock-syntactic-face-function)))
-  (prog-prettify-install perl--prettify-symbols-alist)
+  (setq prettify-symbols-alist perl--prettify-symbols-alist)
   (setq-local syntax-propertize-function #'perl-syntax-propertize-function)
   (add-hook 'syntax-propertize-extend-region-functions
             #'syntax-propertize-multiline 'append 'local)

=== modified file 'lisp/progmodes/prog-mode.el'
--- lisp/progmodes/prog-mode.el 2013-06-17 01:09:13 +0000
+++ lisp/progmodes/prog-mode.el 2013-06-17 23:07:03 +0000
@@ -54,21 +54,14 @@
   (end (progn (forward-sexp 1) (point))))
       (indent-region start end nil))))

-(defvar prog-prettify-symbols-alist nil)
-
-(defcustom prog-prettify-symbols nil
-  "Whether symbols should be prettified.
-When set to an alist in the form `((STRING . CHARACTER)...)' it
-will augment the mode's native prettify alist."
-  :type '(choice
-          (const :tag "No thanks" nil)
-          (const :tag "Mode defaults" t)
-          (alist :tag "Mode defaults augmented with your own list"
-                 :key-type string :value-type character))
-  :version "24.4")
-
-(defun prog--prettify-font-lock-compose-symbol (alist)
-  "Compose a sequence of ascii chars into a symbol.
+(defvar-local prettify-symbols-alist nil
+  "Alist of symbol prettifications.
+Each element looks like (SYMBOL . CHARACTER), where the symbol
+matching SYMBOL (a string, not a regexp) will be shown as
+CHARACTER instead.")
+
+(defun prettify-symbols--compose-symbol (alist)
+  "Compose a sequence of characters into a symbol.
 Regexp match data 0 points to the chars."
   ;; Check that the chars should really be composed into a symbol.
   (let* ((start (match-beginning 0))
@@ -88,28 +81,48 @@
   ;; Return nil because we're not adding any face property.
   nil)

-(defun prog-prettify-font-lock-symbols-keywords ()
-  (when prog-prettify-symbols
-    (let ((alist (append prog-prettify-symbols-alist
-                         (if (listp prog-prettify-symbols)
-                             prog-prettify-symbols
-                           nil))))
-      `((,(regexp-opt (mapcar 'car alist) t)
-         (0 (prog--prettify-font-lock-compose-symbol ',alist)))))))
-
-(defun prog-prettify-install (alist)
-"Install prog-mode support to prettify symbols according to ALIST.
-
-ALIST is in the format `((STRING . CHARACTER)...)' like
-`prog-prettify-symbols'.
-
-Internally, `font-lock-add-keywords' is called."
-  (setq-local prog-prettify-symbols-alist alist)
-  (let ((keywords (prog-prettify-font-lock-symbols-keywords)))
-    (when keywords
-      (font-lock-add-keywords nil keywords)
-      (setq-local font-lock-extra-managed-props
-                  (cons 'composition font-lock-extra-managed-props)))))
+(defun prettify-symbols--make-keywords ()
+  (if prettify-symbols-alist
+      `((,(regexp-opt (mapcar 'car prettify-symbols-alist) t)
+         (0 (prettify-symbols--compose-symbol ',prettify-symbols-alist))))
+    nil))
+
+(defvar-local prettify-symbols--keywords nil)
+
+(define-minor-mode prettify-symbols-mode
+  "Toggle Prettify Symbols mode.
+With a prefix argument ARG, enable Prettify Symbols mode if ARG is
+positive, and disable it otherwise.  If called from Lisp, enable
+the mode if ARG is omitted or nil.
+
+When Prettify Symbols mode and font-locking are enabled, symbols are
+prettified (displayed as composed characters) according to the rules
+in `prettify-symbols-alist' (which see), which are locally defined
+by major modes supporting prettifying.  To use this mode, you should
+enable it in the major mode hook, and optionally extend the default
+set of prettifications, like this:
+
+  (add-hook 'emacs-lisp-mode-hook
+            (lambda ()
+              (push '(\"<=\" . ?≤) prettify-symbols-alist)
+              (prettify-symbols-mode 1)))"
+  :init-value nil
+  (if prettify-symbols-mode
+      ;; Turn on
+      (when (setq prettify-symbols--keywords (prettify-symbols--make-keywords))
+        (font-lock-add-keywords nil prettify-symbols--keywords)
+        (setq-local font-lock-extra-managed-props
+                    (cons 'composition font-lock-extra-managed-props))
+        (font-lock-fontify-buffer))
+    ;; Turn off
+    (when prettify-symbols--keywords
+      (font-lock-remove-keywords nil prettify-symbols--keywords)
+      (setq prettify-symbols--keywords nil))
+    (when (memq 'composition font-lock-extra-managed-props)
+      (setq font-lock-extra-managed-props (delq 'composition
+                                                font-lock-extra-managed-props))
+      (with-silent-modifications
+        (remove-text-properties (point-min) (point-max) '(composition nil))))))

 ;;;###autoload
 (define-derived-mode prog-mode fundamental-mode "Prog"



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

* Re: Interface of prog-prettification
  2013-06-17 23:08             ` Juanma Barranquero
@ 2013-06-18  1:00               ` Stefan Monnier
  2013-06-18  1:38                 ` Juanma Barranquero
  0 siblings, 1 reply; 20+ messages in thread
From: Stefan Monnier @ 2013-06-18  1:00 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: Ted Zlatanov, Emacs developers

> +**** New minor mode, `prettify-symbols-mode', lets the user enable
> +symbol prettification (replacing a string like "lambda" with the Greek
> +lambda character).

Looks OK, but a major motivation of the move to prog-mode was to provide
a global setting for it, so we need a global minor mode for it.


        Stefan



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

* Re: Interface of prog-prettification
  2013-06-18  1:00               ` Stefan Monnier
@ 2013-06-18  1:38                 ` Juanma Barranquero
  2013-06-18 15:02                   ` Ted Zlatanov
  0 siblings, 1 reply; 20+ messages in thread
From: Juanma Barranquero @ 2013-06-18  1:38 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Ted Zlatanov, Emacs developers

On Tue, Jun 18, 2013 at 3:00 AM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:

> Looks OK, but a major motivation of the move to prog-mode was to provide
> a global setting for it, so we need a global minor mode for it.


=== modified file 'etc/NEWS'
--- etc/NEWS 2013-06-17 15:28:22 +0000
+++ etc/NEWS 2013-06-18 01:37:01 +0000
@@ -2873,10 +2873,10 @@
 modes, e.g. (add-hook 'prog-mode-hook 'flyspell-prog-mode) to enable
 on-the-fly spell checking for comments and strings.

-**** New option, `prog-prettify-symbols' lets the user control symbol
-prettify (replacing a string like "lambda" with the Greek lambda
-character).  The mode derived from `prog-mode' must call
-`prog-prettify-install' with its own custom alist, which can be empty.
+**** New minor modes `prettify-symbols-mode' and
+`global-prettify-symbols-mode' let the user enable symbol
+prettification (replacing a string like "lambda" with the Greek lambda
+character).

 *** New hook `change-major-mode-after-body-hook', run by
 `run-mode-hooks' just before any other mode hooks.

=== modified file 'lisp/emacs-lisp/lisp-mode.el'
--- lisp/emacs-lisp/lisp-mode.el 2013-06-15 09:16:49 +0000
+++ lisp/emacs-lisp/lisp-mode.el 2013-06-18 01:13:12 +0000
@@ -231,7 +231,7 @@
   (font-lock-mark-block-function . mark-defun)
   (font-lock-syntactic-face-function
    . lisp-font-lock-syntactic-face-function)))
-  (prog-prettify-install lisp--prettify-symbols-alist))
+  (setq prettify-symbols-alist lisp--prettify-symbols-alist))

 (defun lisp-outline-level ()
   "Lisp mode `outline-level' function."

=== modified file 'lisp/progmodes/cfengine.el'
--- lisp/progmodes/cfengine.el 2013-06-05 17:48:50 +0000
+++ lisp/progmodes/cfengine.el 2013-06-18 01:13:12 +0000
@@ -547,7 +547,7 @@
   (setq font-lock-defaults
         '(cfengine3-font-lock-keywords
           nil nil nil beginning-of-defun))
-  (prog-prettify-install cfengine3--prettify-symbols-alist)
+  (setq prettify-symbols-alist cfengine3--prettify-symbols-alist)

   ;; Use defuns as the essential syntax block.
   (set (make-local-variable 'beginning-of-defun-function)

=== modified file 'lisp/progmodes/perl-mode.el'
--- lisp/progmodes/perl-mode.el 2013-06-05 17:48:50 +0000
+++ lisp/progmodes/perl-mode.el 2013-06-18 01:13:12 +0000
@@ -658,7 +658,7 @@
                              nil nil ((?\_ . "w")) nil
                              (font-lock-syntactic-face-function
                               . perl-font-lock-syntactic-face-function)))
-  (prog-prettify-install perl--prettify-symbols-alist)
+  (setq prettify-symbols-alist perl--prettify-symbols-alist)
   (setq-local syntax-propertize-function #'perl-syntax-propertize-function)
   (add-hook 'syntax-propertize-extend-region-functions
             #'syntax-propertize-multiline 'append 'local)

=== modified file 'lisp/progmodes/prog-mode.el'
--- lisp/progmodes/prog-mode.el 2013-06-17 01:09:13 +0000
+++ lisp/progmodes/prog-mode.el 2013-06-18 01:35:48 +0000
@@ -54,21 +54,14 @@
   (end (progn (forward-sexp 1) (point))))
       (indent-region start end nil))))

-(defvar prog-prettify-symbols-alist nil)
-
-(defcustom prog-prettify-symbols nil
-  "Whether symbols should be prettified.
-When set to an alist in the form `((STRING . CHARACTER)...)' it
-will augment the mode's native prettify alist."
-  :type '(choice
-          (const :tag "No thanks" nil)
-          (const :tag "Mode defaults" t)
-          (alist :tag "Mode defaults augmented with your own list"
-                 :key-type string :value-type character))
-  :version "24.4")
-
-(defun prog--prettify-font-lock-compose-symbol (alist)
-  "Compose a sequence of ascii chars into a symbol.
+(defvar-local prettify-symbols-alist nil
+  "Alist of symbol prettifications.
+Each element looks like (SYMBOL . CHARACTER), where the symbol
+matching SYMBOL (a string, not a regexp) will be shown as
+CHARACTER instead.")
+
+(defun prettify-symbols--compose-symbol (alist)
+  "Compose a sequence of characters into a symbol.
 Regexp match data 0 points to the chars."
   ;; Check that the chars should really be composed into a symbol.
   (let* ((start (match-beginning 0))
@@ -88,28 +81,60 @@
   ;; Return nil because we're not adding any face property.
   nil)

-(defun prog-prettify-font-lock-symbols-keywords ()
-  (when prog-prettify-symbols
-    (let ((alist (append prog-prettify-symbols-alist
-                         (if (listp prog-prettify-symbols)
-                             prog-prettify-symbols
-                           nil))))
-      `((,(regexp-opt (mapcar 'car alist) t)
-         (0 (prog--prettify-font-lock-compose-symbol ',alist)))))))
-
-(defun prog-prettify-install (alist)
-"Install prog-mode support to prettify symbols according to ALIST.
-
-ALIST is in the format `((STRING . CHARACTER)...)' like
-`prog-prettify-symbols'.
-
-Internally, `font-lock-add-keywords' is called."
-  (setq-local prog-prettify-symbols-alist alist)
-  (let ((keywords (prog-prettify-font-lock-symbols-keywords)))
-    (when keywords
-      (font-lock-add-keywords nil keywords)
-      (setq-local font-lock-extra-managed-props
-                  (cons 'composition font-lock-extra-managed-props)))))
+(defun prettify-symbols--make-keywords ()
+  (if prettify-symbols-alist
+      `((,(regexp-opt (mapcar 'car prettify-symbols-alist) t)
+         (0 (prettify-symbols--compose-symbol ',prettify-symbols-alist))))
+    nil))
+
+(defvar-local prettify-symbols--keywords nil)
+
+;;;###autoload
+(define-minor-mode prettify-symbols-mode
+  "Toggle Prettify Symbols mode.
+With a prefix argument ARG, enable Prettify Symbols mode if ARG is
+positive, and disable it otherwise.  If called from Lisp, enable
+the mode if ARG is omitted or nil.
+
+When Prettify Symbols mode and font-locking are enabled, symbols are
+prettified (displayed as composed characters) according to the rules
+in `prettify-symbols-alist' (which see), which are locally defined
+by major modes supporting prettifying.  To add further customizations
+for a given major mode, you can modify `prettify-symbols-alist' thus:
+
+  (add-hook 'emacs-lisp-mode-hook
+            (lambda ()
+              (push '(\"<=\" . ?≤) prettify-symbols-alist)))
+
+You can enable this mode locally in desired buffers, or use
+`global-prettify-symbols-mode' to enable it for all modes that
+support it."
+  :init-value nil
+  (if prettify-symbols-mode
+      ;; Turn on
+      (when (setq prettify-symbols--keywords (prettify-symbols--make-keywords))
+        (font-lock-add-keywords nil prettify-symbols--keywords)
+        (setq-local font-lock-extra-managed-props
+                    (cons 'composition font-lock-extra-managed-props))
+        (font-lock-fontify-buffer))
+    ;; Turn off
+    (when prettify-symbols--keywords
+      (font-lock-remove-keywords nil prettify-symbols--keywords)
+      (setq prettify-symbols--keywords nil))
+    (when (memq 'composition font-lock-extra-managed-props)
+      (setq font-lock-extra-managed-props (delq 'composition
+                                                font-lock-extra-managed-props))
+      (with-silent-modifications
+        (remove-text-properties (point-min) (point-max) '(composition nil))))))
+
+(defun turn-on-prettify-symbols-mode ()
+  (when (and (not prettify-symbols-mode)
+             (local-variable-p 'prettify-symbols-alist))
+    (prettify-symbols-mode 1)))
+
+;;;###autoload
+(define-globalized-minor-mode global-prettify-symbols-mode
+  prettify-symbols-mode turn-on-prettify-symbols-mode)

 ;;;###autoload
 (define-derived-mode prog-mode fundamental-mode "Prog"



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

* Re: Interface of prog-prettification
  2013-06-18  1:38                 ` Juanma Barranquero
@ 2013-06-18 15:02                   ` Ted Zlatanov
  2013-06-18 19:17                     ` Stefan Monnier
  0 siblings, 1 reply; 20+ messages in thread
From: Ted Zlatanov @ 2013-06-18 15:02 UTC (permalink / raw)
  To: emacs-devel

On Tue, 18 Jun 2013 03:38:56 +0200 Juanma Barranquero <lekktu@gmail.com> wrote: 

JB> === modified file 'lisp/emacs-lisp/lisp-mode.el'
JB> +  (setq prettify-symbols-alist lisp--prettify-symbols-alist))

JB> === modified file 'lisp/progmodes/cfengine.el'
JB> +  (setq prettify-symbols-alist cfengine3--prettify-symbols-alist)

JB> === modified file 'lisp/progmodes/perl-mode.el'
JB> +  (setq prettify-symbols-alist perl--prettify-symbols-alist)

Looks good to me.

Ted




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

* Re: Interface of prog-prettification
  2013-06-18 15:02                   ` Ted Zlatanov
@ 2013-06-18 19:17                     ` Stefan Monnier
  2013-06-18 19:42                       ` Juanma Barranquero
  0 siblings, 1 reply; 20+ messages in thread
From: Stefan Monnier @ 2013-06-18 19:17 UTC (permalink / raw)
  To: emacs-devel

JB> +  (setq prettify-symbols-alist lisp--prettify-symbols-alist))
JB> +  (setq prettify-symbols-alist cfengine3--prettify-symbols-alist)
JB> +  (setq prettify-symbols-alist perl--prettify-symbols-alist)

BTW, I'd use setq-local because I can't be bothered to try and remember
which vars were made buffer-local and which ones weren't and which var's
definining package is known to be already loaded and which one isn't.


        Stefan



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

* Re: Interface of prog-prettification
  2013-06-18 19:17                     ` Stefan Monnier
@ 2013-06-18 19:42                       ` Juanma Barranquero
  2013-06-18 20:26                         ` Stefan Monnier
  0 siblings, 1 reply; 20+ messages in thread
From: Juanma Barranquero @ 2013-06-18 19:42 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs developers

> JB> +  (setq prettify-symbols-alist lisp--prettify-symbols-alist))
> JB> +  (setq prettify-symbols-alist cfengine3--prettify-symbols-alist)
> JB> +  (setq prettify-symbols-alist perl--prettify-symbols-alist)
>
> BTW, I'd use setq-local because I can't be bothered to try and remember
> which vars were made buffer-local and which ones weren't and which var's
> definining package is known to be already loaded and which one isn't.

Yeah, that's a good idea. I'll change it.

I'm assuming that you don't have any more comments and it's OK to install it.

   J



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

* Re: Interface of prog-prettification
  2013-06-18 19:42                       ` Juanma Barranquero
@ 2013-06-18 20:26                         ` Stefan Monnier
  0 siblings, 0 replies; 20+ messages in thread
From: Stefan Monnier @ 2013-06-18 20:26 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: Emacs developers

> I'm assuming that you don't have any more comments and it's OK to install it.

Rightly so,


        Stefan



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

end of thread, other threads:[~2013-06-18 20:26 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-16  1:56 Interface of prog-prettification Juanma Barranquero
2013-06-16  9:24 ` Ted Zlatanov
2013-06-16  9:58   ` Juanma Barranquero
2013-06-16 22:58   ` Stefan Monnier
2013-06-16 23:41     ` Juanma Barranquero
2013-06-17  1:00       ` Stefan Monnier
2013-06-17  6:25         ` Ted Zlatanov
2013-06-16 23:46     ` Juanma Barranquero
2013-06-17  6:27     ` Ted Zlatanov
2013-06-17 14:31       ` Stefan Monnier
2013-06-17 16:04         ` Juanma Barranquero
2013-06-17 16:27           ` Stefan Monnier
2013-06-17 23:08             ` Juanma Barranquero
2013-06-18  1:00               ` Stefan Monnier
2013-06-18  1:38                 ` Juanma Barranquero
2013-06-18 15:02                   ` Ted Zlatanov
2013-06-18 19:17                     ` Stefan Monnier
2013-06-18 19:42                       ` Juanma Barranquero
2013-06-18 20:26                         ` Stefan Monnier
2013-06-17 19:13           ` Ted Zlatanov

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.