doomemacs / doomemacs

An Emacs framework for the stubborn martian hacker
MIT License
19.13k stars 3.03k forks source link

fails to mark local variables as safe and instead prompts every time #7267

Open rgkirch opened 1 year ago

rgkirch commented 1 year ago

I confirm that...

Current Behavior and Steps to Reproduce

I renamed my ~/.doom.d/config.el to config.el.bak I deleted my custom.el file I have a ~/org/.dir-locals.el that looks like this


((org-mode . ((eval . (add-hook! org-insert-heading :local
                        (defun after-org-insert-heading-add-property-created ()
                          (org-set-property "CREATED" (format-time-string "[%Y-%m-%d %T]"))))))))

I open an org file ~/org/scratch.org and Emacs prompts me to apply the local variables and answering ! will create a custom.el

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(safe-local-variable-values
   '((eval add-hook! org-insert-heading :local
      (defun after-org-insert-heading-add-property-created nil
       (org-set-property "CREATED"
                         (format-time-string "[%Y-%m-%d %T]")))))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

I quit and restart emacs and reopen the org file I get the same prompt to apply local variables

The local variables list in c:/Users/me/richie/org/
contains values that may not be safe (*).

Do you want to apply it?  You can type
y  -- to apply the local variables list.
n  -- to ignore the local variables list.
!  -- to apply the local variables list, and permanently mark these
      values (*) as safe (in the future, they will be set automatically.)
i  -- to ignore the local variables list, and permanently mark these
      values (*) as ignored

  * eval : (add-hook! org-insert-heading :local (defun after-org-insert-heading-add-property-created nil (org-set-property "CREATED" (format-time-string "[%Y-%m-%d %T]"))))

After toggle-debug-on-quit and C-g at the prompt I get this backtrack

Debugger entered--Lisp error: (minibuffer-quit)
  signal(minibuffer-quit nil)
  #f(compiled-function () #<bytecode 0x1f4108e26fc3>)()
  read-from-minibuffer("Please type y, n, ! or i, or C-v/M-v to scroll: " nil (keymap (remap keymap (self-insert-command . read-char-from-minibuffer-insert-other)) (32 . read-char-from-minibuffer-insert-char) (110 . read-char-from-minibuffer-insert-char) (121 . read-char-from-minibuffer-insert-char) (105 . read-char-from-minibuffer-insert-char) (33 . read-char-from-minibuffer-insert-char) keymap (remap keymap (scroll-other-window-down . minibuffer-scroll-other-window-down) (scroll-other-window . minibuffer-scroll-other-window) (scroll-down-command . minibuffer-scroll-down-command) (scroll-up-command . minibuffer-scroll-up-command) (recenter-top-bottom . minibuffer-recenter-top-bottom) (exit-minibuffer . read-char-from-minibuffer-insert-other) (self-insert-command . read-char-from-minibuffer-insert-char)) keymap (19 . counsel-minibuffer-history) (menu-bar keymap (minibuf "Minibuf" keymap (previous menu-item "Previous History Item" previous-history-element :help "Put previous minibuffer history element in the min...") (next menu-item "Next History Item" next-history-element :help "Put next minibuffer history element in the minibuf...") (isearch-backward menu-item "Isearch History Backward" isearch-backward :help "Incrementally search minibuffer history backward") (isearch-forward menu-item "Isearch History Forward" isearch-forward :help "Incrementally search minibuffer history forward") (return menu-item "Enter" exit-minibuffer :key-sequence "\15" :help "Terminate input and exit minibuffer") (quit menu-item "Quit" abort-recursive-edit :help "Abort input and exit minibuffer") "Minibuf")) (13 . exit-minibuffer) (10 . exit-minibuffer) (7 . minibuffer-keyboard-quit) (C-tab . file-cache-minibuffer-complete) (9 . self-insert-command) (XF86Back . previous-history-element) (up . previous-line-or-history-element) (prior . previous-history-element) (XF86Forward . next-history-element) (down . next-line-or-history-element) (next . next-history-element) (27 keymap (60 . minibuffer-beginning-of-buffer) (114 . previous-matching-history-element) (115 . next-matching-history-element) (112 . previous-history-element) (110 . next-history-element))) nil empty-history)
  read-char-from-minibuffer("Please type y, n, ! or i, or C-v/M-v to scroll: " (33 105 121 110 32))
  read-char-choice("Please type y, n, ! or i, or C-v/M-v to scroll: " (33 105 121 110 32))
  hack-local-variables-confirm(((eval add-hook! org-insert-heading :local (defun after-org-insert-heading-add-property-created nil (org-set-property "CREATED" (format-time-string "[%Y-%m-%d %T]"))))) ((eval add-hook! org-insert-heading :local (defun after-org-insert-heading-add-property-created nil (org-set-property "CREATED" (format-time-string "[%Y-%m-%d %T]"))))) nil "c:/Users/me/richie/org/")
  hack-local-variables-filter(((eval add-hook! org-insert-heading :local (defun after-org-insert-heading-add-property-created nil (org-set-property "CREATED" (format-time-string "[%Y-%m-%d %T]"))))) "c:/Users/me/richie/org/")
  hack-dir-local-variables()
  #f(compiled-function (&optional handle-mode inhibit-locals) "Parse and put into effect this buffer's local variables spec.\nFor buffers visiting files, also puts into effect directory-local\nvariables.\n\nUses `hack-local-variables-apply' to apply the variables.\n\nSee `hack-local-variables--find-variables' for the meaning of\nHANDLE-MODE.\n\nIf `enable-local-variables' or `local-enable-local-variables' is\nnil, or INHIBIT-LOCALS is non-nil, this function disregards all\nnormal local variables.  If `inhibit-local-variables-regexps'\napplies to the file in question, the file is not scanned for\nlocal variables, but directory-local variables may still be\napplied.\n\nVariables present in `permanently-enabled-local-variables' will\nstill be evaluated, even if local variables are otherwise\ninhibited." #<bytecode -0x16b2471bfff5ac05>)(no-mode)
  so-long--hack-local-variables(#f(compiled-function (&optional handle-mode inhibit-locals) "Parse and put into effect this buffer's local variables spec.\nFor buffers visiting files, also puts into effect directory-local\nvariables.\n\nUses `hack-local-variables-apply' to apply the variables.\n\nSee `hack-local-variables--find-variables' for the meaning of\nHANDLE-MODE.\n\nIf `enable-local-variables' or `local-enable-local-variables' is\nnil, or INHIBIT-LOCALS is non-nil, this function disregards all\nnormal local variables.  If `inhibit-local-variables-regexps'\napplies to the file in question, the file is not scanned for\nlocal variables, but directory-local variables may still be\napplied.\n\nVariables present in `permanently-enabled-local-variables' will\nstill be evaluated, even if local variables are otherwise\ninhibited." #<bytecode -0x16b2471bfff5ac05>) no-mode)
  apply(so-long--hack-local-variables #f(compiled-function (&optional handle-mode inhibit-locals) "Parse and put into effect this buffer's local variables spec.\nFor buffers visiting files, also puts into effect directory-local\nvariables.\n\nUses `hack-local-variables-apply' to apply the variables.\n\nSee `hack-local-variables--find-variables' for the meaning of\nHANDLE-MODE.\n\nIf `enable-local-variables' or `local-enable-local-variables' is\nnil, or INHIBIT-LOCALS is non-nil, this function disregards all\nnormal local variables.  If `inhibit-local-variables-regexps'\napplies to the file in question, the file is not scanned for\nlocal variables, but directory-local variables may still be\napplied.\n\nVariables present in `permanently-enabled-local-variables' will\nstill be evaluated, even if local variables are otherwise\ninhibited." #<bytecode -0x16b2471bfff5ac05>) no-mode)
  hack-local-variables(no-mode)
  run-mode-hooks(org-mode-hook)
  org-mode()
  set-auto-mode-0(org-mode nil)
  set-auto-mode--apply-alist((("Procfile\\'" . yaml-mode) ("/bspwmrc\\'" . sh-mode) ("\\.\\(?:zunit\\|env\\)\\'" . sh-mode) ("\\.bats\\'" . sh-mode) ("/README\\(?:\\.md\\)?\\'" . gfm-mode) ("\\.g\\(?:radle\\|roovy\\)$" . groovy-mode) ("\\.js\\(?:on\\|[hl]int\\(?:rc\\)?\\)\\'" . json-mode) ("\\.Cask\\'" . emacs-lisp-mode) ("\\.pdf\\'" . pdf-view-mode) ("\\.\\(e?ya?\\|ra\\)ml\\'" . yaml-mode) ("\\.gp\\'" . gnuplot-mode) ("\\.gnuplot\\'" . gnuplot-mode) ("\\.\\(?:md\\|markdown\\|mkd\\|mdown\\|mkdn\\|mdwn\\)\\'" . markdown-mode) ("/Jenkinsfile\\'" . groovy-mode) ("\\.g\\(?:ant\\|roovy\\|radle\\)\\'" . groovy-mode) ("\\(?:\\(?:\\.\\(?:b\\(?:\\(?:abel\\|ower\\)rc\\)\\|json\\(?:l..." . json-mode) ("\\(?:build\\|profile\\)\\.boot\\'" . clojure-mode) ("\\.cljs\\'" . clojurescript-mode) ("\\.cljc\\'" . clojurec-mode) ("\\.\\(clj\\|cljd\\|dtm\\|edn\\)\\'" . clojure-mode) ("/git-rebase-todo\\'" . git-rebase-mode) ("/git/ignore\\'" . gitignore-mode) ("/info/exclude\\'" . gitignore-mode) ("/\\.gitignore\\'" . gitignore-mode) ("/etc/gitconfig\\'" . gitconfig-mode) ("/\\.gitmodules\\'" . gitconfig-mode) ("/git/config\\'" . gitconfig-mode) ("/modules/.*/config\\'" . gitconfig-mode) ("/\\.git/config\\'" . gitconfig-mode) ("/\\.gitconfig\\'" . gitconfig-mode) ("/git/attributes\\'" . gitattributes-mode) ("/info/attributes\\'" . gitattributes-mode) ("/\\.gitattributes\\'" . gitattributes-mode) ("\\.janet\\'" . janet-mode) ("\\.gpg\\(~\\|\\.~[0-9]+~\\)?\\'" nil epa-file) ("\\.elc\\'" . elisp-byte-code-mode) ("\\.zst\\'" nil jka-compr) ("\\.dz\\'" nil jka-compr) ("\\.xz\\'" nil jka-compr) ("\\.lzma\\'" nil jka-compr) ("\\.lz\\'" nil jka-compr) ("\\.g?z\\'" nil jka-compr) ("\\.bz2\\'" nil jka-compr) ("\\.Z\\'" nil jka-compr) ("\\.vr[hi]?\\'" . vera-mode) ("\\(?:\\.\\(?:rbw?\\|ru\\|rake\\|thor\\|jbuilder\\|rabl\\|ge..." . ruby-mode) ("\\.re?st\\'" . rst-mode) ("\\.py[iw]?\\'" . python-mode) ("\\.m\\'" . octave-maybe-mode) ("\\.less\\'" . less-css-mode) ...) nil nil)
  #f(compiled-function (&optional keep-mode-if-same) "Select major mode appropriate for current buffer.\n\nTo find the right major mode, this function checks for a -*- mode tag\nchecks for a `mode:' entry in the Local Variables section of the file,\nchecks if there an `auto-mode-alist' entry in `.dir-locals.el',\nchecks if it uses an interpreter listed in `interpreter-mode-alist',\nmatches the buffer beginning against `magic-mode-alist',\ncompares the file name against the entries in `auto-mode-alist',\nthen matches the buffer beginning against `magic-fallback-mode-alist'.\n\nIf `enable-local-variables' is nil, or if the file name matches\n`inhibit-local-variables-regexps', this function does not check\nfor any mode: tag anywhere in the file.  If `local-enable-local-variables'\nis nil, then the only mode: tag that can be relevant is a -*- one.\n\nIf the optional argument KEEP-MODE-IF-SAME is non-nil, then we\nset the major mode only if that would change it.  In other words\nwe don't actually set it to the same mode the buffer already has." #<bytecode -0x1220ab5af11a525c>)()
  so-long--set-auto-mode(#f(compiled-function (&optional keep-mode-if-same) "Select major mode appropriate for current buffer.\n\nTo find the right major mode, this function checks for a -*- mode tag\nchecks for a `mode:' entry in the Local Variables section of the file,\nchecks if there an `auto-mode-alist' entry in `.dir-locals.el',\nchecks if it uses an interpreter listed in `interpreter-mode-alist',\nmatches the buffer beginning against `magic-mode-alist',\ncompares the file name against the entries in `auto-mode-alist',\nthen matches the buffer beginning against `magic-fallback-mode-alist'.\n\nIf `enable-local-variables' is nil, or if the file name matches\n`inhibit-local-variables-regexps', this function does not check\nfor any mode: tag anywhere in the file.  If `local-enable-local-variables'\nis nil, then the only mode: tag that can be relevant is a -*- one.\n\nIf the optional argument KEEP-MODE-IF-SAME is non-nil, then we\nset the major mode only if that would change it.  In other words\nwe don't actually set it to the same mode the buffer already has." #<bytecode -0x1220ab5af11a525c>))
  apply(so-long--set-auto-mode #f(compiled-function (&optional keep-mode-if-same) "Select major mode appropriate for current buffer.\n\nTo find the right major mode, this function checks for a -*- mode tag\nchecks for a `mode:' entry in the Local Variables section of the file,\nchecks if there an `auto-mode-alist' entry in `.dir-locals.el',\nchecks if it uses an interpreter listed in `interpreter-mode-alist',\nmatches the buffer beginning against `magic-mode-alist',\ncompares the file name against the entries in `auto-mode-alist',\nthen matches the buffer beginning against `magic-fallback-mode-alist'.\n\nIf `enable-local-variables' is nil, or if the file name matches\n`inhibit-local-variables-regexps', this function does not check\nfor any mode: tag anywhere in the file.  If `local-enable-local-variables'\nis nil, then the only mode: tag that can be relevant is a -*- one.\n\nIf the optional argument KEEP-MODE-IF-SAME is non-nil, then we\nset the major mode only if that would change it.  In other words\nwe don't actually set it to the same mode the buffer already has." #<bytecode -0x1220ab5af11a525c>) nil)
  #f(advice-wrapper :around #f(compiled-function (&optional keep-mode-if-same) "Select major mode appropriate for current buffer.\n\nTo find the right major mode, this function checks for a -*- mode tag\nchecks for a `mode:' entry in the Local Variables section of the file,\nchecks if there an `auto-mode-alist' entry in `.dir-locals.el',\nchecks if it uses an interpreter listed in `interpreter-mode-alist',\nmatches the buffer beginning against `magic-mode-alist',\ncompares the file name against the entries in `auto-mode-alist',\nthen matches the buffer beginning against `magic-fallback-mode-alist'.\n\nIf `enable-local-variables' is nil, or if the file name matches\n`inhibit-local-variables-regexps', this function does not check\nfor any mode: tag anywhere in the file.  If `local-enable-local-variables'\nis nil, then the only mode: tag that can be relevant is a -*- one.\n\nIf the optional argument KEEP-MODE-IF-SAME is non-nil, then we\nset the major mode only if that would change it.  In other words\nwe don't actually set it to the same mode the buffer already has." #<bytecode -0x1220ab5af11a525c>) so-long--set-auto-mode)()
  apply(#f(advice-wrapper :around #f(compiled-function (&optional keep-mode-if-same) "Select major mode appropriate for current buffer.\n\nTo find the right major mode, this function checks for a -*- mode tag\nchecks for a `mode:' entry in the Local Variables section of the file,\nchecks if there an `auto-mode-alist' entry in `.dir-locals.el',\nchecks if it uses an interpreter listed in `interpreter-mode-alist',\nmatches the buffer beginning against `magic-mode-alist',\ncompares the file name against the entries in `auto-mode-alist',\nthen matches the buffer beginning against `magic-fallback-mode-alist'.\n\nIf `enable-local-variables' is nil, or if the file name matches\n`inhibit-local-variables-regexps', this function does not check\nfor any mode: tag anywhere in the file.  If `local-enable-local-variables'\nis nil, then the only mode: tag that can be relevant is a -*- one.\n\nIf the optional argument KEEP-MODE-IF-SAME is non-nil, then we\nset the major mode only if that would change it.  In other words\nwe don't actually set it to the same mode the buffer already has." #<bytecode -0x1220ab5af11a525c>) so-long--set-auto-mode) nil)
  set-auto-mode()
  normal-mode()
  funcall-interactively(normal-mode)
  call-interactively(normal-mode record nil)
  command-execute(normal-mode record)
  counsel-M-x-action("normal-mode")
  ivy-call()
  ivy-read("M-x " ("toggle-debug-on-quit" "global-undo-tree-mode" "pdf-tools-install" "browse-url-of-dired-file" "package-install" "global-company-mode" "json-pretty-print" "normal-mode" "revert-buffer" "ediff-buffers" "magit-clone" "clojure-mode" "fundamental-mode" "recover-this-file" "sort-lines" "emacs-lisp-mode" "eww" "re-builder" "next-window-any-frame" "erc" "eshell" "server-force-delete" "lsp-treemacs-symbols" "next-error" "elisp-def-mode" "regexp-builder" "ert" "lsp" "netstat" "elisp-def" "lispy-mode" "magit-init" "scheme-mode" "upcase-word" "customize-face" "undo-tree-mode" "flycheck-next-error" "query-replace-regexp" "customize-apropos-faces" "flycheck-previous-error" "doom/toggle-line-numbers" "projectile-remove-known-project" "cd" "5x5" "amx" "arp" "dbx" "dig" "ftp" "gdb" ...) :predicate counsel--M-x-externs-predicate :require-match t :history counsel-M-x-history :action counsel-M-x-action :keymap (keymap (67108908 . counsel--info-lookup-symbol) (67108910 . counsel-find-symbol)) :initial-input nil :caller counsel-M-x)
  counsel-M-x()
  funcall-interactively(counsel-M-x)
  call-interactively(counsel-M-x nil nil)
  command-execute(counsel-M-x)

Expected behavior

Emacs should not prompt me every time. Respect custom.el.

System Information

https://gist.github.com/rgkirch/cd4ae099cc2679001248374e893d1525

hpfr commented 11 months ago

Not a Doom bug, you need to use safe-local-eval-forms: Safe File Variables (GNU Emacs Manual)

rgkirch commented 11 months ago

Thanks for the link. I need to see if that solves my problem. It probably does…