naokazuterada / MarkdownTOC

SublimeText3 plugin which generate a table of contents (TOC) in a markdown document.
https://packagecontrol.io/packages/MarkdownTOC
MIT License
301 stars 48 forks source link

[feature request] Disable on_save hook #126

Closed smanolloff closed 6 years ago

smanolloff commented 6 years ago

Purpose

Allow to disable the on_save TOC update.

How important it is

Just a nuisance.

Ideal implementation

A boolean config value that controls whether the TOC is updated on each save.

naokazuterada commented 6 years ago

Hi, @smanolloff

Thanks for your request. Would you mind to tell me why you want this feature?

smanolloff commented 6 years ago

Hi, thank you for your response. I will be honest: i had a problem with my editor freezing for 3s on every save (markdown context only). I wrongly identified your plugin as the problem, and opened this issue. Turned out the problem was caused by a different package, and I had to either delete this issue, or change it so it is just a feature. I usually dislike stuff triggering at save, because I always panic that l will lose progress, and save like every 30s. If something is triggered on each save, that would be a waste, since I save way too often. But it is just a small nuisance, so I am OK with closing this one 🙂 It's not actually causing me any problems

thezimmee commented 3 years ago

Thank you for this plugin, it's wonderful!!

I'd love this feature as well, being able to toggle the autosave feature. Reason being is there are times I need to make some manual modifications to the TOC, but autosave overwrites those when I do. Also, there are times when I want a link in the TOC to an external document or URL.

naokazuterada commented 3 years ago

@thezimmee

Hi, thank you for your comment.

But sorry..., I can't understood perfectly 💦 The Autolink feature creates a TOC by scanning the entire document each time you save the document. Therefore, it doesn't seem to make sense to toggle this "temporarily". There are If you want to disable this feature, use autolink="false" or make defaults.autolink to false on MarkdownTOC.sublime-settings (Ref). And consider that it's not "temporary" disabling.

Also, there are times when I want a link in the TOC to an external document or URL.

Would you give me more detail? Why does this have anything to do with temporarily disabling the Autolink feature?

thezimmee commented 3 years ago

@naokazuterada Sure no problem, thanks for the follow up.

Here's an example of a workflow I have followed more than once when it comes to markdown TOC:

  1. Select MarkdownTOC: Insert TOC from Sublime menu to insert my table of contents.

  2. Then I need to do some manual modifications to the TOC. For example: I might need to add links to URLs or other markdown pages outside the current markdown file; or I might want to edit the title of a TOC link. For example:

<!-- I might add a link to an outside page like this: -->
-   [My external link](./docs/another-page.md)

<!-- Or I might edit a link title from "My internal link" to "My awesome internal link": -->
-   [My awesome internal link](#my-internal-link)
  1. When I save, however, those types of edits get undone. So what I end up doing is I remove the <!-- MarkdownTOC --> ... <!-- /MarkdownTOC --> comments altogether to disable the autosave feature. Only problem is now every time I need to update the TOC there is a lot of manual work.

Basically I just don't want autosave to overwrite any manual changes/edits I make to the TOC. If there's a simple way to detect my edits and not overwrite them that would obviously be preferable, but I assume it'd be a lot easier to support disabling the autosave feature than it would be to support programmatically detecting user edits that need to not be overwritten 😛 .

Thanks again for the plugin!

naokazuterada commented 3 years ago

@thezimmee

Thank you for describing!

Sorry my suggestion below was not make sense... 🤕

..., use autolink="false"

Please forget about that.

You would want a feature like autosave="false" instead.

My guess is that once you disable the "Autosave" feature, you will never use it again, right? I think that removing <!-- MarkdownTOC --> ... <!-- /MarkdownTOC --> is the best way in your case.

Thanks 😺

thezimmee commented 3 years ago

@naokazuterada I would still like to be able to manually update toc from sublime though, which I can't do by removing the MarkdownTOC comments. A feature like autosave="false" would be valuable for me.

Thank you.

naokazuterada commented 3 years ago

@thezimmee

I'm sorry, but I can't get enough evidence to implement that feature, so far.

Instead, how about a workaround like this? If you subtly change the magic comment, MarkdownTOC loses track of the TOC.

<!-- MarkdownTOC -->

- test

<!-- /MarkdownTOC -->

# test

↓

<!-- !MarkdownTOC -->

- test

<!-- /MarkdownTOC -->

# some changes