5 Indispensable Tips for Emacs on Windows

    Emacs is generally not very popular on Windows based operating systems. The default installation of Emacs leaves you with a very spartan UI and a very basic editor. However, due to Emacs' extendibility, you can create a very powerful editor by customizing your .emacs file and making some OS specific tweaks. We will be concentrating on the latter as there are plenty of .emacs files floating around for your reference.

    I have 5 simple yet useful tips below, which I have tested with a GNU Emacs 23.0.0.1 (i386-mingw-nt5.1.2600) running on Windows XP.

    Tip 1: Starting off With a Prettier Emacs

    Most of us customize the fonts, colours and window position of Emacs. In fact, I have found that dark backgrounds are much suited to Emacs than the default light background. However, when Emacs starts up, it annoyingly shows the default fonts and colours first. As your .emacs files load, it jumps around and changes colours quite noticeably.

    You can avoid this annoyance by making a simple registry modification. Create a new .reg file say set-frame-and-fonts.reg and copy paste the following lines. Open the file to add the changes to the registry. Restart Emacs and enjoy the difference!

    REGEDIT4
    [HKEY_CURRENT_USER\SOFTWARE\GNU\Emacs]
    "Emacs.Foreground"="black"
    "Emacs.Background"="#f5f5f5"
    "Emacs.Font"="-outline-Consolas-normal-r-normal-normal-12-90-96-96-c-*-iso8859-1"
    "Emacs.Geometry"="100x35+0+0"
    

    Caveat: The lines above are my preferred colours, fonts and window positions. Your’s could be different. Please customize to your taste.

    Tip #2: Add “Open In Emacs” option to all Files

    This will be indispensable once you are more used to Emacs. You will feel like opening anything and everything with it. And being the one true swiss-army-chainsaw it is, you will be delighted at the enormous no: of filetypes that Emacs supports out of the box.

    This .reg file add an “Open in Emacs” option in Windows Explorer when you right click on any file. Copy the following lines to a .reg file say Add-Emacs-To-Open-Any-File.reg and open it to add the changes to the registry. Make sure that you have modified the path below to point to your emacs installation path (mine is in D: drive). The emacsclientw.exe resides in the same place where your runemacs.exe resides (right-clicking on the emacs icon, generally shows you this).

    Windows Registry Editor Version 5.00
     [HKEY_CLASSES_ROOT\*\Shell\Open In Emacs\Command]
    @="\"D:\\Program Files\\Emacs23\\bin\\emacsclientw.exe\" -a \"D:\\Program Files\\Emacs23\\bin\\runemacs.exe\" \"%1\""
    

    Tip #3: Goodbye Capslock

    If you use Emacs a lot, you will find that you have to use the Ctrl key a lot. You might find your left thumb getting strained after prolonged use. The easiest solution for this is to reassign a less used key as the Ctrl key. Most people choose the Caps Lock key for this purpose. It is surprisingly not that much useful and soon you will forget that such a key ever existed.

    Whenever I searched, I found that most people swap the Ctrl and Caps Lock keys. However, this is irritating as I might still want to use the old Ctrl key if I press it accidentally. Here is how to replace Caps Lock with the Ctrl Key.

    Copy the following lines to a .reg file say replace_caps.reg and open it to add the changes to the registry. Now just reboot and you are done!

    REGEDIT4
    
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
    "Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00
    

    Yes, it takes some time to “unlearn” and “learn” the new key position, but trust me it’s worth the effort.

    Tip #4: Use a Spell Checker

    A spell checker is something I feel should be a part of any editor. Here is how to enable on the fly spell checking in Emacs.

    1. Install aspell
    2. Add the following lines to your .emacs file (adjust the path to aspell accordingly)

    Elisp:

    ;; aspell is the spell checker that works for me
    (setq-default ispell-program-name "D:\\Arun\\Home\\bin\\aspell.exe")
    (setq text-mode-hook '(lambda()
                             (flyspell-mode t)       ; spellchek (sic) on the fly
                             ))
    

    Tip #5: Setup a Postscript Printer

    By default, you can pretty-print all your documents directly from emacs. But this requires configuring a postscript printer. There is a nice package called Ghostscript which takes care of doing this.

    1. Download and install Ghostscript from here say at D:\gs

    2. Download and install GSView from here say at D:\gs\gsview

    3. Then add the following lines to your .emacs file:

    Elisp:

    
    (if (string= system-name "CORPLAPTP65") ; Works in office only
        (progn
          ;;  Windows printer
          (setq-default ps-lpr-command (expand-file-name "/gs/gsview/gsprint.exe"))
          (setq-default ps-printer-name t)
          (setq-default ps-printer-name-option nil)
          (setq ps-lpr-switches '("-query")) ; show printer dialog
          (setq ps-right-header '("/pagenumberstring load" ps-time-stamp-mon-dd-yyyy))))
    

    Caveat: Be sure to switch to a light background color scheme before you print, else your fonts will be so light that they won’t be readable!

    Comments →

    V-day Special

    Here is a belated valentine’s day greeting from both of us.

    This photo is a macro taken by Arun

    For all my readers, I recommend visiting the microsite I had made earlier. Now it is written entirely in web.py. Thanks to my new website host, A Small Orange, I can create and host python based applications. I agree that there is no need to design a new blog in python again, but it is a great way to learn a new (anti-) framework. Web.py applications are really small and easy to understand and therefore, has less bugs.

    Guess what, Jeff Atwood owns an ASUS laptop model (W3J) that is similar to mine (F3J). He is full of praise about the decision. Considering I took at least 2 months (the standard duration for yours truly to zero into an buying decision) to arrive at the decision, it seems well worth now :).

    Comments →

    Gamepad Brings New Life to Emulated Games

    I use a fairly powerful laptop at home. It’s not exactly a gaming laptop but it has a pretty powerful gaming card (ATI X1600) and uses dual core (Duo T2300E) processor. In short its a great machine to play classic Sega/Nintendo games of yesteryears' through emulators. Increasingly I have been concerned about the life of my laptop keyboard which I have found, unlike the desktop keyboards, could be quite easily jammed (especially if your 10 year old cousin is banging on Enter key yelling ‘MAAARREYO’).

    Somehow I had this intuition that a gamepad-like input device can solve this problem. After a couple of minutes of googling I found that my guess was correct. I could find that it is easily available in cities like Mumbai/Bangalore and it is quite cheap too. But I was not sure if I can get in in Mangalore so I searched the usual places and a few unusual places like gadget.in. I had the following criteria for my gamepad (or joypad or game controller as it is called in some places):

    • Must have the basic set of buttons for playing Nintendo and Sega games
    • Must have a joystick. This is the basic advantage of gamepads over keyboard+mouse
    • Must be cheap so that I can probably buy more if I need to host a mini game party Plus, it must have decent looks

    The prices range from Rs. 450 (Chinese make incl. Shipping) to Rs. 1100 (Logitech Dual action) online. I also read accounts of people who went for Logitech and lost their calibration in a few months and accounts of people who have been using cheap gamepad for the last 3 years.

    Finally, I could get a decent gamepad with vibrations and dual joysticks from Mangalore (Saibeen Complex, Lalbagh) itself for Rs. 350. It is a Chinese model called PU850 and is autodetected by XP when plugged into the USB port (though it comes with a mini CD with drivers). It has all the features I wanted. As regards to looks, decide for yourself ;)

    My Gamepad closeup

    My Gamepad with Pandora

    Don’t they go well with each other :D? I have played only a few games with it so this is a quick review but here is what I found:

    • It is small and light for my hands alleast. It is fully powered by the usb (no batteries)
    • Almost all emulators detected it out of the box
    • Sega Genesis games work well with the joystick in Analog mode. I use the 4 shoulder buttons and right joystick in most cases.
    • Nintendo Gameboy games work well with the left D-pad or HAT switches. It seems to be over-reacting to the joystick. Could be an emulator problem though. I found it more easier to hold it tilted forward when playing these games.

    All in all, it has been a good value for money. I can now literally sit back and play my game collection with much better controls and stop worrying about my Pandora.

    Comments →

    Happy Organised 2008

    The first New Year after marriage is always special. It will be a lot quieter (and sober?) than one’s earlier outings. In Mangalore, most of the discs were either overcrowded (Zero Degrees?) or charging like hell (GoldFinch?). So we decided to go to Palki and have a nice buffet at the rooftop. What we didn’t know was that it offered an amazingly close view of the fireworks in the surrounding area. It was a great way to start the new year.

    Beginnings

    Speaking of starts, for most of us January 1st is like a reset button. Or at least we wish it is. Here comes an opportunity to cut down on that chocolate addition or make a habit of paying bills on time. They go by the ominous term ‘Resolutions’. For me, a self described procrastinator, I had to bring to speed my time planning tools to the brand new 2008. In case you are wondering, they are:

    I printed out my Pocketmod from the website directly. I was using version 2 for the first time and loved the idea of being able to customize the front page with my details. You can have print your name and address printed rather than typing it each time.

    Sorry! couldn't get a photo for 2008

    I’ve been reconverted to emacs from Notepad++, after seeing the very useful Org mode. Once again I have spent many, many hours cutomising the my .emacs file. When it comes to emacs the word customising is really misleading, it should be actually called reprogramming ;)

    My Current Emacs Screen

    Actually, this time I have added some very neat features like TextMate-like snippet expansion upon pressing TAB, personal menu, windows Postscript printer support (Emacs prepares gorgeous printouts of code). They are very useful and I hope I will be able to blog about them soon. In fact, this post was written in Emacs using a markdown mode

    So for all my readers out there here is wishing you and happy, prosperous and well-planned New Year!

    Comments →

    Work Faster in Windows With Launchy and a few Python Scripts

    Eating the Mouse

    Launchy is a great productivity tool and a cool way to impress your friends. You can launch any application by pressing a hotkey (say Alt+Space) and the first few letters of the application for eg: typing ‘gi’ will display the GIMP icon and pressing Enter will launch GIMP. You can download Launchy from its website and its beta is pretty stable (and gorgeous) on my XP laptop too.

    Using Launchy gets pretty addictive and soon you will hate using the Start menu or even Explorer on Windows for opening applications or files. So I took the red pill and started automating the following things with a little help from Python:

    • Launching Intranet applications inside Internet Explorer (even if Firefox is your default browser)
    • Bringing minimized or overlapped windows to the foreground

    Some Necessary Evil

    Don’t get me wrong, I hate IE as much as you do. But the fact of life is that many web apps out there “Work best when viewed in IE” (TM). Even if you have launchy plugins to launch the web app, if your default browser is Firefox, it might show incorrectly. Here is the solution:

    1. Install Python and Pywin32
    2. Copy the following script to the Utilities directory (it will be in the path where you installed Launchy) and save it with a .pyw extension not a .py extension

    ie.pyw:

    
    from win32com.client import Dispatch
    ie = Dispatch("InternetExplorer.Application")
    ie.Visible = True
    ie.Navigate(r"http://intranetapp/home")
    

    In the above code replace the URL http://intranetapp/home with the URL of your choice.

    Finally, open Launchy, right-click and say ‘Rebuild Index’.

    No more Alt-Tabbing around

    If you are like me, you’ll have a lot of windows open at the same time. I have tried increasing the task bar height and grouping similar windows feature in XP to manage them. But I always wish I could invoke commonly used open applications like my chat window in just a few keystrokes. Launchy doesn’t index open programs by default, but with some python magic I can show you how to bring some commonly used windows to the foreground:

    1. As before, install Python and Pywin32
    2. Copy the following script to the Utilities directory (it will be in the path where you installed Launchy) and save it with a .pyw extension not a .py extension

    windowfore.pyw:

    
    import sys
    from win32gui import GetWindowText, EnumWindows, ShowWindow, SetForegroundWindow
    from win32con import SW_RESTORE, SW_SHOW
    
    TITLE_MATCH = "Microsoft Excel - Expenses.xls"
    
    def listWindowsHandles():
        res = []
        def callback(hwnd, arg):
            res.append(hwnd)
        EnumWindows(callback, 0)
        return res
    
    def listWindowsNamesAndHnd():
        return [(hwnd, GetWindowText(hwnd)) for hwnd in listWindowsHandles()]
    
    def unminimizeWindow(a_hwnd):
        ShowWindow(a_hwnd, SW_RESTORE)
        SetForegroundWindow(a_hwnd)
    
    def finder1():
        for hwnd, title in listWindowsNamesAndHnd():
            if TITLE_MATCH in title:
                unminimizeWindow(hwnd)
    
    finder1()
    

    In the above code change the string Microsoft Excel - Expenses.xls with the title the window you would like to summon.

    Finally, open Launchy, right-click and say ‘Rebuild Index’.

    This works even if the window was minimized.

    I hope, finally you can throw your mouse away. Ah… What a bliss!

    Comments →

    « Newer Page 22 of 39 Older »