1

I have a lot of filenames in Russian in my file system. Every time I close Emacs if I had eshell opened, it shows a *temp* buffer with a list of directories. And asks 2 questions:

  1. Select coding system (default utf-8):

    I click enter

  2. Selected encoding utf-8 disagrees with latin-2 specified by file contents. Really save (else edit coding cookies and try again)? (y or n)

    I click "y", enter

What file cookies is he talking about? Where can I set it to utf-8, so this question is never asked again?

Update

I found the wrong file: ~/.emacs.d/eshell/lastdir. I saved this: "яОяН­яОяННяОуВяНЕяОяОяННяОяНОяОяНВяОяНА" instead of normal Russian name. Then it tries to save it again.

4
  • I can't find any mention of such a file "cookie" in the manual, may it may refer to gnu.org/software/emacs/manual/html_node/emacs/…
    – JeanPierre
    Apr 3, 2017 at 19:06
  • @JeanPierre Maybe, it tries to save the history of eshell somewhere?
    – user4035
    Apr 3, 2017 at 19:09
  • Do you have all of the following set? (setq locale-coding-system 'utf-8) (set-terminal-coding-system 'utf-8) (set-keyboard-coding-system 'utf-8) (set-selection-coding-system 'utf-8) (prefer-coding-system 'utf-8)
    – mclear
    Apr 5, 2017 at 3:23
  • @mclear Tried, didn't help. Please, see the update: I found the file that causes the error, but don't know, what to do with it.
    – user4035
    Apr 5, 2017 at 8:02

2 Answers 2

1

The file you mention is where Eshell saves the directory ring, which is basically a list of the directories that you've visited. Just like in most shells, you can use cd - to go back to the previous directory. cd = will display the contents, and so on (see the Eshell manual for all the details). Eshell saves this list to a file so that you'll still have it in your next session, and Emacs will always prompt the user when it things the coding system might be incorrect. I can see how it would be frustrating that it asks you all the time about a file you're not specifically editing. One way to control the coding system that Emacs uses is by setting a file-local variable, which is why the error message mentions them. (I think "cookie" is an older term for it, which adds to the confusion.)

The code that saves the list is eshell-write-last-dir-ring in em-dirs.el. As you can imagine, all it does is open a temporary buffer, insert every item in the list into the buffer, followed by a newline character, then write the buffer to the file. The error message itself comes from select-safe-coding-system in mule-cmds.el, which is horrible. Seriously, don't look at it. I don't know why this function is so complex, but I assume that it "gradually got so" (to coin a phrase).

I don't know what the best way to fix this will be, but the first thing that select-safe-coding-system does is compare the filename with the contents of the variable auto-coding-alist. You could add an entry for this specific file, which sets the desired coding system to 'utf-8. As you can see from the error message, the contents look to Emacs like utf-8, but it thought for some other reason that it should be saved in latin1. Editing auto-coding-alist should fix that.

0

I was facing a similar problem i.e while closing the Emacs (my version 26.3), I was repeatedly prompted about the encoding: Select coding system (default utf-8):

I solved the problem by deleting some entries from .emacs.d/ac-comphist.dat file (in my case, the character is the lowercase lambda λ).

1
  • Sounds like a bug in the package that writes ac-comphist.dat. Please report it accordingly.
    – Stefan
    Apr 19, 2020 at 1:50

Your Answer

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

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