snosov1 / toc-org

toc-org is an Emacs utility to have an up-to-date table of contents in the org files without exporting (useful primarily for readme files on GitHub)
GNU General Public License v3.0
292 stars 29 forks source link

toc-org-enable to add TOC headline if missing #26

Closed VladimirAlexiev closed 8 years ago

VladimirAlexiev commented 8 years ago

Something for toc-org-enable:

    (setq  ; toc-org puts TOC in the org file, so these conflict
       org-export-with-section-numbers nil
       org-export-with-toc nil)
    ;; add TOC headline if missing
    (unless (org-find-exact-headline-in-buffer "Table of Contents")
      (org-first-headline-recenter)
      (beginning-of-line)
      (insert "* Table of Contents                                 :TOC_5:\n\n"))

Why :TOC_5: not :TOC_2: ? See #27

snosov1 commented 8 years ago

Not sure I understand the problem.

csantosb commented 8 years ago

I think the idea is to auto insert a TOC in none exists.

Personally, I would prefer you let the user customize this package behavior, for example with

(advice-add 'toc-org-insert-toc :before #'toc-org-advice)

You define your own toc-org-advice, as the one above

snosov1 commented 8 years ago

I think the idea is to auto insert a TOC in none exists.

You mean right after opening the file? Or what? I still don't fully understand =)

csantosb commented 8 years ago

Well, when toc-org-insert-toc acts, that's to say, when before-save-hook is called. No need to modify the package to achieve this, in my opinion.

snosov1 commented 8 years ago

Yeah, if you want to generate the TOC right after you open the file, you can use find-file-hook. Not sure it's a good idea, though. Some time ago, this was a default behavior of the mode, but I eliminated that.

csantosb commented 8 years ago

Up to the user to decide ... ! I am using this setup, which fits me.

VladimirAlexiev commented 8 years ago

If this mode depends on a :TOC: heading, I think it should ensure (or at least have an option to do it). But I'm also happy to close this. @csantosb thanks, your code is better, esp :noexport: so I can use the "native" toc:t for html export

snosov1 commented 8 years ago

Ok, let's close it. Thx!