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
286 stars 29 forks source link

batch mode doesn't work with repeated headlines #43

Closed JAremko closed 7 years ago

JAremko commented 7 years ago

If I run toc-org-insert-toc normally (from Emacs) I'll get

* Table of Contents                                         :TOC_4_gh:noexport:
- [[#description][Description]]
- [[#layer-installation][Layer Installation]]
  - [[#layer][Layer]]
  - [[#choosing-a-backend][Choosing a backend]]
- [[#backends][Backends]]
  - [[#meghanada][Meghanada]]
    - [[#installation][Installation]]
    - [[#about-maven][About Maven]]
  - [[#eclim][Eclim]]
    - [[#installation-1][Installation]]
      - [[#eclipse][Eclipse]]
      - [[#eclim-1][Eclim]]
    - [[#configuration][Configuration]]
    - [[#usage][Usage]]
  - [[#ensime][ENSIME]]
    - [[#installation-2][Installation]]
    - [[#configuration-1][Configuration]]
    - [[#usage-1][Usage]]
    - [[#issues][Issues]]
- [[#key-bindings][Key bindings]]
  - [[#meghanada-1][Meghanada]]
    - [[#server][Server]]
    - [[#navigation][Navigation]]
    - [[#compilation][Compilation]]
    - [[#tests-junit][Tests (junit)]]
    - [[#refactoring][Refactoring]]
    - [[#tasks][Tasks]]
  - [[#eclim-2][Eclim]]
    - [[#java-mode][Java-mode]]
      - [[#project-management][Project management]]
      - [[#eclim-daemon][Eclim daemon]]
      - [[#maven][Maven]]
      - [[#goto][Goto]]
      - [[#refactoring-1][Refactoring]]
      - [[#documentation-find][Documentation, Find]]
      - [[#errors-problems][Errors (problems)]]
      - [[#tests][Tests]]
    - [[#errors-problems-buffer][Errors (problems) buffer]]
    - [[#projects-buffer][Projects buffer]]
  - [[#ensime-key-bindings][Ensime key bindings]]
    - [[#search][Search]]
    - [[#sbt][sbt]]
    - [[#typecheck][Typecheck]]
    - [[#debug][Debug]]
    - [[#errors][Errors]]
    - [[#goto-1][Goto]]
    - [[#print-and-yank-types][Print and yank types]]
    - [[#documentation-inspect][Documentation, Inspect]]
    - [[#server-1][Server]]
    - [[#refactoring-2][Refactoring]]
    - [[#tests-1][Tests]]
    - [[#repl][REPL]]

https://gist.github.com/JAremko/acc95c9efbe2cd3d68773bbb9aa624df

But if I do something like this:

emacs --batch -l toc-org.el --file README.org --eval "(progn (toc-org-insert-toc) (save-buffer))"

I'll get that:

* Table of Contents                                         :TOC_4_gh:noexport:
- [[#description][Description]]
- [[#layer-installation][Layer Installation]]
  - [[#layer][Layer]]
  - [[#choosing-a-backend][Choosing a backend]]
- [[#backends][Backends]]
  - [[#meghanada][Meghanada]]
    - [[#installation][Installation]]
    - [[#about-maven][About Maven]]
  - [[#eclim][Eclim]]
    - [[#installation][Installation]]
      - [[#eclipse][Eclipse]]
      - [[#eclim][Eclim]]
    - [[#configuration][Configuration]]
    - [[#usage][Usage]]
  - [[#ensime][ENSIME]]
    - [[#installation][Installation]]
    - [[#configuration][Configuration]]
    - [[#usage][Usage]]
    - [[#issues][Issues]]
- [[#key-bindings][Key bindings]]
  - [[#meghanada][Meghanada]]
    - [[#server][Server]]
    - [[#navigation][Navigation]]
    - [[#compilation][Compilation]]
    - [[#tests-junit][Tests (junit)]]
    - [[#refactoring][Refactoring]]
    - [[#tasks][Tasks]]
  - [[#eclim][Eclim]]
    - [[#java-mode][Java-mode]]
      - [[#project-management][Project management]]
      - [[#eclim-daemon][Eclim daemon]]
      - [[#maven][Maven]]
      - [[#goto][Goto]]
      - [[#refactoring][Refactoring]]
      - [[#documentation-find][Documentation, Find]]
      - [[#errors-problems][Errors (problems)]]
      - [[#tests][Tests]]
    - [[#errors-problems-buffer][Errors (problems) buffer]]
    - [[#projects-buffer][Projects buffer]]
  - [[#ensime-key-bindings][Ensime key bindings]]
    - [[#search][Search]]
    - [[#sbt][sbt]]
    - [[#typecheck][Typecheck]]
    - [[#debug][Debug]]
    - [[#errors][Errors]]
    - [[#goto][Goto]]
    - [[#print-and-yank-types][Print and yank types]]
    - [[#documentation-inspect][Documentation, Inspect]]
    - [[#server][Server]]
    - [[#refactoring][Refactoring]]
    - [[#tests][Tests]]
    - [[#repl][REPL]]

https://gist.github.com/JAremko/3a098fa1ee439cd1e9df31ea4dd7c24d


diff https://www.diffchecker.com/BYfFinYe

JAremko commented 7 years ago

I tried it with Emacs25 and snapshot

I think it happens because Emacs in "normal mode" loads different org-mode version

snosov1 commented 7 years ago

Hey!

Not really. The mode actually uses a state variable that tracks headings and their "hrefified" versions (both for adding suffices (like, -1, -2, etc) and C-c C-o jumping). So, you need to call toc-org-enable prior to toc-org-insert-toc. Try emacs --batch -l toc-org.el --file README.org --eval "(progn (toc-org-enable) (toc-org-insert-toc) (save-buffer))"

JAremko commented 7 years ago

@snosov1 thx!

snosov1 commented 7 years ago

:+1: