4

I have a specific file which I want to always open with visual-line-mode activated. This file cannot be distinguished from others for which I want visual-line-mode deactivated, either by file name/extension or by its contents. For example, running file(1) on the file in question will give the same result as it would on lots of my other files.

At the moment, I am using # -*- eval: (visual-line-mode t); -*- in the first line of the file. This is less than ideal because every time I open the file I need to confirm I want to eval this code. The file should just open in visual-line-mode without asking for confirmation. What is the best way to achieve this?

A perfect answer would not require me to add anything to my .emacs and would be applicable to other modes besides visual-line.

6
  • 1
    I fear that the available solution space under those constraints (no eval warning, no distinct filename pattern, and no Lisp code) is the empty set. You almost certainly need to find a way to live with changing at least one. Commented May 26, 2022 at 8:32
  • 1
    The confirmation warning should provide an option to 'permanently mark these values as safe' by pressing !? Isn't that the solution you are looking for? You would only have to do this once for every new variable(-list) you are setting. You could also set the safe-local-variable-values directly, as explained in the 'Safety of File Variables' section of the Emacs manual. Commented May 26, 2022 at 8:53
  • 1
    @dalanicolai Thanks for that. It does modify my .emacs to do that but I suppose I can live with it.
    – wieks
    Commented May 26, 2022 at 12:14
  • 2
    There is a way: Report a bug. (visual-line-mode t) should have the safe-function property. If it has this property no confirmation is needed before evaluation. Report this and maybe they add this property in the next Emacs version.
    – Tobias
    Commented May 26, 2022 at 15:56
  • 1
    The eval isn't necessary. # -*- visual-line-mode: t -*- should be sufficient.
    – nega
    Commented Jun 1, 2022 at 14:35

1 Answer 1

1

You can prevent future modification of your init file (by customize) by defining a separate file to hold custom settings (a la safe-local-variable-values). At the beginning of your init file do something like

;; nb. `custom-file` is an Emacs variable see `C-h v custom-file`
(setq custom-file (expand-file-name "~/.emacs.d/custom.el"))

and at the end of your init file add

(load custom-file)

(Ok, it doesn't have to be split like that, but that's how I organize my init file. I do recommend having the call to load at the end of your init file though.)

Note that custom-file itself is a customize-able variable, so I encourage you to read it's help via C-h v custom-file.

If you do this, you should obviously move any custom settings to your new file, or delete them. This is great in situations where your init files are read-only, or you keep them under version control (don't forget to add your new custom-file to your VC's ignore list).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.