From 81e6be80512e6fbc5c6375df328887047bf863fd Mon Sep 17 00:00:00 2001 From: Danny McClanahan Date: Mon, 22 Feb 2016 07:43:14 -0600 Subject: [PATCH] make live-preview follow min or max point --- markdown-mode.el | 22 +++++++++++++++++----- tests/markdown-test.el | 21 +++++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/markdown-mode.el b/markdown-mode.el index 22a152dd..60ac0a69 100644 --- a/markdown-mode.el +++ b/markdown-mode.el @@ -5872,17 +5872,29 @@ buffer. Inverse of `markdown-live-preview-buffer'.") "Get window point and scroll data for all windows displaying BUF if BUF is non-nil." (when buf - (mapcar (lambda (win) (list win (window-point win) (window-start win))) - (get-buffer-window-list buf)))) + (with-current-buffer buf + (mapcar + (lambda (win) + (let* ((pt (window-point win)) + (pt-or-sym (cond ((= pt (point-min)) 'min) + ((= pt (point-max)) 'max) + (t pt)))) + (list win pt-or-sym (window-start win)))) + (get-buffer-window-list buf))))) (defun markdown-live-preview-window-deserialize (window-posns) "Apply window point and scroll data from WINDOW-POSNS, given by `markdown-live-preview-window-serialize'." - (cl-destructuring-bind (win pt start) window-posns + (cl-destructuring-bind (win pt-or-sym start) window-posns (when (window-live-p win) (set-window-buffer win markdown-live-preview-buffer) - (set-window-point win pt) - (set-window-start win start)))) + (set-window-start win start) + (let ((actual-pt (cl-case pt-or-sym + (min (point-min)) + (max (point-max)) + (t pt-or-sym)))) + (with-current-buffer markdown-live-preview-buffer + (set-window-point win actual-pt)))))) (defun markdown-live-preview-export () "Export to XHTML using `markdown-export' and browse the resulting file within diff --git a/tests/markdown-test.el b/tests/markdown-test.el index c61127d7..3305b974 100644 --- a/tests/markdown-test.el +++ b/tests/markdown-test.el @@ -3787,6 +3787,27 @@ Detail: https://github.com/jrblevin/markdown-mode/issues/79" (should (file-exists-p file-output))) (delete-file file-output))))) +(ert-deftest test-markdown-ext/live-preview-follow-min-max () + (markdown-test-temp-file "inline.text" + (markdown-live-preview-mode) + (should (buffer-live-p markdown-live-preview-buffer)) + (should (window-live-p (get-buffer-window markdown-live-preview-buffer))) + (with-selected-window (get-buffer-window markdown-live-preview-buffer) + (goto-char (point-min))) + (goto-char (point-min)) + (insert "a ") + (markdown-live-preview-export) + (let (final-pt) + (with-selected-window (get-buffer-window markdown-live-preview-buffer) + (should (= (window-point) 1)) + (setq final-pt (point-max)) + (goto-char (point-max))) + (goto-char (point-min)) + (insert "this is ") + (markdown-live-preview-export) + (with-selected-window (get-buffer-window markdown-live-preview-buffer) + (should (= (window-point) (+ final-pt (length "this is ")))))))) + (provide 'markdown-test) ;;; markdown-test.el ends here