Skip to content

Commit 81e6be8

Browse files
author
Danny McClanahan
committed
make live-preview follow min or max point
1 parent 3e88d58 commit 81e6be8

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

markdown-mode.el

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5872,17 +5872,29 @@ buffer. Inverse of `markdown-live-preview-buffer'.")
58725872
"Get window point and scroll data for all windows displaying BUF if BUF is
58735873
non-nil."
58745874
(when buf
5875-
(mapcar (lambda (win) (list win (window-point win) (window-start win)))
5876-
(get-buffer-window-list buf))))
5875+
(with-current-buffer buf
5876+
(mapcar
5877+
(lambda (win)
5878+
(let* ((pt (window-point win))
5879+
(pt-or-sym (cond ((= pt (point-min)) 'min)
5880+
((= pt (point-max)) 'max)
5881+
(t pt))))
5882+
(list win pt-or-sym (window-start win))))
5883+
(get-buffer-window-list buf)))))
58775884

58785885
(defun markdown-live-preview-window-deserialize (window-posns)
58795886
"Apply window point and scroll data from WINDOW-POSNS, given by
58805887
`markdown-live-preview-window-serialize'."
5881-
(cl-destructuring-bind (win pt start) window-posns
5888+
(cl-destructuring-bind (win pt-or-sym start) window-posns
58825889
(when (window-live-p win)
58835890
(set-window-buffer win markdown-live-preview-buffer)
5884-
(set-window-point win pt)
5885-
(set-window-start win start))))
5891+
(set-window-start win start)
5892+
(let ((actual-pt (cl-case pt-or-sym
5893+
(min (point-min))
5894+
(max (point-max))
5895+
(t pt-or-sym))))
5896+
(with-current-buffer markdown-live-preview-buffer
5897+
(set-window-point win actual-pt))))))
58865898

58875899
(defun markdown-live-preview-export ()
58885900
"Export to XHTML using `markdown-export' and browse the resulting file within

tests/markdown-test.el

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3787,6 +3787,27 @@ Detail: https://github.com/jrblevin/markdown-mode/issues/79"
37873787
(should (file-exists-p file-output)))
37883788
(delete-file file-output)))))
37893789

3790+
(ert-deftest test-markdown-ext/live-preview-follow-min-max ()
3791+
(markdown-test-temp-file "inline.text"
3792+
(markdown-live-preview-mode)
3793+
(should (buffer-live-p markdown-live-preview-buffer))
3794+
(should (window-live-p (get-buffer-window markdown-live-preview-buffer)))
3795+
(with-selected-window (get-buffer-window markdown-live-preview-buffer)
3796+
(goto-char (point-min)))
3797+
(goto-char (point-min))
3798+
(insert "a ")
3799+
(markdown-live-preview-export)
3800+
(let (final-pt)
3801+
(with-selected-window (get-buffer-window markdown-live-preview-buffer)
3802+
(should (= (window-point) 1))
3803+
(setq final-pt (point-max))
3804+
(goto-char (point-max)))
3805+
(goto-char (point-min))
3806+
(insert "this is ")
3807+
(markdown-live-preview-export)
3808+
(with-selected-window (get-buffer-window markdown-live-preview-buffer)
3809+
(should (= (window-point) (+ final-pt (length "this is "))))))))
3810+
37903811
(provide 'markdown-test)
37913812

37923813
;;; markdown-test.el ends here

0 commit comments

Comments
 (0)