Skip to content
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
wants to merge 13 commits into from
Closed

Checking unused references #322

wants to merge 13 commits into from

Conversation

dzhus
Copy link
Contributor

@dzhus dzhus commented Mar 25, 2018

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 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 https://daringfireball.net/projects/markdown/syntax#link and
http://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

  • 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)

Checklist

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

dzhus added 13 commits March 24, 2018 20:20
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
@jrblevin
Copy link
Owner

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants