seagle0128 / grip-mode

Instant Github-flavored Markdown/Org preview using grip
GNU General Public License v3.0
269 stars 6 forks source link

wrong port while using org-mode #21

Closed krescent closed 1 year ago

krescent commented 2 years ago

macOS 11.6.1, with Emacs 27.2.

When using grip-mode with markdown, everything work smooth and fine.

While using org-mode, the browser will start the preview correctly in opening. After that, each time I press C-x C-s to save the change, it will open another web page with a new random port, but the connection is failed.

The saved content could be checked by manually refreshing the page, which is created when the org file open.

seagle0128 commented 2 years ago

I tested on my macbook, and it works well. I don't understand what's your problem.

krescent commented 2 years ago

Thank you for your contribution to open source. =)

Let me elaborate the problem:

Under markdown mode

Time 0: emacs open .md file, browser opened a page, let say in port 10000.

Time 1: edit .md file, don't need to save, browser refresh the updated content automatically in page with port 10000.

Under org-mode

Time 0: Emacs open .org file, browser opened a page, let say in port 10000.

Time 1: edit .org file, and save, browser opened a new page, with port 20000.

seagle0128 commented 2 years ago

No. The port won't be changed unless the grip process is restarted.

krescent commented 2 years ago

Yes, the back end port that serve for org is still the port 10000, but the problem is, each time I press C-x C-s to save org file, it will open a new tab with different port number.

Also an interesting phenomenon I did see is, while I try to open an org file, the browser page will show server unavailable for one second, and then display the content.

seagle0128 commented 2 years ago

I think you should figure out why a new tab will be displayed while saving the org buffers. Can you reproduce the issue with emacs -Q?

Also an interesting phenomenon I did see is, while I try to open an org file, the browser page will show server unavailable for one second, and then display the content.

It's as expected since grip process may not be started completely at that moment.

krescent commented 2 years ago

With -Q, the browser doesn't even start when I load markdown/org file.

seagle0128 commented 2 years ago

With -Q, you also need to load the necessary packages, like grip-mode, markdown, etc.

flora-sun-zhixin commented 2 years ago

I encountered the same issue using hooks, and after I set my init file to

   (use-package grip-mode
     :ensure t
     :after (:any org markdown-mode)
     :bind ("C-c g" . grip-mode) ;; Make a keybinding: `C-c g'
     :init
     (setq grip-binary-path "/Library/Frameworks/Python.framework/Versions/3.7/bin/grip")) ;; I add this just because I have multiple grip

The issue fades away. I experimented a bit, seems that if I use the bind key instead of the hook, the update will be in the same tab for both markdown and org file. Hope this helps.

(Actually I like the bind key better, cuz for reveal and my init.org, I do not really want to preview them.)

flora-sun-zhixin commented 2 years ago

@seagle0128 Also may I ask what you mean that

ox-gfm is optional.

in README? How could I combine ox-gfm with this?(sorry I am green in emacs) You seems already used

org-gfm-export-to-markdown

in your code? Is that already something from ox-gfm?

seagle0128 commented 2 years ago

@FloraSun9101 You can install ox-gfm in your init.el file and use org-gfm-export-to-markdown.

My configuration is here: https://github.com/seagle0128/.emacs.d/blob/master/lisp/init-org.el#L171.

flora-sun-zhixin commented 2 years ago

@seagle0128 Thanks for the fast reply! The way you organized the emacs config is neat!

I do not think ox-gfm makes any difference to grip-mode: I just set up ox-gfm and rendered the file via org-gfm-export-to-markdown. Then I compared the markdown file rendered during grip-mode preview and the markdown file rendered from org-gfm-export-to-markdown using diff at terminal, they are pretty much the same except the generated hyperlink ID. Then I commented out the ox-gfm set up and restart emacs. Compared the markdown generated from grip-mode and the org-gfm-export-to-markdown result(somehow it still runs), and they are still the same. Then I compared grip-mode generated markdown with\without ox-gfm, they are still the same.

My setup for ox-gfm basing your config file:

   (use-package ox-gfm
     :ensure t
     :defer t
     :init
     (add-to-list 'org-export-backends 'md)
     (with-eval-after-load 'counsel
       (bind-key [remap org-set-tags-command] #'counsel-org-tag org-mode-map)))
seagle0128 commented 2 years ago

@FloraSun9101 You should check org-export-to-file. The backend is different (md vs gfm) although you don't feel any difference in your cases.