Skip to content

Commit

Permalink
Make live-preview hook and kill-buffer-hooks buffer-local
Browse files Browse the repository at this point in the history
Take global hooks and make them buffer-local.
markdown-live-preview-remove-on-kill applies to both the Markdown buffers and
the buffers used to preview the export, so it needs to be re-added in two
places, where the export-viewing buffer is created, and when markdown-mode is
turned on.

The test test-markdown-ext/live-preview-exports adequately covers whether
these hooks run.

[jrblevin@sdf.org: Squashed two commits and rebased.
Added GH-63 PR text to commit message for reference.]

Signed-off-by: Jason Blevins <jrblevin@sdf.org>
  • Loading branch information
Danny McClanahan authored and jrblevin committed Jan 5, 2016
1 parent 037ccec commit 002680d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -5313,7 +5313,9 @@ the rendered output."
(let ((output-buffer
(funcall markdown-live-preview-window-function export-file)))
(with-current-buffer output-buffer
(setq markdown-live-preview-source-buffer cur-buf))
(setq markdown-live-preview-source-buffer cur-buf)
(add-hook 'kill-buffer-hook
#'markdown-live-preview-remove-on-kill t t))
(with-current-buffer cur-buf
(setq markdown-live-preview-buffer output-buffer))))
(with-current-buffer cur-buf
Expand Down Expand Up @@ -5912,6 +5914,10 @@ before regenerating font-lock rules for extensions."
(add-hook 'window-configuration-change-hook
'markdown-fontify-buffer-wiki-links t t)

;; add live preview export hook
(add-hook 'after-save-hook #'markdown-live-preview-if-markdown t t)
(add-hook 'kill-buffer-hook #'markdown-live-preview-remove-on-kill t t)

;; do the initial link fontification
(markdown-fontify-buffer-wiki-links))

Expand Down Expand Up @@ -5958,9 +5964,6 @@ before regenerating font-lock rules for extensions."
(markdown-display-buffer-other-window (markdown-live-preview-export))
(markdown-live-preview-remove)))

(add-hook 'after-save-hook #'markdown-live-preview-if-markdown)
(add-hook 'kill-buffer-hook #'markdown-live-preview-remove-on-kill)


(provide 'markdown-mode)
;; Local Variables:
Expand Down

0 comments on commit 002680d

Please sign in to comment.