9

In a python file I have

# Local Variables:
# python-shell-interpreter: "python3"
# python-shell-virtualenv-path: "~/.virtualenvs/datascience"
# leo-python-args-to-send: "-f fqanalysis.txt"
# End:

For a couple of days I want to use the python file without the specified virtualenv, so I would like to comment out the line setting python-shell-virtualenv-path, so that next time I open the python file in emacs python-shell-virtualenv-path keeps its global value.

I tried

# ;;python-shell-virtualenv-path: "~/.virtualenvs/datascience"

and

## python-shell-virtualenv-path: "~/.virtualenvs/datascience"

but on opening the python file I always get the error

File mode specification error: (error "Malformed local variable line: ...)

How do I comment out the local variable line correctly?

1
  • When I select the line containing # python-shell-virtualenv-path: "~/.virtualenvs/datascience" and apply the command comment-region, the result is # # python-shell-virtualenv-path: "~/.virtualenvs/datascience". I don't know if it is the correct way to comment out local variables.
    – Name
    Commented Sep 2, 2015 at 9:51

1 Answer 1

8

Based on a quick check of C-hig (emacs) Specifying File Variables, I'm reasonably sure that you can't.

I think your options are:

  • Move the comment outside of the local variables block.
  • Change the variable (e.g. give it a prefix like DISABLED:) such that the value is simply assigned to a variable which nothing uses.

Edit:

If you don't want to have to approve a bunch of DISABLED:foo variables for safe-local-variable-values, you could adapt the approach to take advantage of the fact that successive entries clobber earlier ones if the same variable name is used. Something like:

# Local Variables:
# #: python-shell-interpreter: "python3"
# #: python-shell-virtualenv-path: "~/.virtualenvs/datascience"
# leo-python-args-to-send: "-f fqanalysis.txt"
# #: <comment>
# End:

These still aren't comments, but it does mean you only have a single local variable named # (or \# in this instance) with the value <comment>, and Emacs won't query you about the earlier ones; so you could re-use this approach in other files and only end up with a single safe-local-variable-values entry for all such 'commented' values, so long as that #: <comment> entry always comes last.

(YMMV; this is only lightly tested, and is obviously a hack workaround. Note also that you needn't use the actual comment character, as it's actually a variable name, so you can call it whatever you want, so long as it's not likely to conflict with any 'proper' variable name.)

You could ditch the need for a #: <comment> entry but still avoid being asked questions if you added the following to your config:

(put '\# 'safe-local-variable (lambda (_) t))

Which says "ALL values for the variable # are safe.

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.