Checking unused references #322
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This adds
markdown-unused-refscommand 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 tomarkdown-check-refs. The only difference is that pop-up buffer contains[X]buttons to remove unused references: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-refshelps weed those out.While testing I also noticed that
markdown-get-defined-referencesmay return duplicates for references defined more than once in different case, as in[REF]:and[ref]:. This also looks confusing inmarkdown-insert-linkcompletion and caused issues implementingmarkdown-unused-refs, somarkdown-get-defined-referencesresults are now downcased. This is consistent with whatmarkdown-check-refsreturns and as per https://daringfireball.net/projects/markdown/syntax#link andhttp://spec.commonmark.org/0.28/#matches 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
Checklist
make test).