Brian's weblog

< April 2011 >
SuMoTuWeThFrSa
      1 2
3 4 5 6 7 8 9
10111213141516
17181920212223
24252627282930
/ (45)
  code/ (1)
  emacs/ (3)
  foolscap/ (1)
  go/ (1)
  hardware/ (2)
  python/ (2)
  security/ (1)
  spam/ (1)
  twisted/ (8)
  version-control/ (1)
  web/ (1)
  weblog/ (6)
Tue, 12 Apr 2011

emacs command of the day

C-x 4 c : clone-indirect-buffer-other-window

I keep learning new tricks in emacs. Today I was studying an overstuffed file, with two large classes, and I needed to navigate around both as I followed the code paths bouncing back and forth between them. I frequently use the "narrow-to-region" command (C-x n n) to temporarily clip the buffer to a single class or method of interest, because then jumping to the beginning/end of the buffer really takes me quickly to the beginning/end of the class, and searching is limited to the class, etc. But this time, I needed to narrow the buffer to two separate regions.

Enter today's interesting command: "clone-indirect-buffer-other-window", reached by C-x 4 c . All the "C-x 4" commands put things in a new window (which means a new region of the current "frame", where each frame gets a new OS-level window). This one makes an "indirect buffer" that's a mirror of the current one, but with a slightly different name (it gets a <2> tacked on to the end). Both buffers are looking at the same time, so any changes you make in one will also appear in the other. But you can narrow each one separately. So I was able to narrow to the first class in the main buffer, and narrow to the second class in the second buffer, and then search/study/explore as if they were two entirely different files. When you're done, just close the second buffer.

posted at: 12:09 | path: /emacs | permanent link to this entry

Wed, 28 May 2008

pastebinit

Another package that appeared in debian today: pastebinit, which is a command-line tool to upload bits of code to some of the various pastebin web servers out there (handy when you want to discuss some code over IRC and don't want to jam the whole thing into the channel.. it is much more polite to put it in a pastebin and then refer to it by URL).

Now what I want is an emacs interface to this, since the code I'd be referring to would always come from one of my emacs buffers anyways.

posted at: 18:34 | path: /emacs | permanent link to this entry

Emacs Trick of the Day

There are a few million gems hidden inside emacs. The two that I ran into most recently are:

C-x r m, C-x r b, C-x r l : these create named bookmarks, each of which records the file that you're visiting and a position within that file. When I need to hold my place while I looked elsewhere, I usually split the window (C-x 2) and leave one of them fixed while I moved around in the other one to find something. Then C-x 0 makes that window go away, leaving me in my original position. But if you do that too deeply, the windows get too small.

C-x r m creates a bookmark, and the name defaults to the name of the file (so if you only use one bookmark per file, you don't even have to type anything). Then C-x r b jumps back to that bookmark. C-x r l lists all your bookmarks.

Bookmarks can also be persistent.

highlight-trailing-space: by setting this to 't', any trailing whitespace will be highlighted in an ugly orange color that makes you want to delete it right away. Darcs does the same thing when you're committing code (it shows you a special "[_$_]" -like symbol to make you aware of the whitespace at then end of the line), so I've been in the habit of deleting that whitespace anyways.. even wrote a little python tool to find it all for me. With highlight-trailing-space turned on, I get to see the whitespace as I'm editing, so I can remove it earlier.

posted at: 18:15 | path: /emacs | permanent link to this entry

Powered by PyBlosxom