This is not an issue.
It's more of a thank you and a rudimentary emacs usage as I found this extension much more helpfull than using pandoc with emacs markdown mode on *nix like systems. I use this on Ubuntu 20.04.3 LTS and GNU Emacs 26.3.
Feel free to comment or just close this issue as you see fit.
To use this gh extension with emacs:
- insert into the
.emacs file (or equivalent):
(defun md_preview ()
"start /usr/bin/gh markdown-preview -p PORT <current buffer file>"
(let (PORT BFN BFN_PORT)
(setq PORT (read-string "PORT: " nil nil "3333"))
(setq BFN (buffer-file-name))
(setq BFN_PORT (concat BFN ":" PORT))
(start-process "gh_markdown_preview" BFN_PORT "/usr/bin/gh" "markdown-preview" "-p" PORT BFN)))
(global-set-key [(control ?x) (p)] 'md_preview)
- restart emacs and open a couple of markdown files.
- to preview a buffer with a markdown file by using a web browser and the url
http://localhost:3333: in emacs "C-x p" RET (to use the default port 3333)
- to preview a second buffer with a different markdown file in a web browser and the url
http://localhost:3334: in emacs "C-x p" 3334 RET (or any port that isn't in use such as 3333 in this example)
- the lisp code above will put output from the gh markdown-preview instances into separate buffers named like
/path/to/different-markdown-file.md:3334, etc. in emacs
- close the
/path/to/markdown-file.md:3333 emacs buffer to exit the preview processes on port 3333 (and free the port)
This emacs implementation has shortcomings:
A. The user must keep track of what port is open and available for use
B. I'm not sure if this is the best solution if one is editing several hundred md files. I only edit a handful so I suspect it will work just fine for that.
C. While I've used emacs for some time, the above is a first attempt at coding lisp. It works for me but there are likely many more shortcomings than A & B above. Treat this a place to start, not an end point.
and thanks again - it's really handy.
EDITs - the original code posted didn't work. The code above does, is a bit simpler, and perhaps makes it easier to keep track of what markdown file is being displayed on what port.