Skip to content

Commit df66315

Browse files
committed
tweak(+browse-html-file): create a temporary file for non-file visiting buffers
1 parent 678f6a8 commit df66315

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

core/me-lib-extra.el

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,17 @@ use `browse-url'.
455455
456456
When called with universal argument, open the current buffer's file."
457457
(interactive (list (if current-prefix-arg (buffer-file-name) (read-file-name "HTML file to open: "))))
458-
(let ((url (format "file://%s" (expand-file-name file)))
459-
(browse-backend (or (cl-find-if #'fboundp +browse-html-file-browser-priority)
460-
#'browse-url)))
458+
(let* ((file (or file
459+
;; Non file-visiging buffer, make a temporary file
460+
(let ((buf-content (buffer-substring-no-properties (point-min) (point-max))))
461+
(with-temp-buffer
462+
(set-visited-file-name (make-temp-file "browse-html-" nil ".html"))
463+
(insert buf-content)
464+
(save-buffer)
465+
(buffer-file-name)))))
466+
(url (format "file://%s" (expand-file-name file)))
467+
(browse-backend (or (cl-find-if #'fboundp +browse-html-file-browser-priority)
468+
#'browse-url)))
461469
(funcall browse-backend url)))
462470

463471

0 commit comments

Comments
 (0)