edit-as-format
edit-as-format copied to clipboard
Edit document as other format, in Emacs, using Pandoc
#+STARTUP: showall #+TITLE: Edit As Format #+OPTIONS: num:nil ^:{} toc:nil
- Introduction Edit document as other format, as long as your format is supported by [[https://pandoc.org/][Pandoc]].
You love OrgMode, but have to use markdown sometimes, open your markdown file in emacs, =M-x= =edit-as-format-org=, happy writing!
[[https://s3.bmp.ovh/imgs/2022/02/4411a7373b3707e6.gif]]
- Features
- Edit document as other format in a separate buffer, with changes commited back to original buffer
- Handle selected region or whole buffer
- =edit-as-format-org= edit current buffer as org document
- =edit-as-format= edit current buffer as other format, prompt for target format
- supported formats
- default format list use intersection of =pandoc --list-input-formats= and =pandoc --list-output-formats=
- however, not all that list is supported, especially non-textual formats
- basically, markup language formats will works OK
- it's customizable =edit-as-format-formats=
- Configuration
Prerequisite
- install [[https://pandoc.org/installing.html][Pandoc]], make it accessible from ~PATH~
Use package from Melpa
#+begin_src elisp (use-package edit-as-format :ensure t :bind ("C-c e e" . edit-as-format)) #+end_src
Custom commands can be created easily with =edit-as-format=, examples:
#+begin_src elisp (defun edit-org-as-markdown () (interactive) (edit-as-format "org" "markdown")) (defun edit-as-markdown () (interactive) (edit-as-format nil "gfm") #+end_src
- Key Bindings This package uses edit-indirect for editing, the key binding in =edit-indirect-mode-map= resembles =org-src-mode-map=
#+begin_quote
- C-c ' edit-indirect-commit
- C-c C-c edit-indirect-commit
- C-c C-k edit-indirect-abort
- C-x C-s edit-indirect-save #+end_quote
Bind key to =edit-as-format= =edit-as-format-org= for convenient access
#+begin_src elisp (global-set-key (kbd "C-c e e") 'edit-as-format) (global-set-key (kbd "C-c e o") 'edit-as-format-org) #+end_src
Optionally, unbind =edit-indirect-commit=, give [C-c '] back to =org-edit-special= in org-mode
#+begin_src elisp (unbind-key "C-c '" edit-indirect-mode-map) #+end_src
- Alternatives
- [[https://github.com/tecosaur/org-pandoc-import][org-pandoc-import]] gives a rather complete solution, it has many good features, in contrast, =edit-as-format= takes a simpler way: =pandoc + edit-indirect= (and takes some code from =org-pandoc-import=, great thanks).
- Known issues
- markdown redundant spaces, maybe write pandoc filter ?