Loading...

Thursday, January 7, 2010

Emacs ECB Crash Course and Tutorial

This is a Quick and Complete Tutorial on Emacs and ECB . It will cover all Commands , ECB , SVN and SSH FTP Remote Editing .

Open Emacs First , preferably latest Version Emacs 23 .
Emacs 23 is the Latest Version of Emacs and has Ruby and XML support shipped by Default.
So All you Ruby on Rails Programmers have it all by Default .

I am using Ubuntu 9.10 Linux and I Go to System -> Administration -> Synaptic Package Manager and Check If these Packages are Installed .
If you are using Older Ubuntu 9.04 then instead of emacs23 Install emacs-snapshot instead because emacs 23 isnt available by Default in 9.04. Rest 4 Packages should remain the same.

5 Packages you need to install in Ubuntu 9.10 -
emacs23
php-elisp
html-helper-mode
css-mode
js2-mode

If you have all these 5 Packages Installed then you are All set for your PHP and Ruby on Rails Endeavours :)
------------------------------------------------------------------------------
Tips
------------------------------------------------------------------------------
C Means CTRL Key
M means ALT Key

E.g.
C-x means Press CTRL and simultaneously Press X Key
C-x C-f means Press CTRL and simultaneously Press X Key, Now keep Pressing CTRL and leave X Key and Press F Key
C-x b means Press both CTRL and X . Then leave both and Press B Key.
M-w means Press ALT and simultaneously Press M Key

Use usual Arrow Keys and Backspace and DELETE to delete.
Press TAB multiple Times to Auto-Complete .
For E.g. When Opening a File using C-X C-f , Press TAB 1-23... times to see File Names . Pressing TAB Key Hints you what other Files Match with what has been already written.

Press ENTER key (Also called RET in Emacs Docs).
Press ENTER key to Confirm any Action .
For e.g. C-x C-s Saves a File . Press ENTER to Confirm . It should be obvious I think.


Working with Files
-----------------------------------------------------------------------------
C-x C-f
Read a File
C-x C-s
Save a File
C-x i
Insert a File into Current Buffer ( Buffer is basically a File loaded into your Computer Memory[RAM])
C-x C-w
Do 'Save As' on a File(Buffer)
C-x b
Selct another File(Buffer)
C-x C-b
List all Buffers (Again Buffer just assume Buffer to be a File though it may not be Technically)

Press CTRL and LeftClick with Mouse to see all Files in TABs


Exitting Emacs
------------------------------------------------------------------------------
C-x C-c - Exit Emacs,See Warning Messages to save Files.Save and Press Usual ENTER.
C-v - Move Down a Screen
M-v - Move Up a Screen


Editing Text
---------------------------------------------------------------------------
I would like to Say before Hand that If you dont Prefer Editing Text the Emacs way then you can change to CUA-Mode . You can use Windows like commands like CTRL+X,CTRL-C,CTRL-V,CTRL-Z,(SHIFT+ArrowKeys and SHIFT+HOME,END Keys for Selecting Text)
In Fact , I like to Activate many things like ,
Go in thecMenu to ,
Options ->
Check i) C-xC-cC-v (CUA)
ii) Paren Match Highlighting
iii) Auto-Fill Text mode
Then Most Important Thing,
Options->Save Options
You are Done , Now you can run all Emacs Commands Windows way .
See,If you need to Restart Emacs to make changes Effective.

Now,Coming to the Emacs way of doing things,
First Mark with CTRL+SPACEBAR to set Intial Point .Move with Arrow Keys to select.
Cut - C-w
Copy - M-w
Paste - C-y

Undo - C-x u ( Means Press CTRL + X Key , then leave both of them and Press U Key)
Redo - Press C-x f and then C-x u


Searching Text
--------------------------------------------------------------------------
C-s - Search forward (Keep Pressing C-s for Next)
C-r - Search backward (Keep Pressing C-r for Back)


Replacing Text
--------------------------------------------------------------------------
First Press C-s
Type the World you want to Match

Then Press
M-% (That means ALT+SHIFT+5 :)
Enter the Replacement Work and Press ENTER

Possible Options Now ->
Space Bar - Replace string, go on to next match

DeleteKey - Skip without replacing, go on to next match

! - Replace all remaining matches

ESC - Stop Replacing


Manipulating Windows
-----------------------------------------------------------------------
C-x 2
Split Window into 2
C-x 1
Make Current Window Full-Size
C-x o
Switch to other Window


Cancel
-----------------------------------------------------------------------
Press C-g anytime when you want to cancel something anytime . Vey handy!


SVN Commands
-----------------------------------------------------------------------
Emacs has Same Interface for any Version Control System like SVN,GIT,Bazaar or Mercurial ( and many more)

C-x v i - Add a New File to your SVN based Project
C-x v v - Commit File If it has been Changed
C-x v m - Update your File to the Latest Revision(Version) from Repository
C-x v = - Compare your File with the Latest from Repository.

You can go to the Menu Tools -> Version Control to see all other Options .


Emacs ECB Code Browser
----------------------------------------------------------------------
For those of you who prefer a Code Browser similar to other Editors Emacs has ECB (Emacs Code Browser).

When You run ECB for the First Time , You need to Set Path for Directories you want to Open in ECB.

Open like this
gedit ~/.emacs

Enter this in your File at the End (Append)

(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(ecb-primary-secondary-mouse-buttons (quote mouse-1--mouse-2))
'(ecb-source-path (quote (("/home/billy" "MyHome")))))

Save and EXIT Now,

Explanantion ->
Here , ("/home/billy" "MyHome") is one setting for your Local Computer.

You can Add As many Folder you like by keeping adding another ("/home/billy" "MyHome") Block

ecb-primary-secondary-mouse-buttons is Added to Open Files like we are used to . Because , By Default Emacs opens a Folder with MiddleMouseClick :)
Remember to Hit the "Small Icon of the folder or otherwise you may not be able to Open Files and Folders.

Now Open Emacs,

M-x ecb-activate

On the Left are Usual 4 Small Windows One above another - 1st is Folder Window , 2nd is Files inside the Folder , 3rd is MethodNames in a File (Like Outline Window in Eclipse) and 4th is History of Files previously Opened.

Just Open a Big PHP or Ruby File with Lots of Methods (Function for Procedural Oriented People :) . Now See the 3rd Window and Click on Any Function there and youll see that It gets Highlighted in the Main Window .
I am used to this in Eclipse PDT so I found it nice to be present in Emacs also .

I hope this is what youll ever need in an IDE and Emacs provides you all of it . But keep Reading . I have Remote File Editing on my Way :)

To close ECB enter ALT-x ecb-deactivate

Opening a File for Remote Editing on SSH or FTP in ECB

----------------------------------------------------------------------

Your .emacs File should look like this ,

(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(ecb-primary-secondary-mouse-buttons (quote mouse-1--mouse-2))
'(ecb-source-path (quote (("/home/billy" "MyHome") ("/billy@99.54.87.802#8081:" "MySSHProject")))))

("/billy@99.54.87.802#8081:" "MySSHProject")
And this One for Remote Editing a File over SSH or FTP or SFTP , Where billy is your username on the Remote Computer , 99.54.87.802 is the Remote Computer and 8081 is SSH Port . SSH Port by default is 22 , but here to show you I have set it to 8081
FTP Port by Default I think is 21.

Open Emacs and then ECB . Enter Password and start Editing Remotely.


You can download Emacs Documentation from here

http://www.gnu.org/software/emacs/manual/emacs.html

Download it in PDF Format as I find integrated Emacs Documentation a bit intrusive . I prefer to open it in a separate PDF Viewer .

I hope It may be useful to some Budding Emacs User . I think It should work same If you prefer to use XEmacs as both Emacs and XEmacs are mostly the same .

Thanks

Rohit Chauhan

0 comments:

Post a Comment