Domanda

How do I (automatically) set the dictionary (e.g. through an automated call to ispell-change-dictionary) to a specific language for every file below a particular directory?

Example: I'd prefer my standard directory language to be American English (e.g. by setting (setq ispell-dictionary "en_US-wo_accents") in my .emacs file) but I'd like to use British English for all files below (or: under) the directory /home/werner/dissertation/. And perhaps to Dutch for all files under /home/werner/letters/.

I am aware of the solution that prescribes to use -*- ispell-dictionary: "english" -*- at the first line of a file to set the dictionary for that particular file (described at EmacsWiki.org). I'd like to prevent to have to put this line on top of every new file that I make.

È stato utile?

Soluzione

You can use something like (but this approach is more useful when you want to make something complex for given files):

(defun set-dictionary-hook ()
  (when (and (stringp buffer-file-name)
     (string-match "/dissertation/" buffer-file-name))
    (setq ispell-local-dictionary "ru")))
(add-hook 'find-file-hook 'set-dictionary-hook)

or you can specify it in .dir-locals.el as described in Emacs Manual - I think, that this will simpler than first approach, something like:

((tex-mode . ((ispell-local-dictionary . "english"))))

for files with specific modes, or

((nil . ((ispell-local-dictionary . "english"))))

for all files

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top