Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom variables marked as :safe are considered unsafe when loading file local variables on startup #1302

Closed
sfllaw opened this issue Mar 28, 2024 · 1 comment · Fixed by #1304

Comments

@sfllaw
Copy link
Contributor

sfllaw commented Mar 28, 2024

I have an HTML file with the following file local variables:

<!-- Local Variables:
     web-mode-code-indent-offset: 1
     End: -->

If web-mode is already required, visiting this file is just fine. However, if web-mode is auto-loaded, then Emacs thinks this setting is unsafe, despite it being marked as :safe #'integerp:

web-mode/web-mode.el

Lines 105 to 110 in a9d2184

(defcustom web-mode-code-indent-offset
(if (and (boundp 'standard-indent) standard-indent) standard-indent 2)
"Code (javascript, php, etc.) indentation level."
:type 'integer
:safe #'integerp
:group 'web-mode)

According to Emacs Lisp: File Local Variables:

However, a safety predicate defined using :safe will only be known once the package that contains the defcustom is loaded, which is often too late. As an alternative, you can use the autoload cookie (see Autoload) to assign the option its safety predicate, like this:

;;;###autoload (put 'var 'safe-local-variable 'pred)

So it seems to me that the definition for web-mode-code-indent-offset should be revised to be:

(defcustom web-mode-code-indent-offset
  (if (and (boundp 'standard-indent) standard-indent) standard-indent 2)
  "Code (javascript, php, etc.) indentation level."
  :type 'integer
  :group 'web-mode)
;;;###autoload
(put 'web-mode-code-indent-offset 'safe-local-variable #'integerp)

If you would like, I can prepare a patch. Please let me know how you’d like me to contribute.

@sfllaw
Copy link
Contributor Author

sfllaw commented Apr 13, 2024

Thanks, @fxbois!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant