New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking unused references #322

wants to merge 13 commits into
base: master


None yet
2 participants

dzhus commented Mar 25, 2018


This adds markdown-unused-refs command bound to C-c C-c u that will find orphaned references which are defined in the document footer but not actually linked to anywhere in the text. This works similarly to markdown-check-refs. The only difference is that pop-up buffer contains [X] buttons to remove unused references:

screen shot 2018-03-25 at 02 13 40

This is useful when maintaining documents with dozens of links. Sometimes I remove a paragraph but the orphaned reference stays in the footer. markdown-unused-refs helps weed those out.

While testing I also noticed that markdown-get-defined-references may return duplicates for references defined more than once in different case, as in [REF]: and [ref]:. This also looks confusing in markdown-insert-link completion and caused issues implementing markdown-unused-refs, so markdown-get-defined-references results are now downcased. This is consistent with what markdown-check-refs returns and as per and link labels are
case-insensitive anyways. I don't think it should cause any issues in properly written Markdown files.

Some minor refactoring too – moved duplicated code to macros.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change which improves an existing feature)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)


  • I have read the document.
  • I have updated the documentation in the file if necessary.
  • I have added an entry to
  • I have added tests to cover my changes.
  • All new and existing tests passed (using make test).

dzhus added some commits Mar 24, 2018

Add markdown-unused-refs
Modeled after markdown-check-refs, it performs the opposite check:
finding references which are defined but not used anywhere in the buffer.
Use defun-markdown-buffer macro
to define

Downcase reference labels in markdown-get-defined-references
As per and link labels are
case-insensitive, so it shouldn't make sense to have



defined in the same document.

By downcasing everything in markdown-get-defined-references we make
sure that such duplicate links don't show up in markdown-insert-link
completion list
Sort results of markdown-get-unused-refs
Apparently cl-set-difference result contains elements in the reverse
order on Emacs 24.x, so we sort the list to by line number for
Use defun-markdown-ref-checker macro
to define


This comment has been minimized.


jrblevin commented May 26, 2018

Thank you, I have often wanted exactly this! I have rebased these commits and pushed them to master.

@jrblevin jrblevin closed this May 26, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment