I'm sure you probably do not care about Emacs enough to want to deal with maintaing code for it but just for reference in case other nerds are using Emacs,
Emacs is heavy into using scratch buffers which are still in markdown-mode
but don't actually have a file on the disk. So you don't want to allow this function to be called on those buffers. Thus you need to make sure it's visiting a file.
(defun markdown-preview-file ()
"Open the current file (if visiting one) in Marked."
(interactive)
(when (buffer-file-name)
(shell-command (concat "open -a Marked.app " (shell-quote-argument buffer-file-name)))))
Second, you shouldn't set a global key for this. Keybindings are supposed to be mode specific in most cases and it makes sense since there is a markdown-mode
that it should be bound in that mode,
(eval-after-load 'markdown-mode
'(define-key markdown-mode-map (kbd "C-c m") 'markdown-pandoc))
or if you only use text-mode
you could do,
(define-key text-mode-map (kbd "C-c m") 'markdown-preview-file)
And as a footnote if you want to make markdown-mode
the default for txt
files you can do,
(setq auto-mode-alist
(cons '("\\.txt" . markdown-mode) auto-mode-alist))