(defun sanityinc/utf8-locale-p (v)
  "Return whether locale string V relates to a UTF-8 locale."
  (and v (string-match "UTF-8" v)))

(defun locale-is-utf8-p ()
  "Return t iff the \"locale\" command or environment variables prefer UTF-8."
  (or (sanityinc/utf8-locale-p (and (executable-find "locale") (shell-command-to-string "locale")))
      (sanityinc/utf8-locale-p (getenv "LC_ALL"))
      (sanityinc/utf8-locale-p (getenv "LC_CTYPE"))
      (sanityinc/utf8-locale-p (getenv "LANG"))))

(when (or window-system (locale-is-utf8-p))
  (setq utf-translate-cjk-mode nil) ; disable CJK coding/encoding (Chinese/Japanese/Korean characters)
  (set-language-environment 'utf-8)
  (setq locale-coding-system 'utf-8)
  (set-default-coding-systems 'utf-8)
  (set-terminal-coding-system 'utf-8)
  (unless (eq system-type 'windows-nt)
   (set-selection-coding-system 'utf-8))
  (prefer-coding-system 'utf-8))

(provide 'init-locales)

(defun sanityinc/utf8-locale-p (v)
  "Return whether locale string V relates to a UTF-8 locale."
  (and v (string-match "UTF-8" v)))

(defun locale-is-utf8-p ()
  "Return t iff the \"locale\" command or environment variables prefer UTF-8."
  (or (sanityinc/utf8-locale-p (and (executable-find "locale") (shell-command-to-string "locale")))
      (sanityinc/utf8-locale-p (getenv "LC_ALL"))
      (sanityinc/utf8-locale-p (getenv "LC_CTYPE"))
      (sanityinc/utf8-locale-p (getenv "LANG"))))

(when (or window-system (locale-is-utf8-p))
  (setq utf-translate-cjk-mode nil) ; disable CJK coding/encoding (Chinese/Japanese/Korean characters)
  (set-language-environment 'utf-8)
  (setq locale-coding-system 'utf-8)
  (set-default-coding-systems 'utf-8)
  (set-terminal-coding-system 'utf-8)
  (set-selection-coding-system (if (eq system-type 'windows-nt) 'utf-16-le 'utf-8))
  (prefer-coding-system 'utf-8))

(provide 'init-locales)

Use utf-16-le for selection-coding-system on windows
Use utf-16-le for selection-coding-system on windows

See https://stackoverflow.com/questions/2901541/which-coding-system-should-i-use-in-emacs/2903256#comment20730840_2903256

DarkThrone/emacs.d,ruiyang/emacs.d,haodaivshen/emacs.d,exclamaforte/emacs.d,shafayetkhan/emacs.d,benkha/emacs.d,zhaotai/.emacs.d,emuio/emacs.d,ilove0518/emacs.d,LittleLmp/emacs.d,jthetzel/emacs.d,farzadbekran/emacs.d,roxolan/emacs.d,zenith-john/emacs.d,danfengcao/emacs.d,modkzs/emcs.d,lust4life/emacs.d,ruiyang/emacs.d,purcell/emacs.d,boblannon/emacs.d,Guoozz/emacs.d,mmqmzk/emacs.d,Jadecity/PurcellEmacs.d,wenpincui/emacs.d,hkcqr/emacs.d,svenyurgensson/emacs.d,whizzzkid/emacs.d,fengxl/emacs.d,wegatron/emacs.d,Togal/emacs.d,qinshulei/emacs.d,Shanicky/emacs.d,Enzo-Liu/emacs.d,me020523/emacs.d,sgarciac/emacs.d,dhanunjaya/emacs.d,zhuoyikang/emacs.d,blueabysm/emacs.d,alant/emacs.d,caoyuanqi/emacs.d,lromang/emacs.d,jhpx/emacs.d,atreeyang/emacs.d,gsmlg/emacs.d,jachinpy/emacs.d,renatoriccio/emacs.d,braveoyster/emacs.d,kongfy/emacs.d,farzadbekran/emacs.d,arthurl/emacs.d,scorpionis/emacs.d,jkaessens/emacs.d,mpwang/emacs.d,krzysz00/emacs.d,cjqw/emacs.d,farzadbekran/emacs.d,baohaojun/emacs.d,46do14/emacs.d,farzadbekran/emacs.d,jachinpy/emacs.d,carlosliu/emacs.d,LKI/emacs.d,ernest-dzf/emacs.d,dcorking/emacs.d,qianwan/emacs.d,kindoblue/emacs.d,farzadbekran/emacs.d,lujianmei/emacs.d,hophacker/emacs.d,Werewolflsp/emacs.d,cyjia/emacs.d,dongdonghu/.emacs.d,bibaijin/emacs.d,blueseason/emacs.d,pairyo/emacs.d