aboutsummaryrefslogtreecommitdiff
path: root/modules/markdown-config.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-07-02 00:08:33 -0400
committerCraig Jennings <c@cjennings.net>2026-07-02 00:08:33 -0400
commit821ec1e4d5f5e64ed54972960589ca5c8c41b9f9 (patch)
treedad5e9b67a8f059b962d7070f42244f8d095a42f /modules/markdown-config.el
parent622a4d8c13a5037e064cf9caa3e917100f7f5cc9 (diff)
downloaddotemacs-821ec1e4d5f5e64ed54972960589ca5c8c41b9f9.tar.gz
dotemacs-821ec1e4d5f5e64ed54972960589ca5c8c41b9f9.zip
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.
Diffstat (limited to 'modules/markdown-config.el')
-rw-r--r--modules/markdown-config.el18
1 files changed, 12 insertions, 6 deletions
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)