aboutsummaryrefslogtreecommitdiff
path: root/modules/markdown-config.el
diff options
context:
space:
mode:
Diffstat (limited to 'modules/markdown-config.el')
-rw-r--r--modules/markdown-config.el19
1 files changed, 15 insertions, 4 deletions
diff --git a/modules/markdown-config.el b/modules/markdown-config.el
index d2cd7f86..1d4a8b74 100644
--- a/modules/markdown-config.el
+++ b/modules/markdown-config.el
@@ -60,9 +60,7 @@ Idempotent: re-running while the server is already up is a no-op."
;; 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.
-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)."
+Starts the simple-httpd listener automatically when it isn't already running."
(interactive)
(cj/--markdown-preview-ensure-server)
(impatient-mode 1)
@@ -110,8 +108,21 @@ signaled a `user-error' instead)."
;; stub doesn't collide with this file's own definition of the command
;; (that collision is the "defined multiple times" byte-compile warning).
;; Same key as compile, for consistency.
+(defun cj/markdown-toggle-view ()
+ "Toggle the current Markdown buffer between edit and read-only view.
+Handles the gfm variants too. The cond checks the most-derived mode
+first, since the view modes derive from their edit modes."
+ (interactive)
+ (cond
+ ((derived-mode-p 'markdown-view-mode) (markdown-mode))
+ ((derived-mode-p 'gfm-view-mode) (gfm-mode))
+ ((derived-mode-p 'gfm-mode) (gfm-view-mode))
+ ((derived-mode-p 'markdown-mode) (markdown-view-mode))))
+
(with-eval-after-load 'markdown-mode
- (keymap-set markdown-mode-map "<f2>" #'cj/markdown-preview))
+ (keymap-set markdown-mode-map "<f2>" #'cj/markdown-preview)
+ (keymap-set markdown-mode-map "C-c C-x v" #'cj/markdown-toggle-view)
+ (keymap-set markdown-view-mode-map "C-c C-x v" #'cj/markdown-toggle-view))
(provide 'markdown-config)
;;; markdown-config.el ends here