Emacs ansi-term tricks

December 26, 2008 at 11:30 AM | categories: emacs | View Comments

Being on vacation is soo nice. With some of my free time I'm planning on revamping my emacs environment, so hopefully that means a few more articles showing up here on that topic.

I read some great tips on ansi-term. Ansi-term is a terminal emulator written in emacs lisp that is as close to a real terminal as possible. That means you can run virtually all command line programs, even the ones that use ncurses like top or screen, all within emacs. You can still switch between line and char modes which means you can still edit the buffer as you could in a regular (emacs) shell too.

F2 Keybinding

In the above mentioned article Joseph wrote a nice little bit of elisp to get to a running ansi-term efficiently, by hitting F2. The nice thing about it is that it does what I mean:

  1. If I'm already in an ansi-term, but it's called "*ansi-term*" rename it.
  2. If I'm already in an ansi-term, but it's called something else, start a new ansi-term called "*ansi-term*"
  3. If I'm in another non-terminal buffer, switch to a buffer called "*ansi-term*" or create a new one if it doesn't exist

There's one more catch though, as Joseph explains, an ansi-term can be considered "stopped" such that it is no longer running but the buffer still exists. In that case I don't want the third rule to switch me to a defunct terminal, so instead I want it to kill the buffer and create a new ansi-term. Here is my enhanced elisp:

(require 'term)
(defun visit-ansi-term ()
  "If the current buffer is:
     1) a running ansi-term named *ansi-term*, rename it.
     2) a stopped ansi-term, kill it and create a new one.
     3) a non ansi-term, go to an already running ansi-term
        or start a new one while killing a defunt one"
  (let ((is-term (string= "term-mode" major-mode))
        (is-running (term-check-proc (buffer-name)))
        (term-cmd "/bin/bash")
        (anon-term (get-buffer "*ansi-term*")))
    (if is-term
        (if is-running
            (if (string= "*ansi-term*" (buffer-name))
                (call-interactively 'rename-buffer)
              (if anon-term
                  (switch-to-buffer "*ansi-term*")
                (ansi-term term-cmd)))
          (kill-buffer (buffer-name))
          (ansi-term term-cmd))
      (if anon-term
          (if (term-check-proc "*ansi-term*")
              (switch-to-buffer "*ansi-term*")
            (kill-buffer "*ansi-term*")
            (ansi-term term-cmd))
        (ansi-term term-cmd)))))
(global-set-key (kbd "<f2>") 'visit-ansi-term)

TRAMP Integration

This is cool.

Put the following inside of your .bash_profile on any computer that you ssh into frequently:

#Emacs ansi-term directory tracking
# track directory, username, and cwd for remote logons
if [ $TERM = eterm-color ]; then
    function eterm-set-cwd {
        echo -e "\033AnSiTc" $(pwd)
    # set hostname, user, and cwd
    function eterm-reset {
        echo -e "\033AnSiTu" $(whoami)
        echo -e "\033AnSiTc" $(pwd)
        echo -e "\033AnSiTh" $(hostname)
    for temp in cd pushd popd; do
        alias $temp="eterm-set-cwd $temp"
    # set hostname, user, and cwd now

Now when you ssh into a machine from within ansi-term and open a file with C-x C-f you'll be loading a file via TRAMP from the current working directory on the remote machine. Amazingly cool.

Read and Post Comments

Ubuntu: coping with a height restricted display

December 10, 2008 at 01:06 PM | categories: linux | View Comments

I'm eagerly awaiting my new Samsung NC10 to be shipped from Amazon. It's a nice little netbook that I can use when traveling and when going to social occasions. I'm specifically buying this laptop because of its small size, but I know that one thing specifically will bother me: the screen resolution, at 1024x600 is wide enough for most tasks, but not very tall at all.

So while I'm waiting, I'm playing around with Ubuntu 8.10 inside a VirtualBox instance. I've got the window resized to 1024x600 and am playing around with different settings to make maximum use of the screen. Here are my tweaks:

Gnome Panel (the toolbar):

Open gconf-editor (Alt-F2 'gconf-editor') and navigate to apps -> panel -> toplevels -> top_panel_screen0 and change the following:

  • auto_hide: checked -- makes the main toolbar panel autohide
  • auto_hide_size: 0 -- makes the toolbar completely hide instead of leaving a few pixels visible
  • enable_animations: unchecked -- make the hiding/unhiding as fast as possible
  • hide_delay: 500 -- makes the toolbar stay on screen for half a second after using it
  • unhide_delay: 0 -- makes the toolbar immediately popup when your mouse goes to the very top (or bottom) of the screen

Gnome Terminal:

Open the default profile properties, right click in the window and click "Edit Current Profile"

  • Turn off the menu bar: on the General tab uncheck "Show menubar by default in new terminals"
  • Turn off the scrollbar: on the Scrolling tab select "Scrollbar is: Disabled"

Oversized windows:

Uncheck the following key in gconf-editor:


Now you can Alt-left-click any window and drag it around even above the top of the screen.


  • Move the bookmarks bar up to the file menu bar and get rid of the bookmarks bar:
    • Right click on the Home button and click customize.
    • Your bookmarklets should now disappear and read "Bookmarks Toolbar items."
    • Drag "Bookmarks Toolbar items" along the right hand side of the File .. Edit .... Help menus.
    • Click "Done."
    • Right click on the now empty bookmarks toolbar and uncheck "Bookmarks Toolbar."
  • Get rid of the status bar: Go to View -> uncheck "Status Bar."
  • Install a theme that uses smaller buttons and text: I like Classic Compact.
  • Remember that Firefox has a nice fullscreen option : F11.
  • Check out Tree Style Tabs. It puts the tabs vertically on the left side of the browser and visually keeps track of what sites you were at that prompted you to open a new tab, all in a tree like fashion.

Here is the desktop with gnome panel completely hidden and one terminal with menu bar hidden (click to see native size):

Here is firefox maximised with two tabs open (click to see native size):

Here is firefox in fullscreen (click to see native size):

Firefox maximized with Tree Style Tabs:

Read and Post Comments

In Pursuit of the Aggressor

December 05, 2008 at 12:08 PM | categories: free state project, pissed off | View Comments

I've been feeling pretty good lately, I have a decent job, a wonderful wife, awesome friends, and a new-found purpose in life: liberty activism in New Hampshire. In a world as messed up as ours, its been a profound comfort to have found such peace and purpose. But I've also been a bit startled recently including having feelings of helplessness, distrust, and insecurity.

My truck got broken into.

I had just gotten home from work and not 10 minutes transpired before I heard a loud crash and some rustling outside. As I rushed out the door, I saw someone had broken the window of my truck and was diving inside to grab my video camera. Before I knew it, I was several blocks away from my house, running full speed 10 feet behind the guy who was also running like hell. I kept chasing him, never quite closing the gap between him and myself until I ran out of energy. He turned the corner and I followed a bit more slowly. Knowing he was hiding, I looked closely in the darkness for him and I finally saw the guy dash from his hiding spot and continue running away. I said a few more unkind words in his direction as he fled, but there was nothing more for me to do. Out of breath, dejected, and quite frustrated, I walked back home. Kellie was already outside at this point wondering what had happened, we assessed the damage and confirmed that he had destroyed the passenger side window of my truck and managed to steal my video camera.

My Landlord had already called the cops and they showed up about 10 minutes later. Since they were there anyway, I gave them my take on what happened, although I had never really gotten a good look at the guy. I really didn't have much hope that the police would ever do anything (and in an ideal world we wouldn't have such agents of force). Kellie left to do her own reconnaissance at the corner store and surprised me when she told me that she saw the same cops doing actual detective work, questioning the store manager. Although I'm almost sure that these same men have violated the rights of peaceful individuals before, and will most likely continue to do so in their roles as agents of the state, I'm glad that they take their jobs seriously enough to want to protect peace when they can.

I don't really leave anything that valuable in my truck. The camera is a somewhat cheap Samsung SC-MX10, I had it mounted to my dash with a Modifry camera mount (The mount got ripped out with the camera), this setup was supposed to record the cops if I ever got pulled over. Sadly, I never got to try that out. I'm sure that the way I had it mounted made it stand out as an easy target for a thief.

I called up my insurance rep as well as an auto glass shop and got things taken care of pretty quickly, the auto glass shop was even willing to drive out to my house the next day and repair it right there even while I went to work that day. I love how market competition makes this so easy.

In total, I'm out $200 for the camera, $25 for the mount, and $163.15 for the glass. Yea, $388 is kind of a lot. However I was much more irritated with the inconvenience of it all, as well as the knowledge that there are people right in my neighborhood that have no reservations in actively destroying their society. The reason I'm here in NH is to work towards creating a civil and voluntary society. Its one thing to disagree with my ideas, I'm used to that. Its quite another to find that you live in a community where some percentage of the people do the exact opposite; creating a society of violence and distrust.

I'm left with a renewed sense of the importance of security, including responsible firearms ownership and carrying whenever possible. I don't actually think that a gun would have been useful in this situation, especially after the incident was carried onto the open street at 12 mph, but knowing first hand that desperation has led people to such forceful actions, it makes me much more cautious.

Read and Post Comments