15

This is a two part question having to do with link rot.

  1. Does org-mode provide any functionality for validating hyperlinks, especially local ones? This could be used to combat link rot after the fact.

  2. Even better, does org provide functionality so that if I rename a file in dired, it will update affected files? This could prevent some kinds of link rot before it happens, at least for local files.

6

For part 1, I didn't find anything built-in. The following function will provide a list of broken links in the minibuffer. I've tested it on some simple examples, but far from exhaustively.

(defun check-bit-rot ()
  "Searches current buffer for file: links, and reports the broken ones."
  (interactive)
  (save-excursion
    (beginning-of-buffer)
    (let (file-links)
      (while (re-search-forward org-bracket-link-analytic-regexp nil t)
        (if (string= "file:" (match-string-no-properties 1))
            (if (not (file-exists-p (match-string-no-properties 3)))
                (setq file-links
                      (cons (match-string-no-properties 0)
                            file-links)))))
      (message
       (concat "Warning: broken links in this file:\n"
               (mapconcat #'identity file-links "\n"))))))
  • 1
    Do you think org-bracket-link-analytic-regexp would help pick apart Org links? Seems like it was created for tasks just like this one. – Constantine Dec 16 '14 at 2:23
  • @Constantine yes, thanks! Didn't know about that one. – Tyler Dec 16 '14 at 2:45
  • Nice. Two possible add-on ideas: (1) add some marking text to bad links to promote discovery via search and/or highlighting; (2) bookmark the bad links. – David J. Dec 16 '14 at 3:08
  • Idea (3) make this into a flycheck checker, and the in-buffer highlighting will be done for you. – Malabarba Dec 16 '14 at 10:16
  • Interesting suggestions. I'll dig into it when time permits over the holiday. – Tyler Dec 17 '14 at 1:52
8

Since Org 9.0 you can run the org-lint function which, among other things, checks for broken local links.

2

I wrote a Python script https://github.com/cashTangoTangoCash/orgFixLinks that attempts to repair broken links to local files, within one or more org files on a local drive in the Ubuntu OS. It is certainly an amateur command line script, but might be worth playing with. There is a GitHub wiki that provides a degree of documentation: https://github.com/cashTangoTangoCash/orgFixLinks/wiki. Please check the warnings in the README.

I'm sorry that this Python script is not a part of Org, but completely separate/stand-alone. I hope no-one is bothered that I am not answering the question of the OP directly; I just thought someone might like playing with the Python script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.