Sunday, March 8, 2009

Emacs Example Tutorial: exit emacs and save a file or discard changes

For those who are just starting to learn emacs, the key command sequence to save a file is:

Ctrl x s

That means hold down the Control key, tap the x key once, and the s key once, let go of Control key. If you're used to using "Cntl+s" in a graphical progam to save file, this key binding might seem a little awkward at first but you'll get used to it quickly.

You can also choose whether or not to save by simply exiting emacs and telling it "y" for "yes" or "n" for "no" when it asks you if you want to save your changes (also known as "Exit saving changes") by typing the "quit" key command sequence:

Ctrl x c

Emacs will then prompt you "Save file /path/to/filename? (y, n, !, ., q, C-r or C-h)" which means you must answer with one of the options listed inthe parenthesis. To save just tap the "y" key and you're done.

If you decide you don't want to save your changes, tap "n" for "no". Emacs will then double-check your decision by asking you:

Modified buffers exist; exit anyway? (yes or no)

Type "yes", which in this context means "yes I really do want to exit and discard my changes"
If you type "no" emacs will send you back to editing mode with Emacs still open and your unsaved changes still visible and accessable in the window.

Tuesday, March 3, 2009

Installing Mac OS X software updates from the commandline

I don't know why I didn't know this existed earlier - it's the most helpful computer administration command I've found in a year.

Apple's Software updates can be downloaded and installed on Mac OS X with the command "softwareupdate". This makes Updating your OS X remotely via ssh a snap compared to using ARD or VNC.

The command:

softwareupdate -l

will scan the apple update site for pending updates, and display them complete with a commandline-friendly label (name).

You can then install the updates you want with

softwareupdate -i [update_label]

For example:

$ softwareupdate -l
Software Update Tool
Copyright 2002-2005 Apple

Software Update found the following new or updated software:

   * JavaForMacOSX104Release7-1.0
      Java for Mac OS X 10.4, Release 7 (1.0), 82580 [recommended]

$ softwareupdate -i JavaForMacOSX104Release7-1.0

The command output shows which upates are recommended and which will requite a system restart.

The install command prints out a handy character based progress meter while it's downloading and installing:

Downloading Java for Mac OS X 10.4, Release 7
 Downloading Java for Mac OS X 10.4, Release 7
 0..20..40..60..80..100

 Expanding Java for Mac OS X 10.4, Release 7
 Installing Java for Mac OS X 10.4, Release 7
 0..20..40..60..80..100

 Done.

This is one terrific feature!