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 to send back to the people that sent him the original file.
Export of .docx is the reason my Emacs config installs ox-pandoc which exports to .docx through pandoc, so I have experienced the same need occasionally even though I am lucky that most of the documents I use at work are pure text files with either code or org markup I use for interactive presentations in class with org-present.
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 had to open the async-shell-command buffer with switch-to-buffer because I normally hide this buffer from popping up to avoid unwanted distractions when using async-shell-command, but for most users, this is not needed.
I bound the function to C-z o in my own keymap to make it easy to open a file. The idea is to use this function in dired. I usually get .docx files for reading only through Teams at work which I usually read in the browser where I also use Teams, but occasionally, I need to edit one and I thought this function might save me an excursion outside my favourite text editor.
(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))) (async-shell-command (concat "pandoc -f " endelse " -t org --wrap=none " "\"" filnavn "\"")) (switch-to-buffer "*Async Shell Command*")))