unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#32817: 27.0.50; Dotted pair syntax for directory-local variables
@ 2018-09-23 23:14 Juri Linkov
  2018-09-25 12:10 ` Phil Sainty
  0 siblings, 1 reply; 7+ messages in thread
From: Juri Linkov @ 2018-09-23 23:14 UTC (permalink / raw)
  To: 32817

As indicated in https://lists.gnu.org/archive/html/emacs-devel/2018-09/msg00817.html
the current syntax is confusing.

This patch fixes add-dir-local-variable to output syntax corresponding
to examples in (info "(emacs) Directory Variables"):

diff --git a/lisp/files-x.el b/lisp/files-x.el
index 92532e85f4..8603b6299c 100644
--- a/lisp/files-x.el
+++ b/lisp/files-x.el
@@ -492,15 +492,31 @@ modify-dir-local-variable
       ;; Insert modified alist of directory-local variables.
       (insert ";;; Directory Local Variables\n")
       (insert ";;; For more information see (info \"(emacs) Directory Variables\")\n\n")
-      (pp (sort variables
+      (princ (add-dir-local-variables-to-string
+              (sort variables
 		    (lambda (a b)
 		      (cond
 		       ((null (car a)) t)
 		       ((null (car b)) nil)
 		       ((and (symbolp (car a)) (stringp (car b))) t)
 		       ((and (symbolp (car b)) (stringp (car a))) nil)
-		   (t (string< (car a) (car b))))))
-	  (current-buffer)))))
+		       (t (string< (car a) (car b)))))))
+             (current-buffer))
+      (goto-char (point-min))
+      (indent-sexp))))
+
+(defun add-dir-local-variables-to-string (variables)
+  (format "(%s)" (mapconcat
+                  (lambda (mode-variable)
+                    (format "(%S . %s)"
+                            (car mode-variable)
+                            (format "(%s)" (mapconcat
+                                            (lambda (variable-value)
+                                              (format "(%s . %S)"
+                                                      (car variable-value)
+                                                      (cdr variable-value)))
+                                            (cdr mode-variable) "\n"))))
+                  variables "\n")))
 
 ;;;###autoload
 (defun add-dir-local-variable (mode variable value)





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

* bug#32817: 27.0.50; Dotted pair syntax for directory-local variables
  2018-09-23 23:14 bug#32817: 27.0.50; Dotted pair syntax for directory-local variables Juri Linkov
@ 2018-09-25 12:10 ` Phil Sainty
  2018-09-25 19:41   ` Juri Linkov
  0 siblings, 1 reply; 7+ messages in thread
From: Phil Sainty @ 2018-09-25 12:10 UTC (permalink / raw)
  To: Juri Linkov, 32817

Hi Juri,

On 24/09/18 11:14, Juri Linkov wrote:
> As indicated in https://lists.gnu.org/archive/html/emacs-devel/2018-09/msg00817.html
> the current syntax is confusing.
> 
> This patch fixes add-dir-local-variable to output syntax corresponding
> to examples in (info "(emacs) Directory Variables"):

Thanks for implementing this.


> +(defun add-dir-local-variables-to-string (variables)

`add-dir-local-variables-to-string' is quite a confusing name.
It makes it sound like the dir-local variables will be added to
a string (which doesn't make a lot of sense), when it's actually
formatting all of the dir-locals *as* a string.

This is on account of the "add-" prefix, which I think is unnecessary
-- the functionality isn't really tied to `add-dir-local-variable';
it would work regardless of where its argument came from.

`dir-locals-to-string' seems a better name to me, and is consistent
with other dir-locals-* functions.

I think it should also have a docstring.


> +  (format "(%s)" (mapconcat
> +                  (lambda (mode-variable)

"mode-variables" (plural), I think.

> +                    (format "(%S . %s)"
> +                            (car mode-variable)
> +                            (format "(%s)" (mapconcat
> +                                            (lambda (variable-value)
> +                                              (format "(%s . %S)"
> +                                                      (car variable-value)

Why is the variable symbol "%s" when the mode symbol was "%S" ?

> +                                                      (cdr variable-value)))
> +                                            (cdr mode-variable) "\n"))))
> +                  variables "\n")))


regards,

-Phil





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

* bug#32817: 27.0.50; Dotted pair syntax for directory-local variables
  2018-09-25 12:10 ` Phil Sainty
@ 2018-09-25 19:41   ` Juri Linkov
  2018-09-26 15:01     ` Phil Sainty
  0 siblings, 1 reply; 7+ messages in thread
From: Juri Linkov @ 2018-09-25 19:41 UTC (permalink / raw)
  To: Phil Sainty; +Cc: 32817

>> +(defun add-dir-local-variables-to-string (variables)
>
> `add-dir-local-variables-to-string' is quite a confusing name.
> It makes it sound like the dir-local variables will be added to
> a string (which doesn't make a lot of sense), when it's actually
> formatting all of the dir-locals *as* a string.
>
> This is on account of the "add-" prefix, which I think is unnecessary
> -- the functionality isn't really tied to `add-dir-local-variable';
> it would work regardless of where its argument came from.
>
> `dir-locals-to-string' seems a better name to me, and is consistent
> with other dir-locals-* functions.

My intention was to use this prefix to add the new function
to the add-dir-local-variable* namespace.  But I agree that
dir-locals-* is more suitable, so I renamed the function.

>> +  (format "(%s)" (mapconcat
>> +                  (lambda (mode-variable)
>
> "mode-variables" (plural), I think.

Fixed as well.

>> +                    (format "(%S . %s)"
>> +                            (car mode-variable)
>> +                            (format "(%s)" (mapconcat
>> +                                            (lambda (variable-value)
>> +                                              (format "(%s . %S)"
>> +                                                      (car variable-value)
>
> Why is the variable symbol "%s" when the mode symbol was "%S" ?

The mode symbol is "%S" to support string values of a subdirectory like
"src/imported" in the example in (info "(emacs) Directory Variables")
But admittedly add-dir-local-variable doesn't support adding 3 levels
subdirectory-mode-variables anyway, it could be used only to create
an initial subdirectory-variable-value to allow the user adding mode
manually.  But for any case I changed the variable symbol "%s" to "%S".





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

* bug#32817: 27.0.50; Dotted pair syntax for directory-local variables
  2018-09-25 19:41   ` Juri Linkov
@ 2018-09-26 15:01     ` Phil Sainty
  2018-09-26 15:50       ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Phil Sainty @ 2018-09-26 15:01 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 32817

Do we want a NEWS entry for this?

It's a user-visible change, even if the *effective* behaviour is
identical.

I'm mostly thinking it's worth flagging in NEWS for the sake of
users who have previously rejected the `add-dir-local-variable'
command on the basis that it wrecks their .dir-locals.el
formatting.


-Phil





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

* bug#32817: 27.0.50; Dotted pair syntax for directory-local variables
  2018-09-26 15:01     ` Phil Sainty
@ 2018-09-26 15:50       ` Eli Zaretskii
  2018-09-27  0:09         ` Juri Linkov
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2018-09-26 15:50 UTC (permalink / raw)
  To: Phil Sainty; +Cc: 32817, juri

> From: Phil Sainty <psainty@orcon.net.nz>
> Date: Thu, 27 Sep 2018 03:01:41 +1200
> Cc: 32817@debbugs.gnu.org
> 
> Do we want a NEWS entry for this?

Probably.





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

* bug#32817: 27.0.50; Dotted pair syntax for directory-local variables
  2018-09-26 15:50       ` Eli Zaretskii
@ 2018-09-27  0:09         ` Juri Linkov
  2018-09-27  6:47           ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Juri Linkov @ 2018-09-27  0:09 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Phil Sainty, 32817

>> Do we want a NEWS entry for this?
>
> Probably.

I added a NEWS entry like Phil suggested.





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

* bug#32817: 27.0.50; Dotted pair syntax for directory-local variables
  2018-09-27  0:09         ` Juri Linkov
@ 2018-09-27  6:47           ` Eli Zaretskii
  0 siblings, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2018-09-27  6:47 UTC (permalink / raw)
  To: Juri Linkov; +Cc: psainty, 32817

> From: Juri Linkov <juri@linkov.net>
> Cc: Phil Sainty <psainty@orcon.net.nz>,  32817@debbugs.gnu.org
> Date: Thu, 27 Sep 2018 03:09:25 +0300
> 
> >> Do we want a NEWS entry for this?
> >
> > Probably.
> 
> I added a NEWS entry like Phil suggested.

Thanks.





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

end of thread, other threads:[~2018-09-27  6:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-23 23:14 bug#32817: 27.0.50; Dotted pair syntax for directory-local variables Juri Linkov
2018-09-25 12:10 ` Phil Sainty
2018-09-25 19:41   ` Juri Linkov
2018-09-26 15:01     ` Phil Sainty
2018-09-26 15:50       ` Eli Zaretskii
2018-09-27  0:09         ` Juri Linkov
2018-09-27  6:47           ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).