Recursive Input to query-replace

The other day I needed to change all occurrences of a certain Unicode character with another in a large file. No problem, I thought, I’ll just fire off a query-replace and be done. Of course, now I had to enter those two Unicode characters to the query-replace prompt. My usual way of entering Unicode characters is with 【Ctrl+x 8】 but that didn’t work because I was already in the minibuffer. Grrrr.

After a moments thought I brought up the *scratch* buffer, put the two characters in it with my usual 【Ctrl+x 8】 procedure, loaded the characters into a couple of registers, and used the registers to give the characters to query-replace. Even granting that needing to do this is a rare occurrence, that was a singularly terrible solution.

In my shame, I started thinking of better ways to do it. The first thing I realized was that the registers were silly (I had just been using a register for something else and they were on my mind). Instead, I could have merely copied the two characters into the kill ring with 【Meta+w】 and then used 【Ctrl+y】 and 【Meta+y】 to give them to query-replace. Still not a good solution but better than the nonsense with registers.

Finally, I remembered my previous post on making the minibuffer recursive. When I wrote about that I set enable-recursive-minibuffers to t but because I didn’t use it in my day to day work I never added it to my init.el. Too bad. Once I re-enabled the recursive minibuffer processing I was able to do what I wanted in the first place: fire off query-replace and then enter the characters with 【Ctrl+x 8】. The very next thing I did was to add it to my init.el.

Again, entering Unicode characters in the minibuffer is not something I do very often but when I need it, this is a great solution. Does anyone know of a better solution?

Posted in General | Tagged | 4 Comments

Securing WordPress Sites

WordPress.tv has an interesting video by Chris Wiegman of bit51 entitled Securing WordPress is Easier Than Making Coffee. If you have a WordPress site this is worth an hour of your time. He begins by showing how a seemingly trivial plugin can open you up to an easy exploit requiring no more than Chrome. Wiegman says that the core of WordPress is actually pretty secure but that poorly written themes and plugins can make you vulnerable.

I particularly liked the section about tools. Wiegman discusses several tools that you can use to check your site, back it up, and harden it against exploits. Many of these are free so even the casual blogger can afford to be protected.

Again, there’s a lot of useful information in the video and it’s worth watching.

Posted in General | Tagged , | 1 Comment

Remapping the Caps Lock Key

Read any article on optimizing your workflow with Emacs and odds are the first recommendation is to remap 【caps lock】 to 【Ctrl】. For as long as I can remember, the first thing I’ve done when setting up a new machine is to remap the caps lock key. I did this long before I started using Emacs—not because I was worried about RSI issues but because I was tired of hitting 【caps lock】 instead of 【Tab】 and getting a bunch of unwanted capital letters in my text. For me, the remapping was simply a way of turning off the caps lock function. (Why are they still putting that key on the keyboard, anyway?)

Recently I decided to try actually using 【caps lock】 as 【Ctrl】. It hasn’t been easy. After years of bending my pinkie down to the standard 【Ctrl】 key, it felt unnatural to use 【caps lock】 instead. After a few weeks, I’m finally getting used to it and except for occasionally mixing up 【Shift】 and 【caps lock】, I’ve pretty much retrained my muscle memory.

Actually, I’ve discovered that having two control keys is handy. For most key sequences modified with 【Ctrl】, I used the 【caps lock】 key but when the sequence is modified by both 【Ctrl】 and 【Meta】 (such as 【Ctrl+Meta+f】 to move forward by a sexr) it’s convenient to use the standard 【Ctrl】 key.

If you’ve remapped 【caps lock】, what was your experience? Did you have a hard time getting used to it or did it seem natural to you right away? My difficulties may be the result of using the standard 【Ctrl】 key for so long. In any event, I’d be interested in hearing about other people’s experiences.

Posted in General | Tagged | 13 Comments

More on Setting the Emacs Frame Height

I got some really great comments to my Setting An Emacs Per-System Height post. If you are interested in automatically sizing your Emacs frames you should definitely take a look at them. Not all the suggestions are OS X specific so there’s good information no matter what platform you are using.

Unlike many people, I like to keep all my Emacs configuration in a single (init.el) file. Even so, I really liked this suggestion from Mark Hepburn: keep your system-specific and platform-specific configurations in separate files. So I put the configuration specific to my laptop, manfred, in a separate file (manfred.el) and similarly for aineko. Then I inserted

(load (car (split-string (system-name) "\\.")) t) ; load adds suffix

into my init.el to automatically load the system-specific configurations.

Similarly, rather than having commands such as

(when (macp)
  (setq ping-program-options '("-c" "4")))

scattered throughout my init.el, I put all those configurations into darwin.el and added

(load (symbol-name system-type) t)

to my init.el file.

This has the advantage of being easier to manage. Rather than constantly updating init.el to account for new systems or platforms, I need only add a <system>.el file and perhaps a <platform>.el file to a new machine. So far, I’m considering this an experiment but it feels right to me.

Posted in General | Tagged | Leave a comment

Turning Off Native OS X Scrolling for Emacs

One of the minor annoyances of Emacs on the Mac is that it’s easy to inadvertently scroll an Emacs window even if Emacs doesn’t have focus. Usually this happens when I’m working in a browser or in Reeder and I use the trackpad to try to scroll the display but the cursor is sitting on an Emacs window. I tried turning off the scroll bar but the window would still scroll if the cursor was in it.

The other day I was looking through Magnar Sveen’s emacs.d and discovered the answer. All you need do is add

(mouse-wheel-mode -1)

to your .emacs or init.el file.

As I say, it’s a minor thing but if you too are bothered by it, now you know what to do.

Posted in General | Tagged | Leave a comment

Setting An Emacs Per-System Height

Every time I start Emacs I have to adjust the frame size. That’s because my two main systems are a 15 inch MacBook Pro and a 27 inch iMac. In both cases I want the width to be 80 cols so I just set that with set-frame-width in my init.el file. I always ended up setting the height though because the MacBook can handle only 53 rows while the iMac can do 87. I finally got tired of that and added a bit of code to check the system name and set the height appropriately. I’m not even sure this is the best way of handling the problem but it’s simple and works. Here’s the code for anyone else who has a similar problem

(defconst jcs-system-heights '(("aineko" . 87) ("manfred" . 53)))
(let* ((system (car (split-string (system-name) "\\.")))
       (height (assoc system jcs-system-heights)))
  (when height
      (set-frame-height (selected-frame) (cdr height))))

Once you have the system name, you can make any other system-specific adjustments you need. If this init.el is used for another system (such as one of my servers), height will be nil and no action will be taken. If you are using Linux, you can probably get the same effect by setting the X-defaults; I couldn’t find a way of doing this for OS X.

Posted in General | Tagged | 8 Comments

Xah Lee on Crypto

Xah Lee has a nice digest (heh!) of the various cryptography algorithms used on the Web. It’s not a detailed technical picture—there are plenty of those available—but, rather, a short explanation of each of the major algorithms and how they fit into the Web security infrastructure.

This post does not cover HTTPS, SSH, or SSL/TLS but Lee is promising to cover those in a subsequent article. If you’re confused by crypto jargon and are looking for an explanation of what the terms mean and what role they play, you may find this article useful.

Posted in General | Tagged | Leave a comment

Storing Passwords Securely 2

A few days ago, I wrote about the Stormpath Video on how to secure passwords. Now Stormpath has published a blog post that covers the same material. This is good stuff and if you’re working on a site that handles users’ passwords, you need to know this material.

Both the video and blog post give a very accessible introduction on how to handle passwords. If your idea is just to throw them into a database as plain text or to run them through MD-5 and then throw them into a database, you need to study this material. Otherwise, sooner or later, you will have your users’ information compromised. It’s really not that hard—you just need to know what to do. Stormpath is doing everyone a service by telling you the proper steps. Read them already.

Posted in General | Tagged | Leave a comment

Finding Command Suffixes

After my post on How To Really Quit, I scanned through the Emacs section of Brian Zwahr’s Dev and Such blog. He’s got a ton of good Emacs tips there (many from his previous Blog Emacs Journey, which he’s merged with Dev and Such). You really should head on over and take a look if you’re not already familiar Dev and Such.

I don’t want to reblog everything he’s already said but here’s a tip so useful I am going to reblog it to make sure it gets as wide an exposure as possible. I often have a hard time remembering all the, say, register commands. I know they all start with 【Ctrl+x r】 but I find it hard to remember the suffix of the various commands or sometimes even what commands are available. Zwahr’s tip is to type the prefix and then 【Ctrl+h】 to get a list of the commands.

Oddly, the example he gives is exactly the one I always have the most difficulty with: the register commands. Suppose I want to save the point to a register but I can’t remember the exact command. I just type 【Ctrl+x r】 and then 【Ctrl+h】 to get a list of all the commands that start with 【Ctrl+x r】. Since I learned that trick I’ve used it several times. Very very nice!

Posted in General | Tagged | 1 Comment

Emacs Net Utilities

I came across a post by mulander over at My Opera about his journey to Emacs. I found it interesting because it closely paralleled my experience: a long time Vim user moves to Emacs to get Slime. When I did that, I just jumped in and switched to Emacs cold turkey. Mulander, however, started using it “part-time” for specific tasks such as Slime and SQL-oracle mode. Over time he kept discovering new ways to make his work flow more efficient with Emacs. His post has a list of some of the applications that he replaced with Emacs. Be sure to take a look; it’s a worthwhile read.

One of the things I learned about from mulander’s post was the Emacs net utilities. This includes support for (the diagnostic output of) network utility programs such as ping, traceroute, netstat, nslookup, dig, arp, ifconfig and route. It also has native support for finger and whois as well as the ability to connect to a given HOST/PORT. I really love this. I often find myself wanting to ping some other host, check my network configuration with ifconfig, or run a whois. My normal way of doing this is to bring up a terminal and enter the appropriate command. Now I don’t even have to leave Emacs. If I want to check if I’m connected to the outside world, I just type 【Meta+xping and then some external site when prompted1.

The only Emacs documentation I could find for the network utilities is the net-utils.el file. I asked Google and found this nice post from Mickey. Again, I really like this functionality. It’s one more reason to never leave Emacs while I’m working. You can probably find everything you need from Mickey’s post so be sure to take a look at it.

Footnotes:

1 If your system keeps pinging until stopped you will want to set ping-program-options to send only a few pings. You can do that with the configuration facility or by adding

(setq ping-program-options '("-c" "4"))

to your .emacs or init.el file.

Posted in General | Tagged | 2 Comments