Skip to content

Instantly share code, notes, and snippets.

@jmn
Created May 23, 2015 20:15
Show Gist options
  • Save jmn/9c1492ae1b483b84c203 to your computer and use it in GitHub Desktop.
Save jmn/9c1492ae1b483b84c203 to your computer and use it in GitHub Desktop.
Emacs org-capture: Handle wrong (non utf-8) character encoding using special template
;; If the org property value of CODING is not nil, mark the (capture) buffer it and use recode-region to recode it to UTF-8.
(defun jmn/recode-buffer-from-cp1252-to-utf-8 ()
""
(message "recoding buffer!")
(interactive)
(mark-whole-buffer)
(recode-region (region-beginning) (region-end) 'cp1252 'utf-8)
)
(add-hook 'org-capture-prepare-finalize-hook
'(lambda ()
(if (cdr(assoc "CODING" (org-entry-properties nil 'standard)))
(progn
(org-delete-property "CODING")
(jmn/recode-buffer-from-cp1252-to-utf-8)
)
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment