-
Notifications
You must be signed in to change notification settings - Fork 163
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
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Modeled after markdown-check-refs, it performs the opposite check: finding references which are defined but not used anywhere in the buffer.
As per https://daringfireball.net/projects/markdown/syntax#link and http://spec.commonmark.org/0.28/#matches link labels are case-insensitive, so it shouldn't make sense to have [mylink]: http://foo1.bar [MyLink]: http://baz1.foo 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
to define markdown-reference-check-buffer markdown-unused-references-buffer markdown-reference-links-buffer
to define markdown-check-refs markdown-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 consistency
Thank you, I have often wanted exactly this! I have rebased these commits and pushed them to |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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-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 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-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 inmarkdown-insert-link
completion and caused issues implementingmarkdown-unused-refs
, somarkdown-get-defined-references
results are now downcased. This is consistent with whatmarkdown-check-refs
returns 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
).