bug#28713: Inconvenient usage of defconst in python-mode

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

bug#28713: Inconvenient usage of defconst in python-mode

Lele Gaifax
In Emacs 25+, to be exact after commit
dadcf33984391a285ef0b161c1122864264e4386, python-mode uses a defconst to
define the value of `python--prettify-symbols-alist':

  (defconst python--prettify-symbols-alist
    '(("lambda"  . ?\u03bb)
      ("and" . ?\u2227)
      ("or" . ?\u2228)))

that is used just once in the major mode initializer:

  (set (make-local-variable 'prettify-symbols-alist)
       python--prettify-symbols-alist)

While the replacement for "lambda" is pretty, I find the other two quite
unreadable. To get rid of those I cannot simply customize the alist, but I
have to do something like the following in one of my python-mode-hooks:

  ;; Prettify only lambda keyword
  (setq prettify-symbols-alist '(("lambda" . ?λ)))

  ;; Force a refresh
  (prettify-symbols-mode -1)
  (prettify-symbols-mode))

This is of course a minor hassle, but I wonder if the major mode could/should
use a normal variable (if not a defcustom) instead.

Thanks&bye, lele.
--
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
[hidden email]  |                 -- Fortunato Depero, 1929.



Reply | Threaded
Open this post in threaded view
|

bug#28713: Inconvenient usage of defconst in python-mode

Noam Postavsky-2
severity 28713 minor
tags 28713 + patch
quit

Lele Gaifax <[hidden email]> writes:

> have to do something like the following in one of my python-mode-hooks:
>
>   ;; Prettify only lambda keyword
>   (setq prettify-symbols-alist '(("lambda" . ?λ)))
>
>   ;; Force a refresh
>   (prettify-symbols-mode -1)
>   (prettify-symbols-mode))

Actually you could probably get away with

(with-eval-after-load 'python
  (setq python--prettify-symbols-alist '(("lambda" . ?λ))))

since defconst doesn't actually make anything const.

> This is of course a minor hassle, but I wonder if the major mode could/should
> use a normal variable (if not a defcustom) instead.

prettify-symbols-alist is not a defcustom, due to some uncertainty over
how to produce a reasonable interface for customizing it, if I recall
correctly.  So I think the python-mode version should not be a defcustom
either, but I see no reason against making it a normal variable:


From c430329a2138674c8d67ccb3f4ce92c6b75972b7 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <[hidden email]>
Date: Thu, 5 Oct 2017 19:16:46 -0400
Subject: [PATCH v1] Make python prettify symbols into a defvar (Bug#28713)

* lisp/progmodes/python.el (python-prettify-symbols-alist): New
variable.
(python--prettify-symbols-alist): Make into obsolete alias for
`python-prettify-symbols-alist'.
---
 lisp/progmodes/python.el | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 9aa5134ca0..f79d9a47d3 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -640,10 +640,14 @@ python-syntax-propertize-function
    ((python-rx string-delimiter)
     (0 (ignore (python-syntax-stringify))))))
 
-(defconst python--prettify-symbols-alist
+(defvar python-prettify-symbols-alist
   '(("lambda"  . ?λ)
     ("and" . ?∧)
-    ("or" . ?∨)))
+    ("or" . ?∨))
+  "Value for `prettify-symbols-alist' in `python-mode'.")
+
+(define-obsolete-variable-alias 'python--prettify-symbols-alist
+  'python-prettify-symbols-alist "26.1")
 
 (defsubst python-syntax-count-quotes (quote-char &optional point limit)
   "Count number of quotes around point (max is 3).
--
2.11.0

Reply | Threaded
Open this post in threaded view
|

bug#28713: Inconvenient usage of defconst in python-mode

Eli Zaretskii
> From: Noam Postavsky <[hidden email]>
> Date: Thu, 05 Oct 2017 19:42:52 -0400
> Cc: [hidden email]
>
> > This is of course a minor hassle, but I wonder if the major mode could/should
> > use a normal variable (if not a defcustom) instead.
>
> prettify-symbols-alist is not a defcustom, due to some uncertainty over
> how to produce a reasonable interface for customizing it, if I recall
> correctly.  So I think the python-mode version should not be a defcustom
> either, but I see no reason against making it a normal variable:

Thanks, LGTM.



Reply | Threaded
Open this post in threaded view
|

bug#28713: Inconvenient usage of defconst in python-mode

Noam Postavsky-2
tags 28713 fixed
close 28713 26.1
quit

Eli Zaretskii <[hidden email]> writes:

>> From: Noam Postavsky <[hidden email]>
>> Date: Thu, 05 Oct 2017 19:42:52 -0400
>> Cc: [hidden email]
>>
>> > This is of course a minor hassle, but I wonder if the major mode could/should
>> > use a normal variable (if not a defcustom) instead.
>>
>> prettify-symbols-alist is not a defcustom, due to some uncertainty over
>> how to produce a reasonable interface for customizing it, if I recall
>> correctly.  So I think the python-mode version should not be a defcustom
>> either, but I see no reason against making it a normal variable:
>
> Thanks, LGTM.

Pushed to emacs-26.

[1: c194fb61c6]: 2017-10-07 19:19:05 -0400
  Make python prettify symbols into a defvar (Bug#28713)
  http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=c194fb61c638490e3510864fe2750814af8c3719