Skip to content

Instantly share code, notes, and snippets.

@ymorimo
Created May 4, 2011 10:02
Show Gist options
  • Save ymorimo/955020 to your computer and use it in GitHub Desktop.
Save ymorimo/955020 to your computer and use it in GitHub Desktop.
Set xattr after saving UTF-8 files in Emacs
(when (eq system-type 'darwin)
(defvar my-set-xattr-utf-8-modes '(text-mode org-mode ruby-mode js2-mode css-mode))
(defun my-set-xattr-if-utf-8()
(when (and (memq major-mode my-set-xattr-utf-8-modes)
(string-match "^utf-8" (prin1-to-string buffer-file-coding-system)))
(call-process "xattr" nil 0 nil "-w" "com.apple.TextEncoding" "UTF-8;134217984" buffer-file-name)))
(add-hook 'after-save-hook 'my-set-xattr-if-utf-8))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment