Skip to content

Instantly share code, notes, and snippets.

@tek-nishi
Last active August 29, 2015 14:14
Show Gist options
  • Save tek-nishi/a444901b5cf07fe15d40 to your computer and use it in GitHub Desktop.
Save tek-nishi/a444901b5cf07fe15d40 to your computer and use it in GitHub Desktop.
Set encoding new file for some extensions.
(defun my-set-encoding ()
"新規ファイル生成時のみ、エンコードを強制する Thanks for Syohei YOSHIDA"
(let ((bufname (buffer-file-name)))
(when (not (file-exists-p buffer-file-name))
(when (and bufname (string-match-p ".+\\.\\(cpp\\|c\\|hpp\\|h\\|mm\\)$" bufname))
(set-buffer-file-coding-system 'utf-8-with-signature)))))
(add-hook 'find-file-hook 'my-set-encoding)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment