ardumont / markdown-toc

Generate a TOC in markdown file
GNU General Public License v3.0
127 stars 102 forks source link

markdown-imenu-create-nested-index function definition is void #29

Closed finger563 closed 4 years ago

finger563 commented 8 years ago

Hello,

Please, provide the following information and remove the useless parts. Thanks in advance.

bug?

Yes,

markdown-imenu-create-nested-index, find-library-name are not known to be defined, produce errors when running markdown-toc-generate-toc.

M-x markdown-toc-bug-report

Report back the output from that command here. (You can quote it with ``` for a better readability).

Expected behavior

What command did you use and what were you expecting?

A TOC generated when running markdown-toc-generate-toc

Actual behavior

What really happened?

error, Symbol's function definition is void: markdown-imenu-create-nested-index

Steps to reproduce the behavior

How can we try and reproduce?

Improvments?

What do you want?

Why is it better?

Thanks for sharing!

Cheers,

ardumont commented 8 years ago

Hello,

Can you please:

This is possibly:

Cheers,

anarcat commented 7 years ago

i'm not the original submitter but i am seeing the same issue.

I did this:

System information:

This is using markdown-mode 2.1 from the Debian packages which dates from about february 2016. Upgrading to the snapshot version available in marmalade (20161222.1416) fixes the issue. It would be nice to have a way for the toc plugin to handle this issue more gracefully than just crash - maybe warn the user they are using an old version?

Alternatively, couldn't some backwards-compatibility magic be done to backport that missing code into the plugin itself?

ardumont commented 7 years ago

Hello,

This is using markdown-mode 2.1 from the Debian packages which dates from about february 2016. Upgrading to the snapshot version available in marmalade (20161222.1416) fixes the issue.

Thank you, now i'm able to reproduce the issue (i am running debian as well). (Note that it could also be a more recent from melpa).

I have updated M-x markdown-toc-bug-report to add the library path to markdown-mode, this apparently can help :D

It would be nice to have a way for the toc plugin to handle this issue more gracefully than just crash

Indeed.

maybe warn the user they are using an old version?

Now that i understand it's indeed the case why not. But i'd be more inclined to solve it now.

Alternatively, couldn't some backwards-compatibility magic be done to backport that missing code into the plugin itself?

Mmm, maybe.

This is the commit that introduced the issue for your system version. https://github.com/ardumont/markdown-toc/commit/18e4d7910608ac86a1fa0dfdbca7de2a06ec22cb

For the old version (the one from debian), if you eval this snippet (M-: paste-the-snippet-below RET):

(defun markdown-toc-generate-toc (&optional replace-toc-p)
  "Generate a TOC for markdown file at current point.
Deletes any previous TOC.
If called interactively with prefix arg REPLACE-TOC-P, replaces previous TOC."
  (interactive "P")
  (save-excursion
    (when (markdown-toc--toc-already-present-p)
      ;; when toc already present, remove it
      (let ((region-start (markdown-toc--toc-start))
            (region-end   (markdown-toc--toc-end)))
        (delete-region region-start (1+ region-end))
        (when replace-toc-p
          (goto-char region-start))))
    (->> (markdown-imenu-create-index)
         markdown-toc--compute-toc-structure
         (funcall markdown-toc-user-toc-structure-manipulation-fn)
         markdown-toc--generate-toc
         insert)))

And now trying to generate the toc again, everything should be fine. Am i right? (It's the case for me).

--

Assuming it is. Please, be a little more patient with me, can you please try this snippet again?

(defun markdown-toc-generate-toc (&optional replace-toc-p)
  "Generate a TOC for markdown file at current point.
Deletes any previous TOC.
If called interactively with prefix arg REPLACE-TOC-P, replaces previous TOC."
  (interactive "P")
  (save-excursion
    (when (markdown-toc--toc-already-present-p)
      ;; when toc already present, remove it
      (let ((region-start (markdown-toc--toc-start))
            (region-end   (markdown-toc--toc-end)))
        (delete-region region-start (1+ region-end))
        (when replace-toc-p
          (goto-char region-start))))
    (->> (funcall imenu-create-index-function)
         markdown-toc--compute-toc-structure
         (funcall markdown-toc-user-toc-structure-manipulation-fn)
         markdown-toc--generate-toc
         insert)))

The last snippet should be working as well but with the potential advantage to work with both version... markdown-mode uses a defvar to store the index function to use to generate the index since at least that markdown-mode 2.1 version. So this should be forward/backward compatible (well, depending on your point of view :).

Cheers,

anarcat commented 7 years ago

On 2017-02-27 10:04:06, Antoine R. Dumont wrote:

Hello,

If you eval this snippet (M-: paste-the-snippet-below RET):

(defun markdown-toc-generate-toc (&optional replace-toc-p)
  "Generate a TOC for markdown file at current point.
Deletes any previous TOC.
If called interactively with prefix arg REPLACE-TOC-P, replaces previous TOC."
  (interactive "P")
  (save-excursion
    (when (markdown-toc--toc-already-present-p)
      ;; when toc already present, remove it
      (let ((region-start (markdown-toc--toc-start))
            (region-end   (markdown-toc--toc-end)))
        (delete-region region-start (1+ region-end))
        (when replace-toc-p
          (goto-char region-start))))
    (->> (markdown-imenu-create-index)
         markdown-toc--compute-toc-structure
         (funcall markdown-toc-user-toc-structure-manipulation-fn)
         markdown-toc--generate-toc
         insert)))

And now trying to generate the toc again, everything should be fine. Am i right? (It's the case for me).

Yes, it works.

--

Assuming it is. Please, be a little more patient with me, can you please try this snippet again?

(defun markdown-toc-generate-toc (&optional replace-toc-p)
  "Generate a TOC for markdown file at current point.
Deletes any previous TOC.
If called interactively with prefix arg REPLACE-TOC-P, replaces previous TOC."
  (interactive "P")
  (save-excursion
    (when (markdown-toc--toc-already-present-p)
      ;; when toc already present, remove it
      (let ((region-start (markdown-toc--toc-start))
            (region-end   (markdown-toc--toc-end)))
        (delete-region region-start (1+ region-end))
        (when replace-toc-p
          (goto-char region-start))))
    (->> (funcall imenu-create-index-function)
         markdown-toc--compute-toc-structure
         (funcall markdown-toc-user-toc-structure-manipulation-fn)
         markdown-toc--generate-toc
         insert)))

The last snippet should be working as well but with the potential advantage to work with both version...

It works as well.

markdown-mode uses a defvar to store the index function to use to generate the index since at least that markdown-mode 2.1 version. So this should be forward/backward compatible (well, depending on your point of view :).

Great! Can't wait to see this hit the mirrors. :)

A.

-- Worker bees can leave Even drones can fly away The queeen is their slave