This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-06-01
Channels
- # announcements (20)
- # babashka (3)
- # beginners (30)
- # calva (28)
- # cider (3)
- # circleci (4)
- # clerk (27)
- # clj-kondo (72)
- # cljdoc (15)
- # cljs-dev (1)
- # clojure (85)
- # clojure-europe (37)
- # clojure-nl (1)
- # clojure-norway (13)
- # clojure-spec (7)
- # clojurescript (19)
- # clr (1)
- # conjure (11)
- # datahike (2)
- # datomic (11)
- # emacs (26)
- # events (4)
- # hoplon (35)
- # hyperfiddle (41)
- # jobs (7)
- # lsp (10)
- # nrepl (3)
- # off-topic (57)
- # portal (47)
- # practicalli (1)
- # rdf (3)
- # reitit (21)
- # releases (1)
- # testing (6)
- # tools-build (16)
- # wasm (1)
- # xtdb (16)
Hey. Emacs always asks me if it's safe to apply local variables whenever I open a file and I can't figure out why. This isn't even about clojure... 🧵
I have a .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]"))))))))
and when I open an org file I get this prompt
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]"))))
If I respond y
then it's fine but I don't want it prompting me every time. I toggled toggle-debug-on-quit
and git C-g
at that prompt to generate the backtrace just to provide some context.
If I respond !
to the prompt then I'm prompted to enter a "File to load from". Using toggle-debug-on-quit
I gathered this backtrace.
Maybe that's tmi. I'm just saying that at this screen if I hit !
then I get this screen which confuses me.
!
should save variables defined in the .dir-locals.el
file to a (custom-set-variables )
list, usually at the end of the init.el
file in Emacs. Once they are there, Emacs wont ask about them again (unless that section or file is deleted).
Maybe doom puts them in a different file...
In my Doom config, they are saved to a custom.el
file. I am fairly certain Doom created this custom.el file when I first ran Emacs with the Doom configuration.
Hmm. Something in the backtrace stands out to me. undo-tree-load-history-from-hook()
> undo-tree-load-history(nil noerror)
> (read-file-name "File to load from: ")
.doom.d/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]"))))
(cider-jack-in-nrepl-middlewares "cider.nrepl/cider-middleware" "shadow.cljs.devtools.server.nrepl/middleware"))))
(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.
)
If you havent used the Emacs customize
command to make any changes to Emacs, it should be safe to delete custom.el
and start Emacs again, which should recreate it. Move the file out of the way rather than delete if not sure...
This should help narrow down the problem at least, if it doesnt fix it.
This printed in the *Messages*
buffer.
Buffer has been modified since undo-tree history was saved to
"c:/Users/me/.emacs.d/.local/cache/undo-tree-hist/.c35f14d95f3abcae1b592dbd6c6c76ec48930d41.~undo-tree~.zst"; could not load undo-tree history
Saving file c:/Users/me/.doom.d/yogadows-custom.el...
Wrote c:/Users/me/.emacs.d/.local/cache/undo-tree-hist/.c35f14d95f3abcae1b592dbd6c6c76ec48930d41.~undo-tree~.zst
Wrote c:/Users/me/.doom.d/yogadows-custom.el
Wrote c:/Users/me/.emacs.d/.local/cache/undo-tree-hist/.c35f14d95f3abcae1b592dbd6c6c76ec48930d41.~undo-tree~.zst
Wrote c:/Users/me/.emacs.d/.local/cache/undo-tree-hist/.3e53983e60e4166eed74b338700dcd21f14855c9.~undo-tree~.zst
It re-created my custom.el file
(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]"))))
(cider-jack-in-nrepl-middlewares "cider.nrepl/cider-middleware" "shadow.cljs.devtools.server.nrepl/middleware"))))
(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.
)
So I deleted c:/Users/me/.emacs.d/.local/cache/undo-tree-hist/.c35f14d95f3abcae1b592dbd6c6c76ec48930d41.~undo-tree~.zst
Then it "worked" once where I answered !
to the prompt and did not get the "File to load from" prompt. After restarting emacs and trying again, I do get that "File to load from" prompt and I see the same messages from undo-tree...
I tried disabling undo-tree via global-undo-tree-mode
right after starting emacs and now I don't get the "File to load from" prompt but I am prompted about the local variables that may not be safe and I have to respond !
.
Is there something funny about my .dir-locals.el
including an inline defun
? I don't know where I got that but it does work. Maybe it's not compatible with safe-local-variable-values
somehow...
Maybe its the defun code. I've only used declarative style code in a .dir-locals.el file, e.g. setting variables to values.
I documented a few examples of adding code to a .dir-locals.el https://practical.li/spacemacs/clojure-development/project-configuration/#custom-code but dont use them myself.
Can the defun be defined in your Emacs configuration and called from the .dir-locals.el
? It might make the .dir-locals.el easier to work with (and maybe fix the underlying issue)
Hmm, I'm still getting prompted. I moved the defun to my config.el and deleted my custom.el. I started emacs, answered !
, and quit emacs. Starting again I'm prompted again.
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 after-org-insert-heading-add-property-created)
(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
'((org-log-into-drawer . t)
(eval add-hook! org-insert-heading :local after-org-insert-heading-add-property-created)
(cider-jack-in-nrepl-middlewares "cider.nrepl/cider-middleware" "shadow.cljs.devtools.server.nrepl/middleware"))))
(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.
)
(defun after-org-insert-heading-add-property-created ()
(org-set-property "CREATED" (format-time-string "[%Y-%m-%d %T]")))
Oh, this is different File local-variables error: (void-variable after-org-insert-heading-add-property-created)
I'll read what you linked, I must have it configured incorrectly.
Hmm. I can't figure out how to use add-hook!
I've been playing around with it but after moving the function to my config.el, the hook isn't running.
Hmm. I moved the dufun back to .dir-locals.el and the hook still isn't running. Interesting, it's broken now.
I am sure help can be found at the #doom-emacs channel or in the Doom Emacs discord community
Doom has some macros that may help, like map!
and after!
but I havent done anything fancy in my https://github.com/practicalli/doom-emacs-config I dont think.