Maintaining the System Clipboard Over an Emacs Kill

Ben Maughan has a nice tip for Clipboard/Emacs Kill Ring interaction. In recent versions of Emacs at least, you can yank the value of the system clipboard as long as nothing has been put in the kill ring since the time that the value in the clipboard was set. That works well and I often use it to copy some text from, say, a Web page and then yank it into an Emacs buffer.

The problem is that if you kill something in Emacs in the meantime, the clipboard value is lost because it’s not actually added to the kill ring. Maughan gives us a one-line fix that causes the clipboard to be pushed onto the kill ring if necessary. That means that you can still retrieve it even if there’s an intervening kill. That’s really handy. I often copy text from the browser, return to Emacs, do some editing that involves a kill, and then end up having to copy the text from the browser again. With this fix, it’s still in the kill ring and retrievable. Very nice. I wish I’d known about this sooner.

Posted in General | Tagged | Leave a comment

Exporting JavaScript from a Babel Source Block

One of the nice things about Org mode is that “You’ll never have to write HTML again.” That’s not quite true, of course, but it mostly is. Just write in Org markdown, including tables, and then export it to HTML all from the comfort of Emacs. That’s how Irreal gets published everyday.

If you know a bit about writing non-trivial Web pages, you may want to embed some JavaScript in the final HTML. I do this all the time when I embed a tweet in a post. When I tell Twitter that I want to embed a tweet, it gives me the code (surrounded by <script>, </script>) that I include in the post by simply putting it between #+BEGIN_EXPORT HTML and #+END_EXPORT tags in my Org source. That’s easy because Twitter provides all the code I need.

But what if you want to add your own JavaScript? That’s pretty easy too. You just type <h Tab to get the export tags and then Ctrl+' to be put in a buffer where you can write your JavaScript. That’s fine but there are a couple of problems. First the editing buffer you get put in is in HTML mode not JavaScript mode so you don’t get the syntax highlighting and the other benefits of JavaScript mode. Secondly you have to add all the <script>, </script> boilerplate by hand. Finally, it’s not how you embed source for other languages in an Org document so it’s a special case.

Over at the Emacs reddit, oantolin provides a really nice fix for this. With just a few lines of Elisp he adds JavaScript to the languages that Babel knows about. Now when you want to embed some JavaScript, you just put it in a Babel source block as you would with any other supported language. When you type Ctrl+' you get put in JavaScript mode and the boilerplate will be inserted for you when you execute the block.

What’s really amazing about all this is how easy it is; take a look and see. I hope the Org folks add this to the code base so it will be available without adding the Elisp to your init.el. Even if they don’t, it’s such a minimal amount of code that it’s not much of a burden to add it yourself.

Posted in General | Tagged , | Leave a comment

Loyalty Cards

In yet another case of the Iron Law of Data Collection, we have this example from Seattle. For the last four years, King County Animal Services has been sending notices to residents who have unlicensed pets that they must license those pets or face a $250 fine. But how did they know who had unlicensed pets?

It turns out they gathered data from supermarket loyalty cards—those cards that the cashiers are always asking if you have so they can offer you a discount—to see who was buying pet food and then cross referenced that with pet license data. Last year the county brought in $100,000 of new licenses this way.

Once again, we see data that was collected for an ostensibly benign reason being used for unintended purposes in a privacy violating way. There are no terrorists here, no pedophiles, no drugs, just dogs. While you can make a case that ensuring pets are properly vaccinated serves a public good, it’s the most mundane of public goods and one that certainly doesn’t rise to a level that requires the government to spy on what citizens are buying at the grocery store.

Sadly, most residents aren’t that concerned. They agree it’s pretty creepy but just shrug it away. One resident, in a charming bit of naivety said, “I just don’t get that concerned. Now if they were looking at my bank records and all sorts of more personal stuff than my dog, then maybe I might be.” Why on earth would you think that a government that spies on what you’re purchasing for pet enforcement reasons isn’t looking at your other data for more “serious” violations?

In any event, you shouldn’t be using those cards. Their whole purpose is to spy on your purchasing habits. That’s nominally for the benefit of the supermarket but as we see here, the data can be co-opted by the government for its own use. In my experience the cashiers usually have a card that they will swipe for you anyway so you won’t even lose out on any benefits from the program.

Posted in General | Tagged | 1 Comment

Org 9 Links

John Kitchin has a very nice post and video demonstrating some of the new link features in Org Mode 9. It’s now easy to create custom link types and control the display, look, and action of the resulting links. You can, for example, choose the color you want for the link or what gets displayed in the tool tip, even making it dynamic.

As an example, Kitchin demonstrates a better file link that asks you what you want to do when you follow it. You can, for example, open it as usual, open it in Dired, copy the path, or any other action that makes sense.

A link’s look and action are controlled by a set of properties, which can be individually set for each link type. Here’s a list of the properties cut from org.el.

:follow - A function that takes the link path as an argument.

:export - A function that takes the link path, description and
export-backend as arguments.

:store - A function responsible for storing the link.  See the
function `org-store-link-functions'.

:complete - A function that inserts a link with completion.  The
function takes one optional prefix arg.

:face - A face for the link, or a function that returns a face.
The function takes one argument which is the link path.  The
default face is `org-link'.

:mouse-face - The mouse-face. The default is `highlight'.

:display - `full' will not fold the link in descriptive
display.  Default is `org-link'.

:help-echo - A string or function that takes (window object position)
as arguments and returns a string.

:keymap - A keymap that is active on the link.  The default is
`org-mouse-map'.

:htmlize-link - A function for the htmlize-link.  Defaults
to (list :uri \"type:path\")

:activate-func - A function to run at the end of font-lock
activation.  The function must accept (link-start link-end path bracketp)

There isn’t very much documentation on how to use this new facility so Kitchin’s post is really useful if you want to take advantage of link properties. Have a look at Kitchin’s video to get an idea of what’s possible. It’s 10 minutes long so it won’t be hard to schedule some time to watch.

Posted in General | Tagged , | Leave a comment

Org 9.0

Org Mode version 9.0 has been released and is ready for update. Take a look at the Changes file to see what’s new. I’ve had it installed for less than an hour as I write this so it’s a little too early to draw any conclusions.

The only issue I’ve had to deal with is the new Export block syntax. That’s explained near the top of the Change file and basically involves writing things like

#+BEGIN_EXPORT html

#+END_EXPORT

instead of

#+BEGIN_HTML

#+END_HTML

The shortcuts (<h Tab in this case) will give you the proper syntax so you need worry only about fixing up old files that you want to export. Happily, the Change file includes a bit of Elisp that will do that for you. I just pasted it into my init.el file for the time being so that I can easily fix any files I need to. That would mostly be old blog posts that I want to post an update to but there are a couple of others that I’ll need to fix the next time I export them.

There are a few other non-backward compatible changes but they probably won’t affect many people. Be sure to look at beginning (at least) of the Changes file to make sure you aren’t affected.

Many thanks to Bastien and the other developers for all their hard work. Org keeps getting better and better and I wouldn’t be nearly as productive without it.

Posted in General | Tagged , | Leave a comment

Zamansky 18: Narrowing and iedit

Mike Zamansky has his latest video up. This time it’s on iedit and narrowing. For narrowing, he uses Artur Malabarba’s narrow-or-widen-dwim package. I love this package and you should definitely be using it too. It makes narrowing really easy and you don’t have to remember all the different key sequences associated with the narrowing commands. It’s a real win.

The other half of the video is about iedit. This command lets you edit every instance of a symbol—or more generally, any sequence of characters—at the same time. Zamansky’s video is an excellent demonstration of its functionality. If you’d like to see it used in a real-world example, take a look at this post from abo-abo that I wrote about previously. If you haven’t seen it before, it will astound you.

One problem with iedit is that it works on an entire buffer, which sometimes includes too much. That’s where narrowing comes in. You can narrow to a region or function, say, and have iedit act on just the narrowed portion of the buffer. Again, Zamansky gives a nice demonstration of this.

This is an excellent video and only nine and a half minutes long so it’s easy to schedule time to watch it. If you aren’t familiar with iedit or narrowing, you can consider it a must see.

Posted in General | Tagged | 1 Comment

The EOS Org Mode Configuration

Yesterday, I wrote about Lee Hinman’s EOS Emacs configuration and mentioned that because the configuration is factored into modules, it’s easy to adapt them to our own configurations. An example of this is Hinman’s Org Mode configuration. It’s a treasure trove of configuration items that I didn’t know about but that can be very useful.

One example, that I immediately implemented, is the org-special-ctrl-a/e variable. By setting that to t, Ctrl+a and Ctrl+e will ignore stars and tags when moving to the beginning and end of a header line. A subsequent Ctrl+a or Ctrl+e will move to the absolute beginning or end of the line.

There are several other similar useful configurations and if, like me, you do a great deal of your work in Org mode, you’ll want to implement some of them yourself. In general, if you’re an Org user—and you should be—you should definitely take a look at Hinman’s configuration. As I say, it’s full of good ideas.

Posted in General | Tagged , | Leave a comment

Living in Emacs

As you know, I’m fond of the notion of living in Emacs to the greatest extent possible. For me, that’s an ongoing process much like a Japanese garden: a process that is always seeking perfection but that is never complete. Others, like Lee Hinman, have made better progress.

Hinman calls his Emacs configuration EOS, The Emacs Operating System. It’s a thing of beauty. He has modules for nearly every component of his workflow—even most of his Web browsing. Those modules are written in Org mode with lots of explanatory text to help you understand what’s going on.

The module setup is nice because it allows you to choose the parts that support your workflow while ignoring the rest. If you’re not a Twitter user, for example, you can just ignore that module. Most people probably won’t want to use EOS out of the box but its module structure and internal documentation make it easy to adapt. If you have a minimal configuration, a good strategy would be to clone EOS, make the changes that are sensible for your workflow, and then install it. If you already have an extensive configuration, Hinman’s configuration will serve as a model for rationalizing your configuration’s structure and as a source of ideas for additions to your configuration.

Even if you aren’t interested in moving your life into Emacs, Hinman’s configuration is worth looking at for the many ideas you can mine from it. It’s an excellent resource.

UPDATE [2016-11-01 Tue 11:08]: Forgot to mention that I found the EOS link from this tweet by Arne Babenhauserheide

Posted in General | Tagged | Leave a comment

Overlays

Xah Lee has an interesting post on overlays. Overlays are not something that a user needs to worry about; they are a means of altering the display of certain areas of a buffer and are therefore a concern only for the Elisp coder. A common example is Magnar Sveen’s excellent multiple-cursors package. It makes use of overlays to show the multiple cursors and altered highlighting.

Lee’s example shows how to temporarily display certain lines in a buffer with a bold face but the real value of his post is that it serves as a nice introduction to working with overlays. If you’re an Elisp coder and haven’t worked with overlays, take a look at his post. It will serve to get you going.

Posted in General | Tagged | Leave a comment

Dennis Ritchie Day

Tim O’Reilly declared today, October 30, as Dennis Ritchie Day. That was five years ago but nonetheless we should all pause and consider how much Ritchie affects our life and work. He was a giant and we should give thanks that he spent some time with us.

Posted in General | Tagged | Leave a comment