unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Policy for declaring safe local variable values
@ 2021-10-08  9:11 Titus von der Malsburg
  2021-10-08  9:55 ` Joost Kremers
  2021-10-08 10:09 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 5+ messages in thread
From: Titus von der Malsburg @ 2021-10-08  9:11 UTC (permalink / raw)
  To: emacs-devel


I have a configuration variable (in package bibtex-completion) that can usefully be set to a local value via a ‘Local Variable‘ comment in the file.  E.g:

# Local Variables:
# bibtex-completion-bibliography: "/path/to/bibliography.bib"
# End:

However, it’s annoying that users have to confirm that the local value for this variable is safe every time they open a file with a different value for that variable.  Question: Can I declare the variable safe for local values in my package, e.g.

(put 'bibtex-completion-bibliography 'safe-local-variable (lambda (_) t))

or would that violate Emacs conventions?

  Titus



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

* Re: Policy for declaring safe local variable values
  2021-10-08  9:11 Policy for declaring safe local variable values Titus von der Malsburg
@ 2021-10-08  9:55 ` Joost Kremers
  2021-10-08 14:51   ` Titus von der Malsburg
  2021-10-08 10:09 ` Lars Ingebrigtsen
  1 sibling, 1 reply; 5+ messages in thread
From: Joost Kremers @ 2021-10-08  9:55 UTC (permalink / raw)
  To: Titus von der Malsburg; +Cc: emacs-devel


On Fri, Oct 08 2021, Titus von der Malsburg wrote:
> I have a configuration variable (in package bibtex-completion) that can usefully be set to a local value via a ‘Local Variable‘ comment in the file.  E.g:
>
> # Local Variables:
> # bibtex-completion-bibliography: "/path/to/bibliography.bib"
> # End:
>
> However, it’s annoying that users have to confirm that the local value for this
> variable is safe every time they open a file with a different value for that
> variable.

Fun fact: answering your e-mail in Emacs I got the same question. :-)

> Question: Can I declare the variable safe for local values in my
> package, e.g.
>
> (put 'bibtex-completion-bibliography 'safe-local-variable (lambda (_) t))
>
> or would that violate Emacs conventions?

`defcustom` even has a keyword for it (`:safe`), so I don't think it violates
any conventions.

TBH, I use this method in some of my packages and it never occurred to me it
might be against conventions...

-- 
Joost Kremers
Life has its moments



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

* Re: Policy for declaring safe local variable values
  2021-10-08  9:11 Policy for declaring safe local variable values Titus von der Malsburg
  2021-10-08  9:55 ` Joost Kremers
@ 2021-10-08 10:09 ` Lars Ingebrigtsen
  1 sibling, 0 replies; 5+ messages in thread
From: Lars Ingebrigtsen @ 2021-10-08 10:09 UTC (permalink / raw)
  To: Titus von der Malsburg; +Cc: emacs-devel

Titus von der Malsburg <malsburg@posteo.de> writes:

> (put 'bibtex-completion-bibliography 'safe-local-variable (lambda (_) t))
>
> or would that violate Emacs conventions?

I think that's fine, but use `stringp' instead.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



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

* Re: Policy for declaring safe local variable values
  2021-10-08  9:55 ` Joost Kremers
@ 2021-10-08 14:51   ` Titus von der Malsburg
  2021-10-08 15:06     ` Joost Kremers
  0 siblings, 1 reply; 5+ messages in thread
From: Titus von der Malsburg @ 2021-10-08 14:51 UTC (permalink / raw)
  To: Joost Kremers; +Cc: emacs-devel


On 2021-10-08 Fri 11:55, Joost Kremers <joostkremers@fastmail.fm> wrote:
> On Fri, Oct 08 2021, Titus von der Malsburg wrote:
>> I have a configuration variable (in package bibtex-completion) that can usefully be set to a local value via a ‘Local Variable‘ comment in the file.  E.g:
>>
>> # Local Variables:
>> # bibtex-completion-bibliography: "/path/to/bibliography.bib"
>> # End:
>>
>> However, it’s annoying that users have to confirm that the local value for this
>> variable is safe every time they open a file with a different value for that
>> variable.
>
> Fun fact: answering your e-mail in Emacs I got the same question. :-)

This is scary and perhaps even a bug?  It seems wrong that text in e-mails should be allowed to set local variables.

>> Question: Can I declare the variable safe for local values in my
>> package, e.g.
>>
>> (put 'bibtex-completion-bibliography 'safe-local-variable (lambda (_) t))
>>
>> or would that violate Emacs conventions?
>
> `defcustom` even has a keyword for it (`:safe`), so I don't think it violates
> any conventions.
>
> TBH, I use this method in some of my packages and it never occurred to me it
> might be against conventions...

Thank you.  I wasn’t aware of the ‘:safe‘ keyword.

  Titus




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

* Re: Policy for declaring safe local variable values
  2021-10-08 14:51   ` Titus von der Malsburg
@ 2021-10-08 15:06     ` Joost Kremers
  0 siblings, 0 replies; 5+ messages in thread
From: Joost Kremers @ 2021-10-08 15:06 UTC (permalink / raw)
  To: Titus von der Malsburg; +Cc: emacs-devel


On Fri, Oct 08 2021, Titus von der Malsburg wrote:
>> Fun fact: answering your e-mail in Emacs I got the same question. :-)
>
> This is scary and perhaps even a bug? It seems wrong that text in e-mails should
> be allowed to set local variables.

You might be right.

>> `defcustom` even has a keyword for it (`:safe`), so I don't think it violates
>> any conventions.
>>
>> TBH, I use this method in some of my packages and it never occurred to me it
>> might be against conventions...
>
> Thank you.  I wasn’t aware of the ‘:safe‘ keyword.

Note that the Elisp manual says that using `:safe` has a disadvantage and that
an autoload cookie may be a better solution (scroll down a little or search for
"autoload"):

(info "(elisp) File Local Variables")



-- 
Joost Kremers
Life has its moments



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

end of thread, other threads:[~2021-10-08 15:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-08  9:11 Policy for declaring safe local variable values Titus von der Malsburg
2021-10-08  9:55 ` Joost Kremers
2021-10-08 14:51   ` Titus von der Malsburg
2021-10-08 15:06     ` Joost Kremers
2021-10-08 10:09 ` Lars Ingebrigtsen

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).