Tuesday, March 31, 2009

Emacs Usage


Emacs is the bese editor I have ever used. It's very good at speed and language format.

.emacs setting

.emacs is a configure file for emacs. When emacs starts, it will run .emacs first. Usually .emacs is at ~/.emacs. Actually .emacs is something like LISP language.
  1. (setq inhibit-startup-message t) is used to shut down the welcome massage when you open emacs. its boring to see a welcome page every time you use emacs.
  2. t means true.
  3. nil means false.
  4. (setq-default make-backup-files nil) is used to shut down the backup automatically. But I recommend you open this function.
  5. (setq require-final-newline nil) will not require a new line in the end of file.
  6. But sometime, (setq require-final-newline nil) does not work. Because /usr/share/emacs/site-lisp/default.el will run after .emacs. At this time, you should switch off the default.el by using (setq inhibit-default-init t). I spent plenty of time on this stupid new line query. Now I can shut it down. But you have to open one thing[7] in .emacs.
  7. (when window-system
    ;; enable wheelmouse support by default
    (mwheel-install)
    ;; make switching frames works properly under the default click- to-focus
    (setq focus-follows-mouse nil) )

-----------------------------------------------------------------------------------------------
Find and Replace

  • Find a string : C-s
  • Find backward : C-r
  • Find forward : C-s
  • How to replace a string. M-x replace-string
  • How to do query replace. M-x query-replace.
  • You also can do query replace by. M-%
----------------------------------------------------------------------------------------------------------

Rectangular Operations

Sometimes it's very convenient to use the rectangular selection in emacs. When you are learning how to do it, it's painful. But after you get it, it will save you much more time.

  1. Select a rectangular area and copy(cut) it to another place. Go to the left-top of the rectangular you want to select. Hit C-space. Then this point is mark set. Then go to the right-bottom of your rectangular area, and click C-x r r(C-x r k for cut) and Enter. This rectangular area has been copied to register. Move your cursor to the place where you want to put this area, and click C-x r i and Enter. After click enter, the content in register will be copied to the new place.
  2. Select a rectangular area and insert some strings. Hit C-space and click C-x r t and Enter. Then you will enter the text you want insert this area. After hit enter, you will see the text has been inserted.
----------------------------------------------------------------------------------------------------------
Cursor Movement

  • Move cursor to the beginning of a line : C-a
  • Move cursor to the and of a line : C-e
  • Move cursor to the beginning of this file: C-x [
  • Move cursor to the end of this file: C-x ]
----------------------------------------------------------------------------------------------------------
Multi-Windows

In emacs, you can split the window in to several windows.

  • C-x 3 will split the window in two columns.
  • C-x 2 will split the window horizontally.
  • C-x 0 will shut down one window.
  • C-x o will change the cursor between different windows.
----------------------------------------------------------------------------------------------------------
Some very useful links
Ted's Blog for emacs
Emacs Keyboard Shortcuts
JW's Tips and Notes: Emacs Example Tutorial: insert a block of text
emacs-fu: working with rectangular selections


Tuesday, March 24, 2009

A Python function which can combine a list to a string


Sometime you can use str.split(".") to split a string to a list. It's very easy to operate on this list. But sometime you want to combine the list to a string again after the list operation. I just write a simple python function.

ListName : the name of list which you want to combine
StrInsert : the string which you want to insert to this list


def combineStr( ListName , StrInsert ):
out_str = ListName[0]
for item in range(1, len(ListName)):
out_str +=StrInsert+ListName[item]
return out_str

Monday, March 23, 2009

How to take a screenshot in your computer

Using GIMP

To take a screenshot with the GIMP, find the following menu option: File —> Acquire —> Screen Shot. You will then be offered some options for the screenshot such as length of delay and whether you want to take a screenshot of the entire screen, or just a window.

PrintScreen Button

This method is easy. Put the button in you keyboard. Normally, the PrintScrn is at
the right side of F12. After you put this button, there will be one window to ask you how to store this picture.


Use Ubuntu(GNOME)

You can open Applications->Accessories->Take Screenshot.
You will see a window which can help you to take a screenshot.

How to add a public calendar to Google Calendar

If you need to print out the meeting schedule, you can just add the public calendar of the meeting to Google Calendar. Google Calender will update the time schedule automatically and I don't need to worry about whether the schedule is the latest.
  1. First you should get the link of the public calender. For example, http://indico.cern.ch/categoryDisplay.py/ical?categId=3l94
  2. Then you can go to your google calender.Click the Add->Add by URL. Then you can type the link of you calendar. Enjoy your own calendar.

I have tested the update rate of Google calender. Normally, it will be updated every 24 hours.

If you are familiar with Python script, you can also use the gcalcli.
gcalcli can connect with google calendar by python. First you can get the public calendar by 'wget'. Then you can edit the calendar file and add these files in to google calendar by gcalcli. It's powerful and useful. But in my case, the first method is enough. So I did't dig out the second method.

Delete the contents of your search toolbar

Sometime if you are using a public computer, you maybe want to delete the search record of your google toolbar.
  • If you are using firefox,you can openEdit->Preferences->Privacy->Clear Now.
  • You also can delete the contents directly. You just click the contents of search bar and shift+delete.

I like the second way. It's more easier and quick.