19

Set the safe-local-variable property to a function that validates the value. For example, fill-column has a safe-local-variable property set to integerp. Use (lambda (x) t) as the validation function if any value is valid. (defvar my-variable-with-any-safe-value …) (put 'my-variable-with-any-safe-value 'safe-local-variable (lambda (x) t)) or (...


17

(setq whitespace-global-modes '(not org-mode)) See C-hv whitespace-global-modes RET


13

The comment from @Malabarba explains your problem. kill-local-variable does get rid of the local variable binding. But since in your case the variable is automatically local in any buffer, when you reassign it a value, that value is local. AFAIK, there is no way to counter make-variable-buffer-local, except to use unintern on the symbol. (makunbound does ...


9

It sounds like your goal is to have org-mode files always show everything when in ediff. The simplest solution is probably to avoid the local variables approach and just put show-all in the relevant hook, ediff-prepare-buffer-hook which is run after buffers A, B, & C are set up: (with-eval-after-load 'outline (add-hook 'ediff-prepare-buffer-hook #'...


9

When you call add-dir-local-variable, it assumes you are already in the directory you want to apply the directory-local variable to. When it prompts for a directory, it's asking if you want the variable applied to a subdirectory of your current directory. So I expect giving it the absolute path to a directory is causing your problem. In your case, I think ...


8

Emacs should offer (and normally does offer) the option to accept and remember the choice for later sessions. I suggest you M-x report-emacs-bug about this missing choice in your case. In the mean time, you can add the following to your ~/.emacs: (add-to-list 'safe-local-variable-values  '(LaTeX-command . "lualatex -shell-escape"))


8

Try this: (add-hook 'js-mode-hook 'my-javascript-hook) (defun my-javascript-hook () (company-mode -1) (auto-complete-mode 1))


8

You can do this for a specific buffer with M-x auto-revert-mode (manual). For file buffers, this will check every auto-revert-interval seconds (defaults to 5) for changes and update the buffer from disk automatically. Your title says "a particular file" while your question's body mentions a file type (org files). Depending on your circumstances, here are a ...


8

In case someone else runs into this, I had enabled TeX-auto-save, which saves settings to an auto/ directory and loads them when a file is revisited. https://www.gnu.org/software/auctex/manual/auctex/Parsing-Files.html


8

(defvar my-local-variable nil "Variable used on a bufer-local basis to indicate ...") (make-variable-buffer-local 'my-local-variable) USAGE: (setq my-local-variable (lambda () (message "major-mode: %s" major-mode))) (define-key name-of-major-mode-keymap [f5] (lambda () (interactive) (funcall my-local-variable)))


7

You can use backquotes and commas to build functions dynamically: `(lambda () (interactive) (insert ,(cdr text))) Or you can also enable lexical-binding to make function closures. More information on Backquotes can be found in Emacs manual.


7

You can easily disable checkers using (setq flycheck-disabled-checkers '(sh-shellscript sh-bash sh-zsh)) The Flycheck documentation adds more information here. You can also disable checkers in a lambda for auto-mode-alist to have it only disable on .cfg files. (add-to-list 'auto-mode-alist '("\\.cfg\\'" . (lambda () ...


7

Based on the answer here, we do this by advising hack-dir-local-variables to look one directory up and load check if that .dir-locals.el file is readable. It will keep going up until it finds a directory with no readable .dir-locals.el. Depending on the value of walk-dir-locals-upward the files can be read from the current directory upward or from the last ...


6

Directory-local variables were actually designed for this use case as well. Read the docs, especially at the end, where it discusses dir-locals-set-directory-class. The idea here is that you can keep the directory-local settings somewhere other than in the .dir-locals.el file. Another way to accomplish this same thing is to make settings directory-...


6

Here's a different way of doing this. I define a function that produces the list of all the directories in the current directory hierarchy. (defun file-name-directory-nesting-helper (name previous-name accumulator) (if (string= name previous-name) accumulator ; stop when names stop changing (at the top) (file-name-...


4

It is probably easier to turn off whitespace mode directly, using (whitespace-mode -1) Also, whitespace-style is not a buffer-local variable, so it is modified for all other buffers as well. Try instead (set (make-local-variable 'whitespace-style) nil)


4

I think what you might do is to use properties of the variable symbol to store the history. That is, each symbol can have a property list, which is a list of pairs. The key will be major mode names, and value the history as list you wanted. But i don't know if that's efficient enough to work out.


4

Here's one way to do it: (let ((a 2)) (pcase 2 ((pred (equal a)) 7))) This snippet uses the fact that (rephrasing (describe-function 'pcase)) a predicate may have the form(FUN ARG1 .. ARGN) in which case it gets called with an N+1'th argument which is the value being matched.


4

You can use a hook to achieve this. Use the one you need as described in auctex documentation. Here we check the file extension so that we don't do that for eg .sty files.  Also, we test the buffer-read-only variable before modifying the buffer. The goto-char at the end ensures point is set at beginning of buffer. (defun my/add-auctex-file-variables () ...


3

I don't know how to enable/disable custom-themes for a buffer only. The following works for changing the global custom-theme when you enter a Tramp buffer, or when you leave it. (add-hook 'buffer-list-update-hook (lambda () (if (and (not (window-minibuffer-p)) (file-remote-p default-directory)) (enable-theme 'pastels-on-dark) (...


3

Another option can be found on the worg page. The basic idea is to use ediff-select-hook to unfold an element whenever given region is selected in ediff and folding them back in the ediff-unselect-hook. I am posting the code here for completeness ;; Check for org mode and existence of buffer (defun f-ediff-org-showhide (buf command &rest cmdargs) "If ...


3

An alternative to pcase with similar features would also suffice (let ((a 2)) (cond ((eq a 2) 7))) ;; => 7 This isn't a joke - everything that can be done with pcase can also be done with a combination of let and cond. And it think it should be - gratuitous branch-introducing macros aren't helping anyone to either code faster or maintain ...


3

Yes. Put this at the end of your file. * COMMENT Config Local Variables: eval: (auto-revert-mode 1) End: This assumes Org-mode, for other modes use comments in the language used as explained in the link given below. Note: see Local Variables in Files in the manual for the background, safety information and a caveat that this might not always be a good ...


3

Use the special "variable" eval as described in Specifying File Variables. This .dir-locals.el code enables whitespace-mode for me: ((c++-mode (eval . (whitespace-mode)))) (I use Emacs 24.4.1.)


3

Save your data as a window-parameter. It will force you to use :eval inside your mode-line, but that's not something to be afraid of. If you want to discuss changes to the "core" Emacs features (like adding window-local variables), then the emacs-devel mailing-list is the place to do it. In this particular case I don't think there's much chance of success ...


2

Sounds like my-package-insert turns on a major mode. Doing that calls kill-all-local-variables. You can give the variable a non-nil permanent-local property to protect it. But we would need more info to be able to suggest whether that is a good idea in your context. If you don't need the variable to be bound before my-package-insert then consider binding ...


2

You can disable this "don't remember risky variables" feature by putting the following in your ~/.emacs: ;; allow remembering risky variables (defun risky-local-variable-p (sym &optional _ignored) nil) Then it'll only re-confirm when you edit one.


2

A variable is either buffer-local or not. If it's buffer-local then the value isn't shared with other buffers. There's no built-in feature to directly have a variable that's shared between buffers. So you'll need to do something where accessing the value of the variable isn't just my-variable and setting isn't just (setq my-variable some-value). One ...


2

If you want to set a buffer-local value for a given mode, do so after the mode has been established. You do that by putting the value-assignment on the mode hook. For example, if you want to set local variable foo to 42 in lisp-mode then do something like this: (add-hook 'lisp-mode (lambda () (setq-local fill-paragraph-function 'my-fill-para))) Or better ...


Only top voted, non community-wiki answers of a minimum length are eligible