Convert any file pandoc can read to org
I got an idea from an EmacsElements video by Raoul Comninos where he converts docx and odt files he finds with dired to org format with two separate functions. Doc-view mode is nice for viewing files from MS365 and LibreOffice and other programs that use Open Document Format with the help of unoconv (which comes with LibreOffice), but you cannot edit the files. So he made these two functions to convert it to Org markup which Emacs edits well in Org mode. After editing, he can export a .docx or .odt through ox-pandoc to send back to the people that sent him the original file.
I have experienced the same need at work where most documents coming from others are .docx even if all my own documents are pure text files. I thought that I could convert any file format to org by using its extension as the from format for pandoc instead of having separate functions for different file formats. It seems to work. My function will either convert the file if pandoc can use it as input or give an error. I bound the function to C-z o to make it easy to convert and open a file from dired.
(defun emo-dired-convert-to-org () "Converts files pandoc can convert to org files for easy editing. Use in dired." (interactive) (let ((endelse (file-name-extension (dired-get-file-for-visit))) (filnavn (dired-get-file-for-visit)) (buffernavn (concat (file-name-nondirectory (dired-get-file-for-visit)) ".org"))) (with-output-to-temp-buffer buffernavn (princ (shell-command-to-string (concat "pandoc -f " endelse " -t org --wrap=none \"" filnavn "\"")))) (switch-to-buffer-other-window buffernavn)))