Emacs decodes a text file with an appropriate coding system when you open it with find-file
.
If you have to tell emacs for some reason what coding system it should use for decoding the file you should do so before you open the file.
You can set the coding system for the next command with Options -> Multilingual Environment -> Set Coding Systems -> For Next Command.
That next command can be find-file
for your file subtitle.srt
.
The file is then read with the coding system of your choice.
If you often need to open files with specified coding system you can also use the following command. Paste the code into your init file and restart emacs. Afterwards you can use the new menu item Find File With Coding System in the File menu.
(defun find-file-with-coding-system (file coding-system)
"Find FILE with CODING-SYSTEM."
(interactive (list
(read-file-name "File Name:")
(read-coding-system "Coding System:")))
(let (buf (coding-system-for-read coding-system))
(if (setq buf
(catch :exit
(while (setq buf (find-buffer-visiting file))
(if (y-or-n-p (format "Kill buffer \"%s\" visiting file \"%s\"?" buf file))
(kill-buffer buf)
(throw :exit buf)))))
(error "Buffer \"%s\" is still visiting \"%s\". In that case `find-file-with-coding-system' does not work as expected." buf file)
(find-file file))))
(require 'easymenu)
(easy-menu-add-item menu-bar-file-menu nil ["Find File With Coding System" find-file-with-coding-system t] "Filesets")
Note that normally the coding system of the file is automatically detected.
For newly created buffers and for buffers where the coding system cannot be uniquely identified the option default-buffer-file-coding-system
determines which coding system is preferred.
As far as I know there is no predefined function changing the buffer file coding-system for decoding without re-reading the file.
That is what you actually asked me in one of your comments:
And the last question: Is it possible to correct decode file AFTER open?
Maybe, that function is not provided since the decoding is not necessarily injective and the translation of the coding system can fail.
Nevertheless, the next lisp function tries to change the coding system for decoding without re-reading the file.
(defun translate-buffer-encoding (target-encoding &optional source-encoding)
"Translate buffer encoding from SOURCE-ENCODING to TARGET-ENCODING."
(interactive (list (read-non-nil-coding-system "Target encoding:")))
(unless source-encoding
(setq source-encoding buffer-file-coding-system))
(encode-coding-region (point-min)
(point-max)
source-encoding)
(decode-coding-region (point-min)
(point-max)
target-encoding)
(set-buffer-file-coding-system target-encoding))
find-file
and not to encoding.