Skip to content

Commit

Permalink
make live-preview follow min or max point
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny McClanahan committed Feb 22, 2016
1 parent 3e88d58 commit 81e6be8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
22 changes: 17 additions & 5 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 81e6be8

Please sign in to comment.