4

I have an org file with several dozen links to various webpages. I'd like to view and edit most of the urls in this file. Is there a convenient way to do this?

In other words, does org-mode have a feature that allows me to view and edit all the links in my document in one place?

  • Do you want an automated way (e.g., "each link is something like whatever.com; change it to whatever.com"), or a way to prompt you for the edit to each link, then automatically move to the next link? – zck Sep 21 '15 at 3:20
  • I'm curious if there is a feature in org-mode that allows me to conveniently view all the urls in one place. – Brian Fitzpatrick Sep 21 '15 at 3:24
  • This isn't a solution to your current problem. But it will help you list all the URLs at the end of the documents going forward. I use this approach so that I can review/edit the links as needed easily as they all are present in section of the file. – Kaushal Modi Sep 21 '15 at 3:30
  • @kaushalmodi That looks like a pretty useful way for me to structure documents in the future. – Brian Fitzpatrick Sep 21 '15 at 3:33
9

It's all plain text, so just use a normal search-and-replace.

If org-mode manages to suppress that somehow, just temporarily change the major mode. e.g. M-x fundamental-mode

Edit:

Actually, assuming you're on Emacs 24.1+, occur-edit-mode will be a nice way to do that, as you'll see the plain text link syntax in the occur buffer, and only the lines you're interested in.

  • M-so <regexp> RET (for whatever pattern matches the links you want to edit)
  • Switch to the *Occur* buffer.
  • e (enter occur-edit-mode)
  • Do any editing you need to do. Search and replace, etc. (n.b. You'll need to move point down off the first line of the occur buffer.)
  • C-cC-c (confirm the changes and exit occur-edit-mode)
  • Return to and save the original buffer.

Edit 2:

If you aren't picky about which links you're searching for, you could run a command like this:

(defun my-org-links-occur ()
  "Run `occur' for all `org-mode' links in the current buffer."
  (interactive)
  (occur org-any-link-re))
  • My issue isn't that I can't see the urls, it's mainly that I have a large number of urls in the file and I'd like to view them all in one place so I can parse them. – Brian Fitzpatrick Sep 21 '15 at 3:25
  • 2
    @BrianFitzpatrick You can see the links too if you enable the visible-mode (toggle using M-x visible-mode)... and use this regexp: \[\[.*?\]\[.*?\]\] for the occur. – Kaushal Modi Sep 21 '15 at 4:34
  • 1
    Brian: It looks like you commented just slightly before I added the info on occur. "[viewing] them all in one place" is exactly what occur is for, so I imagine it suits your purposes quite well. – phils Sep 21 '15 at 5:23
  • 2
    You could also use org-occur instead of regular occur (it will preserve more context around links). Also there's org-toggle-link-display to toggle between how Org links are displayed. – wvxvw Sep 21 '15 at 6:20

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.