From 0c53ded3dcf513a8f082148c89364563850642ec Mon Sep 17 00:00:00 2001 From: Igor Shymko Date: Thu, 23 Oct 2014 02:14:12 +0300 Subject: [PATCH] preview window is scrolling according to cursor position in markdown buffer --- markdown-preview-mode.el | 39 +++++++++++++++++++++++++-------------- preview.html | 7 +++++++ 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/markdown-preview-mode.el b/markdown-preview-mode.el index 95abdb7..25e8cc0 100644 --- a/markdown-preview-mode.el +++ b/markdown-preview-mode.el @@ -95,20 +95,31 @@ (mdpm:sent-preview-to mdpm:local-client)) (defun mdpm:sent-preview-to (websocket) - (when markdown-preview-mode - (markdown markdown-output-buffer-name)) - (with-current-buffer (get-buffer markdown-output-buffer-name) - (websocket-send-text websocket - (concat - "
" - "" - markdown-preview-style - "" - "
" - (buffer-substring-no-properties (point-min) (point-max)) - "
" - "
") - ))) + (let ((mark-position-percent + (number-to-string + (truncate + (* 100 + (/ + (float (line-number-at-pos)) + (count-lines (point-min) (point-max)))))))) + + (when markdown-preview-mode + (markdown markdown-output-buffer-name)) + (with-current-buffer (get-buffer markdown-output-buffer-name) + (websocket-send-text websocket + (concat + "
" + "" + markdown-preview-style + "" + "" + mark-position-percent + "" + "
" + (buffer-substring-no-properties (point-min) (point-max)) + "
" + "
") + )))) (defun mdpm:start () (mdpm:start-websocket-server) diff --git a/preview.html b/preview.html index b2af54b..0a0e29f 100644 --- a/preview.html +++ b/preview.html @@ -5,6 +5,11 @@ Markdown preview +