Skip to content

Instantly share code, notes, and snippets.

@Archenoth
Last active March 6, 2017 05:47
Show Gist options
  • Select an option

  • Save Archenoth/935c8aadda4f90c2b995423176b983f0 to your computer and use it in GitHub Desktop.

Select an option

Save Archenoth/935c8aadda4f90c2b995423176b983f0 to your computer and use it in GitHub Desktop.
Opening a UTF file with a BOM marker will make Emacs play "BOM BOM BOOOOM" before letting you see it
(defun detect-bom (filePath)
"Given a filepath, plays BOM BOM BOOOOOM if the file has a BOM"
(with-temp-buffer
(insert-file-contents-literally filePath)
(let ((bom (decode-coding-string (buffer-substring-no-properties 1 4) 'utf-8)))
(when (string= bom (string ?\uFEFF))
(play-sound-file "bombombom.wav")))))
(add-hook 'find-file-hook (lambda () (detect-bom buffer-file-name)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment