Some spelunking in the ZSH manual last week revealed some real treasures I’ve gotten good use out of already: ESC-" and ESC-'.
ESC-" runs the command escape-region, which you can use to have zsh escape any arbitrary piece of text for you. No more pasting in URLs, file paths, or regular expressions and trying to manually sort out what characters you need to escape–just let the shell do it for you.
Emacs uses the value of the tab-width variable to decide how wide tab characters should be displayed. Setting tab-width is usually one of the first customizations Emacs newbies make:
(setq-default tab-width 2) Displaying tab characters at whatever width you prefer works well for most applications but eventually fails when files mix tab and space characters and (invariably) make assumptions about what the width of those characters will be.
One particularly conspicuous offender is the Emacs (Lisp) source code.
Plasticine smiles and rubescent haircuts
Entheogenic traps of reluctant wake-ups
Candyland costumes and boys wearing make-ups
Buoyed by bouts of relaxed recitation
“Oscillate?” “No, I think ‘vacillation’.”
Gloamingtime breakfasts, forgotten vocations
Approaches of proximal family relations
I suppose what I’d say, if I had to be curt
is—Fucking magnets, how do they work?
I’m a compulsive saver. No, not with money–files. It probably comes from using Photoshop in the 90s, but regardless, I probably save hundreds of times a day.
Sometimes in Emacs I fat-finger C-x C-s (save-buffer) and end up landing in search mode instead (C-s–isearch-forward). Then I have to C-g or ESC ESC ESC my way out before actually saving.
I recently learned (again, from having clumsy fingers) that isearch-mode actually understands C-x C-s, so you can just hit it to save the file and exit search mode in one go.
I’ve been hacking some Clojure code the last couple days and something I’m really coming to love is Clojure’s terse syntax for lambda functions.
The basic form is pretty darn short…
(map (fn [x] (* x x)) [1 2 3]) => (1 4 9) …but we can make that even shorter with this syntax that doesn’t even require us to name the argument:
(map #(* % %) [1 2 3]) => (1 4 9) …or, if we have multiple arguments:
Nerds love Octopress. Nerds love keyboard shortcuts. …need I say more?
@camdez What a delightful plugin, nice work!
— Brandon Mathis (@imathis) March 16, 2012 I added mutt / Gmail-style shortcuts to Octopress and I think it turned out pretty well. Go ahead and try out some of these shortcuts (but be aware that some of them only function within the context of a list of posts–like the homepage):
Key Action j Next article k Previous article j Next article k Previous article ^ First article $ Last article R View full article r Comment on article (“reply”) i Go to the index p Previous page (older articles) n Next page (newer articles) l Scroll to selected article / Search ?
I recently whipped up a command-line utility / Ruby gem called ‘whiteout’ which removes trailing whitespace from files. As you would imagine, it’s a simple piece of code, but it’s a bit more convenient than the shell script I was using. It also gave me a chance to learn how to cut a gem and how to structure a command-line utility in Ruby.
You can use whiteout to remove trailing whitespace from a single file, a directory of files (recursively), or from standard input:
The command transpose-lines, bound to C-x C-t by default, is a standard Emacs workhorse. It exchanges the line point is on with the previous line. Because it also moves point down a line we can invoke it repeatedly to “drag” a line down:
one two two two two two< one three three three three --> three< --> one --> four --> four four four four< one five five five five five< one < This is particularly handy for reordering lists.
Parallel to Ruby’s p and pp methods for quickly printing and pretty-printing, Ruby’s JSON library offers j and jj methods for quickly printing objects in JSON format:
> obj = {"foo"=>"bar", "baz"=>[1, 2, 3]} > p obj {"foo"=>"bar", "baz"=>[1, 2, 3]} > j obj {"foo":"bar","baz":[1,2,3]} > jj obj { "foo": "bar", "baz": [ 1, 2, 3 ] } Definitely handy for investigating those large, deeply-nested objects.
I’ve not actually looked, but the implementation of jj is probably just something like…