Skip to content

Commit

Permalink
check for libxml when trying to use eww
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny McClanahan committed Jan 14, 2016
1 parent 6702e69 commit 048833a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
6 changes: 5 additions & 1 deletion markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -5327,9 +5327,13 @@ buffer. Inverse of `markdown-live-preview-view-buffer'.")
"Status of sync or async live preview in current buffer.")
(make-variable-buffer-local 'markdown-live-preview-current-buffer-sync-async)

(defun markdown-live-preview-has-eww-p ()
(and (require 'eww nil t)
(fboundp 'libxml-parse-html-region)))

(defun markdown-live-preview-window-eww (file)
"A `markdown-live-preview-window-function' for previewing with `eww'."
(if (require 'eww nil t)
(if (markdown-live-preview-has-eww-p)
(progn
(eww-open-file file)
(get-buffer "*eww*"))
Expand Down
31 changes: 22 additions & 9 deletions tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -3290,7 +3290,7 @@ indented the same amount."

(defmacro markdown-temp-eww (&rest body)
`(progn
,@(if (require 'eww nil t) body
,@(if (markdown-live-preview-has-eww-p) body
`((ad-enable-advice #'markdown-live-preview-window-eww
'around 'markdown-create-fake-eww)
(ad-activate #'markdown-live-preview-window-eww)
Expand Down Expand Up @@ -3324,7 +3324,7 @@ indented the same amount."

(ert-deftest test-markdown-ext/live-preview-exports-sync ()
(let ((markdown-live-preview-do-sync t))
(unless (require 'eww nil t)
(unless (markdown-live-preview-has-eww-p)
(should-error (markdown-live-preview-sync-export)))
(markdown-test/live-preview-exports)))

Expand Down Expand Up @@ -3370,13 +3370,27 @@ indented the same amount."
(setq markdown-test-hit-advice t)
(should (eq (selected-window) markdown-test-eww-window)))

(defadvice get-buffer-create (before markdown-set-window-width-mock disable)
(when (let ((buf (ad-get-arg 0))) (and (stringp buf) (string= buf "*eww*")))
(setq markdown-test-hit-advice t)
(should (eq (selected-window) markdown-test-eww-window))))

(defmacro markdown-eww-open-file-advice (&rest body)
`(progn
(ad-enable-advice #'eww-open-file 'before 'markdown-set-window-width)
(ad-activate #'eww-open-file)
,@body
(ad-disable-advice #'eww-open-file 'before 'markdown-set-window-width)
(ad-activate #'eww-open-file)))
(if (markdown-live-preview-has-eww-p)
`(progn
(ad-enable-advice #'eww-open-file 'before 'markdown-set-window-width)
(ad-activate #'eww-open-file)
,@body
(ad-disable-advice #'eww-open-file 'before 'markdown-set-window-width)
(ad-activate #'eww-open-file))
`(progn
(ad-enable-advice #'get-buffer-create 'before
'markdown-set-window-width-mock)
(ad-activate #'get-buffer-create)
,@body
(ad-disable-advice #'get-buffer-create 'before
'markdown-set-window-width-mock)
(ad-activate #'get-buffer-create))))

(defun markdown-test/test-window-size-eww ()
(setq markdown-test-hit-advice nil)
Expand All @@ -3401,7 +3415,6 @@ indented the same amount."
(markdown-live-preview-sync-export)
(markdown-live-preview-async-export))
(markdown-test/live-preview-wait)
(sit-for .1)
;; at this point, `eww-render' should have finished, and eww should
;; have redisplayed. the advice checks that, since there was a
;; single window displaying the *eww* buffer, that window was used
Expand Down

0 comments on commit 048833a

Please sign in to comment.