Repeating a Command

Zachary Kanfer has a nice post on how to repeat a command with a single keystroke. A familiar instance of this is the old-style keyboard macro execution. After defining the macro, you can execute it with 【Ctrl+x e】 and then execute it additional times by simply typing 【e】. Kanfer wants to be able to do this for his own commands.

The trick is to use a transient keymap. Once you use a key in a transient keymap, the keymap goes away so the key will revert to its old meaning. This is a handy trick that’s useful in other circumstances too. For example, here is my code for invoking the ping utility in a full-frame buffer and then restoring the previous window configuration.

 1: (defun net-utils-restore-windows ()
 2:   "Restore windows and clean up after ping."
 3:   (interactive)
 4:   (kill-buffer (current-buffer))
 5:   (jump-to-register :net-utils-fullscreen))
 6: 
 7: (defadvice net-utils-run-program (around net-utils-big-page activate)
 8:   (window-configuration-to-register :net-utils-fullscreen)
 9:   (let ((buf ad-do-it))
10:     (switch-to-buffer buf)
11:     (delete-other-windows)
12:     (set-transient-map
13:       (let ((map (make-sparse-keymap)))
14:         (define-key map (kbd "q") 'net-utils-restore-windows)
15:         map))
16:     (message "Type \"q\" to restore other windows.")))

After the ping operation finishes and we’ve inspected the results, we want to restore the previous window configuration by typing 【q】. As shown on lines 1215, we do that by defining a transient map. After typing 【q】 the transient map disappears and 【q】 reverts to simply being a letter.

Posted in General | Tagged | 7 Comments

On Emacs Being an OS

Katherine Cox-Buday has a lovely 8-tweet long sequence in which she outlines how she uses Emacs to perform a periodic, tedious chore. It’s worth looking at to see if you can get some ideas from it. Here’s the last tweet in the sequence. (Click on the tweet to see the whole sequence.)

What struck me, though, is her remark that “So yes, it is an OS, but that’s a feature!” I’ve always taken that joke to be a comment about Emacs’ editor function not an indictment that you can reasonably compare Emacs to an OS. I’ve also taken it as a given that yes, of course, it’s a feature.

That may be because I yearn for a Lisp Machine and Emacs gives me some semblance of that. On the other hand, how can you not like the fact that Emacs can do so much? What do you think? Is the fact that Emacs is like an OS a bug or a feature? You already know my answer.

UPDATE [2016-09-16 Fri]: also → always.

Posted in General | Tagged | 3 Comments

Capturing Images with Org Mode

Back in January, I came across a post by Arne Babenhauserheide on capturing images into Org. It looked interesting but required Image Magick, which doesn’t play well with OS X1. I thought at the time that it would be pretty easy to adapt but I never got around to it.

Then the other day, I came across this reddit post that pointed to a Stack Overflow post on the same question. That bit of code handles both the Linux and OS X case so I thought I should install it and try it out. But then I saw a comment on the reddit post that pointed to abo-abo’s org-download over on GitHub.

Abo-abo’s code looks like it can be configured to handle Linux, OS X, or windows and it’s available on Melpa. Coming from abo-abo, it’s sure to receive any necessary updates so if you’re looking for a nice utility to grab images and insert them into Org files, you should give it a look.

Footnotes:

1

You have to use the X-server when running it on OS X.

Posted in General | Tagged , | Leave a comment

Abrams on Yasnippet

Howard Abrams over at howardism.org has posted a very nice tutorial on yasnippet. I learned a couple of things I didn’t know so you may find it worth a few minutes too.

First off, I was only dimly aware that you can bring up a template for a new snippet with 【Ctrl+c Ctrl+n】. What’s really nice is that the template is a snippet so you can tab through it filling in the fields like any other snippet. I always have to copy an existing snippet into my buffer to get all the boiler plate. This is a lot easier.

More importantly, Abrams shows us how to use yas-expand-snippet to treat any text as a snippet even if it hasn’t been added to the snippet collection. That may not seem like much but it turns out to be tremendously useful. Abrams gives an interesting use case where he combines auto-insert with yas-expand-snippet to fill in the boiler plate at the top of many programming files.

It’s a good tutorial and well worth taking a look at. It shows some of the power of yasnippet that you may not know about.

Posted in General | Tagged , | 1 Comment

Copying Text with a Mouse in OS X and Emacs

Ben Maughan over at Pragmatic Emacs has a nice tip for those of you using Emacs on OS X. It turns out that it’s easy to copy text to the kill ring with a mouse. I agree with Maughan that it’s not something I want because I try to avoid the mouse when I’m in Emacs but many people feel otherwise.

If you’d like to be able to easily copy text to the kill ring with a mouse, take a look at Maughan’s post to see how easy it is1.

Footnotes:

1

Hint: It’s a single line in your emacs.el.

Posted in General | Tagged | Leave a comment

Refactoring with counsel-ag

Back in January of 2015, I wrote about an excellent post from abo-abo on his refactoring workflow. If you haven’t read his post be sure to take a few minutes to read it. The basic idea was that he wanted to change all occurrences of an identifier in all files in a given directory. He does that by finding each occurrence with rgrep, making the rgrep result buffer writable with wgrep, then using iedit to change all occurrences at once.

Samuel Barreto has a similar workflow that uses counsel-ag. He uses the evil substitution command rather than iedit to make his change but that’s a detail. Take a look at his post for the details. If you’re using ag or looking for a reason to install it, his workflow is very appealing. I wouldn’t be surprised if abo-abo is using it himself now. If you often find yourself making this sort of global change, you really need to check out these workflows.

Posted in General | Tagged | Leave a comment

Put imenu Output in a Buffer

Grant over at Wisdom and Wonder has a short post that points us to imenu-list. That’s a minor mode that puts the output of imenu into a separate buffer where you may find it easier to work with. If you follow the link to imenu-list‘s GitHub page you can see a screen shot of it in action.

Somehow, I’ve never warmed up to imenu but perhaps this will help. You can think of imenu-list as being sort of like occur and use it in a similar way. If you find yourself jumping around a program buffer a lot, you may want to give imenu-list a try.

Posted in General | Tagged | 1 Comment

Calling eww from Dired

If you have files that you read in eww, here’s a suggestion that might make your workflow a bit easier:

Posted in General | Tagged | Leave a comment

Learn Elisp with Xah

Xah Lee is running a one month long Elisp tutorial. Everyday he points you to one of his Elisp pages and then gives a quiz or assignment to test your knowledge of the material. The course has been going on since the end of August but it’s not too late to join in on the fun.

If you’ve been meaning to learn Elisp, here’s an easy way to do it in small chunks of about 20 minutes per day. Lee is available for help if you get stuck so this is an excellent chance to hone your Elisp skills. If you’re an Emacs user, your enjoyment and mastery of Emacs will go up if you learn a bit of Elisp.

Posted in General | Tagged , | Leave a comment

Emacs Configurations for LaTeX

There’s been a lot of tweets and posts on Reddit lately asking about Emacs configurations to support writing \(\TeX\) and \(\LaTeX\). Here’s an example from anasrchid. He asks the typical question: how should I configure Emacs and what packages should I install to give me a pleasant \(\TeX\) environment?

What’s nice about this discussions is that he gets lots of good suggestions and adds an edit that lists a very nice final configuration. Basically, it’s to install

  • AUCTeX
  • RefTeX
  • PDF Tools
  • SyncTeX
  • magic-latex-buffer

If you follow the link to nasseralkmim’s animated gif, you can see this setup in action. It looks pretty nice. You get the power of AUCTeX, nice formatting of symbols in the source buffer, an automatically generated output PDF that reflects your changes as you make them, and easy navigation between the PDF and source buffer. Take a look, I think you’ll be impressed.

Of course, you need to do a bit of configuration as well, but there’s also a link to nasseralkmim’s configuration. It’s an Org file so it’s easy to follow and navigate in. Look at the configuration sections for the above tools to see how he’s got things set up.

If you only occasionally use the full power of \(\LaTeX\), it may be easier to do everything from Org mode but if you write a lot of scientific papers, the suggestions in this post are excellent. Be sure to read the comments too.

Posted in General | Tagged , | 1 Comment