Skip to content

Instantly share code, notes, and snippets.

@siancu
Created January 15, 2013 22:30
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siancu/4542778 to your computer and use it in GitHub Desktop.
Save siancu/4542778 to your computer and use it in GitHub Desktop.
Function to open Marked.app from Emacs showing the contents of the current Markdown file.
(defun markdown-preview-file ()
"run Marked on the current file and revert the buffer"
(interactive)
(shell-command
(format "open -a /Applications/Marked.app %s"
(shell-quote-argument (buffer-file-name))))
)
(global-set-key (kbd "C-c m") 'markdown-preview-file)
@rmm5t
Copy link

rmm5t commented Feb 5, 2013

Thanks for getting me started down the path of what I wanted to accomplish here. I added some behavior to only load Marked.app if it is installed; otherwise, fallback to regular markdown-preview

(defun marked-markdown-preview ()
  "run Marked on the current file if Marked is installed;
otherwise fallback to markdown-preview"
  (interactive)
  (let ((marked-app "/Applications/Marked.app"))
    (if (file-exists-p marked-app)
        (shell-command
         (format (concat "open -a " marked-app " %s")
                 (shell-quote-argument (buffer-file-name))))
      (markdown-preview))
    ))

(eval-after-load 'markdown-mode
  '(progn
     (define-key markdown-mode-map (kbd "C-c C-v") 'marked-markdown-preview)
     ))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment