Skip to content

Save buffer before executing markdown-open-command #248

@saf-dmitry

Description

@saf-dmitry

I would suggest some small improvements to the markdown-open command. The version below will first save the buffer content using (save-buffer (buffer-file-name)) and then run the markdown-open-command on the file.

(defun markdown-open ()
  "Open file for the current buffer with `markdown-open-command'."
  (interactive)
  (if (not markdown-open-command)
      (user-error "Variable `markdown-open-command' must be set")
    (if (not buffer-file-name)
        (user-error "Must be visiting a file")
      (save-buffer (buffer-file-name))
      (call-process markdown-open-command
                    nil nil nil buffer-file-name))))

For the time being you could advise the markdown-open function:

(defadvice markdown-open (before my-markdown-save-and-open activate)
  "Save buffer before open file for the current buffer."
  (unless (buffer-file-name) (user-error "Must be visiting a file"))
  (save-buffer (buffer-file-name)))

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions