Wednesday, October 15, 2008

Emacs Example Tutorial: insert a block of text

As I explained in my previous Emacs tutorial on killing a block of text, it is sometimes hard to find easy to understand documentation on how to use emacs.
One of the first things I wanted to learn how to do in Emacs was block editing. By "block editing" I mean select a vertical area of text (one or more columns across multiple rows making a square or rectangle - you might call it zero or more since you don't actually have to select any characters, only the spaces between them) and do things to it - you might call it column editing or column mode or "Block Mode Editing" like in Kate, or UltraEdit.

Inserting a column of characters in emacs (without using a mouse) is really easy: you start by highlighting or selecting an area - when you do this you are said to "mark" the region.

You mark a region by positioning your cursor in one corner of the area you want to mark and hitting Control-Spacebar. You will see Emacs respond with the message "Mark set". Then navigate your cursor (I always use the arrow keys, but there is probably other ways to do it) to the opposite corner of the region you want to mark. The "region" is now marked as a rectangle between wherever you started (when you hit Ctrl-Space) and wherever your cursor is now sitting. Note that you don't do anything special to mark the end of the region -- the end is where ever your cursor is positioned.

Emacs calls the space you've now selected the "region-rectangle". Once it's highlighted, you can insert characters into the region by typing:

C-x r t

(That means press x while holding down the control key, release both keys, press and release the r key, press and release the t key). Emacs will respond with the message "String rectangle": it is asking you what text you wish to insert. Type what ever characters (letters) you want to "paste" into the region, and hit enter. It will automatically fill in that same text on every line that you've selected in your region.

I find this to be a great way to comment out areas of code with # characters. Emacs also has a "comment region" command which sometimes works, but occasionally emacs is too smart for it's own good and doesn't know what comment character to use (in which case it will usually ask you which to use with the question "No comment syntax is defined. Use:"), or worse it will use the wrong one.

You can use the comment region function by selecting a region in the same manner descried above, then type:

M-x comment-region

(That means press x while holing down the ALT key, release both keys, type "comment-region" - without the quotes of course - and hit enter).

I find C-x r t easier and faster to use than "M-x comment-region" in most cases anyway. It's fewer letters to type, even when you consider tab completion.

Tuesday, October 7, 2008

Linux on a Dell Vostro 1710 laptop - don't try it [yet]

Recently my company needed a new laptop for one of our employees. After my great success with installing SuSE Linux on a Dell Vostro 1700 laptop, we decided to buy a Dell Vostro 1710, hoping that it would have better, newer hardware and still work with SuSE.

Wrong.

For this first time in my entire 11+ years of using Linux, the installer could not use the trackpad or even the keyboard. Yes, you read that right. I was able to complete the install with an external USB mouse and keyboard, but after the install finished and I rebooted the system without the peripherals (hoping that it was only the installer having trouble), the laptop's built-in keyboard and mouse still wouldn't work. I can't image what Dell has done to prevent detection/use of a simple keyboard.

I never bothered to try the other hardware (camera, etc) - we sent the 1710 back and bought a refurbished 1700.

I strongly suggest nobody buy a 1710 until at least another round of distros has been released this coming winter or spring. It was openSuSE 11.0 that I tried on the 1710 - perhaps 11.1 will work with the 1710, but I'm sure I won't be ordering another one to try it on.

Monday, March 24, 2008

Setting the computer hardware clock (BIOS or CMOS) from inside a running Linux system

Normally after setting the date and time in Linux (for example using the NTP service or ntpdate, you can set the hardware clock to match with the following command:

hwclock --systohc

That way when you reboot, your clock will still be correct (or close to it).

I've discovered that this method does not work on the newer Dells, such as our 1U PowerEdge 1850s. Supposedly this has something to do with the kernel RTC module, and hardware changes. However, the following command appears to set the clock just fine on the problematic Dell servers:

hwclock --systohc --directisa