2

I have created a workflow where a python script creates urls in org lists on a dayly basis. Thus the links might be created twice or more often. I open the in my web browser by using C-c o. What I would like to see now in the org table is if I already opened the link in the browser before I open it. I would like to have it like it is done in the web browser itself when you already visited a url then the link is purple instead of blue. Can I do this in org mode as well?

3

This is literally possible, but it isn't provided for by Org itself -- you'll have to do it manually. It will be a bit complex; I can tell you where the pieces are, but you'll need to figure out how to implement it yourself. Essentially, you'll need to emulate what a browser does -- you'll need to maintain a local store of already visited links, then supplement the way org does font-locking to selectively color visited links.

This approach has at minimum four pieces: a face; a list; an advice; a font locking function.

A face, in Emacs, is the set of properties that control the style of a thing. You can check the face of a given thing by moving point over it and calling M-x describe-face. (N.B., modes like hl-line-mode will need to be deactivated, or they're the only faces you'll ever see.) You need to either pick an existing face to use for "visited" links, or you need to define your own. Org's default face for links is called org-link.

The list is comparatively simple; all it needs to do is hold all the links you've visited. That's it.

The advice is a little more complex, but still not too bad. If you aren't familiar, "advising" a function in Emacs allows you to modify the behavior of that function in-place. In this case, you need to find the function you've got bound to C-c o (you can do this with C-h k C-c o) and wrap it in an advice. That advice is where you can update your list, place the link being opened in the global store of all opened lists.

The font lock gets harder. Font locking can get to be quite a headache, but the short short version is: Emacs uses pairs of regex-or-function + locking definition in order to fontify a particular piece of text. You can view these pairs by viewing the value of the variable font-lock-keywords. What you need to do, somehow, is add in extra locking that finds links the same way org does, and then conditionally applies the old face or your new face, depending on whether the link is in your list or not. There are... quite a few ways to try and accomplish this, but my main suggestion is to use the function font-lock-add-keywords to simply add your face in. (Effectively, org will fontify the link one way, then your supplemental code will re-font it another way.)

So. Not impossible. Some work. Do note: if you want Emacs to save your links between sessions, you'll want to consider serializing your list somewhere -- write it out at shutdown, reload it at startup. You might be able to most easily do this by defining your list with defcustom and hooking in to the Emacs customization system. However: this will slowly start to drag on Org Mode, as your list to check gets bigger and bigger and bigger. So. Things to think about.

I hope that... if not helps, calibrates things for you.

  • Thanks your idea will be on my list now ;) as it is not a plug and play solution. I will try this when I have time for investigating emacs programming a little. – daeda Apr 29 '18 at 21:19

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.