From 821ec1e4d5f5e64ed54972960589ca5c8c41b9f9 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Thu, 2 Jul 2026 00:08:33 -0400 Subject: feat(markdown): start the preview server from F2 when it's down cj/markdown-preview now brings up the simple-httpd listener itself instead of signaling a user-error pointing at cj/markdown-preview-server-start. The two-command flow guarded against a surprise network listener, but the preview is the only reason the listener exists, so the guard was just an extra step. I kept the start command for manual use. --- modules/markdown-config.el | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'modules/markdown-config.el') diff --git a/modules/markdown-config.el b/modules/markdown-config.el index cb37556f..d2cd7f86 100644 --- a/modules/markdown-config.el +++ b/modules/markdown-config.el @@ -40,6 +40,8 @@ ;;;; --------------------- WIP: Markdown-Preview --------------------- (declare-function imp--notify-clients "impatient-mode") +(declare-function httpd-running-p "simple-httpd") +(declare-function httpd-start "simple-httpd") (defun cj/markdown-preview-server-start () "Start the simple-httpd listener that serves the live markdown preview. @@ -49,16 +51,20 @@ Idempotent: re-running while the server is already up is a no-op." (httpd-start) (message "markdown preview server running on http://localhost:8080/imp")) +(defun cj/--markdown-preview-ensure-server () + "Start the markdown preview server unless it's already running." + (require 'simple-httpd) + (unless (httpd-running-p) + (cj/markdown-preview-server-start))) + ;; the filter to apply to markdown before impatient-mode pushes it to the server (defun cj/markdown-preview () "Open the current buffer as a live HTML preview at http://localhost:8080/imp. -The simple-httpd listener must already be running -- see -`cj/markdown-preview-server-start'. Starting a network listener as a -side effect of opening a preview is surprising, so the server start -lives in a separate command." +Starts the simple-httpd listener itself when it isn't already running +\(per the 2026-07-01 decision; the earlier separate-start design +signaled a `user-error' instead)." (interactive) - (unless (httpd-running-p) - (user-error "markdown preview server not running; run `M-x cj/markdown-preview-server-start' first")) + (cj/--markdown-preview-ensure-server) (impatient-mode 1) (setq imp-user-filter #'cj/markdown-html) (cl-incf imp-last-state) -- cgit v1.2.3