Generating an Org Link to a Web Page

Recently, I was rereading Vivek Haldar’s post on the seven levels of Emacs proficiency and suddenly realized that I’d regressed in one aspect of my Emacs skills. Haldar says

Up until now, you probably had one large Emacs window plus many other
shell windows spread out on your screen. Also, if you are a typical
developer, you often had to cut and paste text between those windows.
And that was a major road bump, because you had to use the mouse to
select text in an xterm.

I thought I’d long since stopped committing that sin but my epiphany upon rereading Haldar’s post was that I was still guilty of it in one important case: grabbing links to Web pages. Almost all my blog posts link to at least one Web page and often several. I generated those links in exactly the way that Haldar deprecates: change focus to the Web page, cut the URL from the title bar, switch back to Emacs, paste the URL into the Org link. Clearly, I needed a better method; something that would allow me to grab the URL of the currently displayed browser page and turn it into a link in my Org buffer without leaving Emacs.

The org-mac-link package almost does what I needed but it fills in the link description with the Web page title, which was not what I wanted. So I looked at the org-mac-link code and Kris Jenkins’ excellent video on using AppleScript to play Spotify tracks from Emacs and put together a bit of Elisp that does just what I want:

(defun jcs-get-link (link)
  "Retrieve URL from current Safari page and prompt for description.
Insert an Org link at point."
  (interactive "sLink Description: ")
  (let ((result (shell-command-to-string
                 "osascript -e 'tell application \"Safari\" to return URL of document 1'")))
    (insert (format "[[%s][%s]]" (org-trim result) link))))

Of course, this works only on OS X but that’s OK for me because I write all my blog posts on one of my Macs. Doubtless other operating systems have a way to do the same thing1. You could, for example, find a way of doing this in Python and then call Python instead of AppleScript to retrieve the URL. If your main OS is Linux or Windows and this interests you, leave a comment for others if you find a way of doing it in your environment.



A quick check suggests that org-protocol may be a good place to look but I haven’t researched this in any detail.

Posted in Programming | Tagged , | 5 Comments

Bastien Guerry on Org Mode

Here’s a video by Bastien Guerry in which he talks about Emacs and Org Mode. Guerry, of course, is the maintainer of Org Mode and an interesting guy. Here at Irreal, we’ve mentioned him several times.

Guerry begins by demonstrating naked Emacs, his preferred configuration for how Emacs appears on the screen. Afterwards, he talks a bit about the features of Org Mode and the power it provides. If you’re already an experienced Org user, most of this will be familiar; if you’re a n00b or curious about Org, this video will give you a bit of a taste. The video is just under 27 minutes so plan accordingly.

Posted in General | Tagged , | Leave a comment

Formula 1 Communication Technology

I’ve said it before: I’m not a racing fan. And yet, I’ve already written about it twice before and here I go again. This post, like the others, focuses on the technical aspects of the sport.

According to this BBC story, data analysis has become more and more important in a race. The cars have about 150 sensors that provide telemetry on a assortment of measures such as tire pressure, drag, aerodynamic down pressure and many others. It takes a lot of engineers to analyze and interpret this data in real time and relay their findings to the driver.

Unfortunately, the Formula 1 governing body restricts the number of support personnel, including engineers, who can be at trackside to 60. That doesn’t leave enough room for all the engineers needed to work with the data so they moved the analysis back to the factory. This remote analysis necessitates a high speed data link, which turns out to be surprisingly difficult to provide. Communication providers have to set up and tear down facilities at each race site, which are located all over the world.

One provider, Tata Communications uses two teams. One dealing with things at the current race site and the other setting up the next site. Network latency ranges from 7 to 300 milliseconds, depending on distance from the factory. Data rates can sometimes exceed 100 gigabytes a second.

If you enjoy seeing how technology can be brought to bear on problems that don’t seem, at first glance, technological, give the article a read. It’s short and interesting.

Posted in General | Tagged | Leave a comment

Computing the Inner Product with Common Lisp

Over at iqool, Patrick Krusenotto asks how you would compute the inner product of two vectors using Common Lisp. He gives a number of solutions, all of which are interesting. You can look at this problem two ways:

  1. What is the most idiomatic way?
  2. What is the fastest way?

If I were writing a function to do this and speed was not an overriding concern, I would do something like

(defun inner-product (v1 v2)
  (reduce #'+ (mapcar #'* v1 v2)))

and Krusenotto agrees that this is what most Lispers would write.

If I was concerned about speed, I would want to avoid the consing from the mapcar and would do something like

(defun inner-product (v1 v2)
  (let ((sum 0))
    (mapc (lambda (e1 e2) (incf sum (* e1 e2))) v1 v2)

That’s probably fast enough for almost all applications, especially if you add some declares to optimize code generation. There was a solution similar to this in the comments. To tell the truth, though, I might also use a tail recursive loop as in Krusenotto’s solution #2. I do love me some recursive programming.

If I was really concerned about speed, I would probably do something like Krusenotto’s solution #5, which uses an explicit go to speed the loop. With proper declarations, you probably can’t do much better.

It’s fun to think about how you might program simple problems like this. What solution(s) would you use?

Posted in Programming | Tagged , | 1 Comment

TIL: Something New About Ace Jump Mode

Regular readers know that I’ve been a huge fan of ace-jump-mode ever since I saw it demonstrated by Magnor Sveen in one of his celebrated Emacs Rocks! episodes. More recently, I’ve been using it all the time as a replacement for isearch to navigate within a buffer.

Since I started using ace-jump-mode instead of the Yegge approved isearch, my efficiency at jumping around a buffer has been increased significantly. Still, it doesn’t directly address a problem that I often have. When scrolling through a buffer with【Ctrl+v】 or【Meta+v】, I often find myself at the wrong edge of the display—at the top when I want the bottom, or vice versa. I generally solve that problem by picking a word on the desired line and using ace-jump-mode to jump directly to that word. It turns out, though, that ace-jump-mode has me covered for that case too. If I type【Ctrl+u Ctrl+u Hyper+a】 instead of【Hyper+a】, where【Hyper+a】is the sequence I use to invoke ace-jump-mode, each line is marked and I can jump to the desired line by typing the corresponding letter.

One could argue, I suppose, that that’s not any easier than picking a word on the desired line and jumping to that word but it feels more direct and somehow doesn’t take as many of my ever-diminishing brain cycles to invoke. If you aren’t already an ace-jump-mode user, you owe it to yourself to try it out. You’ll be amazed at how much more efficient your navigation becomes.

Posted in General | Tagged | 5 Comments

Org Mode Links

Artur Malabarba has a great post on using Org-mode links to link to anything. It’s a hugely powerful facility that, as Malabarba says, is mostly unknown. Head over to Endless Parentheses for the details.

I wasn’t going to write about this because I didn’t have anything useful to add but decided to mention it in case any Irreal readers missed Malabarba’s post. As I’ve said before, if you aren’t reading Endless Parentheses already, you should start right now. Really.

Posted in General | Tagged , | Leave a comment

John Kitchin on Using Org Mode

I’ve written about John Kitchin and his use of Emacs and org-mode several times (1, 2, 3, 4, 5). Somehow I missed his latest contribution but Sacha Chua had my back and mentioned it in her weekly review.

In his post, What we are using org-mode for, Kitchin recounts how about four years ago he started using Emacs again mainly for its org-mode functionality. His initial idea was to employ Org to manage his obligations—to use it as a GTD application. As he learned more about Org, he began integrating it into more and more of his work.

Kitchin describes how he uses org-mode to write books and papers, develop software in a literate programming way, give presentations, write blog posts, and interact with students about their classwork and assignments in his classes. He remarks that there is hardly any aspect of his work that is not touched by Org. This is an interesting post and definitely worth a read. It’s another example of how you can use Emacs and Org Mode in virtually every aspect of your work flow.

Update: What we using org-mode for → What we are using org-mode for

Posted in General | Tagged , | 5 Comments

Sacha Chats with Harry R. Schwartz

Sacha Chua has posted the latest in her series of Emacs Chats. This time it’s with Harry R. Schwartz. Schwartz is one of the organizers of Emacs NYC, which holds meetings and produces videos of the talks that the participants give. If you live in NYC and are an Emacs aficionado you should check out one of the meetings. If you don’t live in the city, the videos of the talks are available for streaming or download.

As always with Chua’s chats, I learned something useful. I find that I often want to move a line up or down but there’s no built in way of doing that. Schwartz has a couple of simple functions, move-line-up and move-line-down, that do that. You can find their source at GitHub.

The chat is 53 minutes so you’ll want to plan accordingly.

Posted in General | Tagged | Leave a comment

Moving from Scrivener to Org-mode

The estimable Org-mode maintainer Bastien Guerry tweeted a link to an interesting thread on the Org-mode mailing list.

The thread concerned advice for a writer wishing to try Emacs and Org-mode. What I found interesting is that the writer was currently using Scrivener. I’ve written before about my belief that Emacs can do everything Scrivener can. The thread doesn’t address that but it is interesting that some of the commenters moved from Scrivener to Emacs/Org1.

Writers, and everyone else for that matter, should use whatever tools they’re comfortable and productive with but the thread is another piece of evidence that there’s no reason that tool can’t be Emacs.



Not everyone agrees. In this post, Charlie Stross discusses his use of Scrivener and his belief that it’s much better than Org mode. There’s additional discussion of this point in the comments so when you get to the post, search for Scrivener to see everything.

Posted in General | Tagged , | 2 Comments

A Third NSA Leaker?

According to Betteridge’s law the answer should be no but Bruce Schneier isn’t so sure. We’ve heard the speculation about a second leaker responsible for revealing the details of the TAO catalog, X-KEYSTORE rules, and the tapping of Angela Merkel’s cell phone but the latest revelations do not appear to come from either Snowden or the second leaker.

Schneier believes that these latest disclosures represent a separate, third stream of information. If so, perhaps it’s an indication that other insiders are disturbed by what the NSA is doing and taking what steps they can to end it as suggested by Charlie Stross. One can only hope.

Posted in General | Tagged | Leave a comment