From 5079b679e5beac994bca7ee657234c0835580d23 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Mon, 19 Aug 2019 22:56:33 +0800 Subject: [PATCH] Fix #3: Wrong buffer being rendered. --- grip-mode.el | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/grip-mode.el b/grip-mode.el index 769c9e2..321a2a5 100644 --- a/grip-mode.el +++ b/grip-mode.el @@ -63,7 +63,7 @@ (defvar-local grip-port 1088 "Port to the grip port.") -(defvar-local grip-preview-file buffer-file-name +(defvar-local grip-preview-file nil "The preview file for grip process.") (defun grip-start-process () @@ -77,13 +77,15 @@ (setq grip-port (random 65535))) ;; Start a new grip process - (setq grip-process - (start-process (format "grip-%d" grip-port) - (format " *grip-%d*" grip-port) - grip-binary-path - "--browser" - grip-preview-file - (number-to-string grip-port))))) + (when grip-preview-file + (setq grip-process + (start-process (format "grip-%d" grip-port) + (format " *grip-%d*" grip-port) + grip-binary-path + "--browser" + grip-preview-file + (number-to-string grip-port))))) + (message (format "Preview %s on http://localhost:%d" buffer-file-name grip-port))) (defun grip-kill-process () "Kill the grip process." @@ -94,11 +96,13 @@ (setq grip-port 1088) ;; Delete temp file - (unless (string-equal grip-preview-file buffer-file-name) + (when (and grip-preview-file + (not (string-equal grip-preview-file buffer-file-name))) (delete-file grip-preview-file)))) (defun grip-preview-md () "Render and preview markdown with grip." + (setq grip-preview-file buffer-file-name) (grip-start-process)) (declare-function org-md-export-to-markdown 'ox-md)