I've seen this, but it doesn't work for this case.... Basically, I want to do a load-file on an .el file containing

(add-file-local-variable-prop-line "eval" "(set-input-method 'TeX)")

and have it add

;;-*- eval: (set-input-method 'TeX)  -*-

at the top of that same file; instead, it inserts

;; -*- "eval": "(set-input-method 'TeX)"; nil

which is mangled and doesn't work. Obviously, the double-quotes (and the nil too?) render it bad. But then using no quotes and single quotes to satisfy the two interactive prompts produce errors. How can I do this non-interactively "batch" style?


This really has nothing to do with interactive functions at all.

An interactive function is just a function where emacs has some metadata about how the arguments to the function are to be filled in when the function is called by the user. This metadata is ignored when the function is called from code instead. It's up to the caller in this case to supply the necessary arguments, same as for any function call.

In this case the important line is (insert (format "; %S: %S; " variable value)). This is how modify-file-local-variable-prop-line ultimately puts the text into the buffer. If we look at the help for the format function (C-h f format RET), we see that %S tells it to print the argument using prin1, which has the goal of reproducing the lisp value exactly. Thus, if you pass in a string as the variable, it'll be printed as a string so that when someone calls read on it they get back a string. This means that you want to pass in the eval atom rather than the string "eval":

(add-file-local-variable-prop-line 'eval '(set-input-method 'TeX))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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