I started using emacs ever since IV showed us that we could open a shell in it for running gdb, which i didn’t know how to open in vim. ever since i have loved emacs more and more and i think its time to help other people who are itching to move over to emacs.
first of all you need a cheat sheet for emacs, this will help you to get basic stuff done around emacs.
http://ccrma.stanford.edu/guides/package/emacs/emacs.html is a pretty decent one.
now comes configuration, to transform emacs from just another editor to a powerful IDE that it is.
There are three things i want to mention here. One, emacs is not the same as Xemacs, they are two different editors and some of things which work with one may not work with the other. Second, you don’t need to be a lisp expert, or for that matter even know lisp to configure emacs. Third, emacs wiki is your best friend.
Lets begin configuring emacs. One more thing, please read the glossary if can’t relate to a term used below.
There is the configuration file called (dot)emacs and the configuration folder called (dot)emacs(dot)d. These can of course be changed according to personal preference but for the examples these are enough.

(setq load-path (cons “~/.emacs.d/” load-path))

This tells emacs to load the libraries which are present in the folder (dot)emacs(dot)d. The elisp files which have the extension .el have various cool things for your emacs. They can also be downloaded from the emacs wiki

(require ‘pager)
(require ‘install-elisp)

require is a directive to emacs that the given library is required and emacs will give an error if its not found.
The ones that i have included above are particularly useful. Pager is for navigating in documents, and install-elisp is to download and install libraries automatically from emacs wiki (pretty cool huh?).

(load-file “~.emacs.d/cedet/common/cedet.el”)
;;(global-set-key [(f8)] ‘speedbar-get-focus)

cedet is awesome. you have to use it know how awesome it is. Anyways, like i was explaining, CEDET is a collection of tools
written with the end goal of creating an advanced development
environment in Emacs ( ripped from the site of course πŸ˜€ ). The last line starts with “;;” cause its commented. i generally don’t like my F8 to be bound to this ( i will explain how to bind keys soon ). Semantic is quite heavy, hence if you have an ancient comp. you should use the configuration that i have used. On kick ass comps you can enable all the features.

(setq install-elisp-repository-directory “~/.emacs.d/”)

ok by now you would have guessed what setq is for. it sets the value of the variable (duh?). This tell emacs that the elisp repository for install-elisp library is (dot)emacs(dot)d

;; Don’t show splash screen
(setq inhibit-startup-message t)
(setq inhibit-splash-message t)
;; Visible bell – no beeping!
(setq visible-bell t)
;; Modify the mode-line as well. This is a cleaner setup than the default
;; settings for the mode-line.
(setq default-mode-line-format
” “
” %[(” mode-name mode-line-process minor-mode-alist “%n”
(line-number-mode “L%l–“)
(column-number-mode “C%c–“)
(-3 . “%p”)
;; Get rid of the menu, toolbar since I like a plain looking screen.
(menu-bar-mode -1)
;; Don’t echo passwords when communicating with interactive programs – basic
;; security.
(add-hook ‘comint-output-filter-functions
;; Use ANSI colors within shell-mode
(add-hook ‘shell-mode-hook ‘ansi-color-for-comint-mode-on)
;; Disable over-write mode! Never good!
(put ‘overwrite-mode ‘disabled t)
;; Change pasting behavior. Normally, it pastes where the mouse is at, which is
;; not necessarily where the cursor is. This changes things so all pastes,
;; whether they be middle-click or C-y or menu, all paste at the cursor.
(setq mouse-yank-at-point t)
;; Activate font-lock-mode. Syntax coloring!
(global-font-lock-mode t)
;; While we are at it, always flash for parens.
(show-paren-mode 1)
;; The autosave is typically done by keystrokes, but I’d like to save after a
;; certain amount of time as well.
(setq auto-save-timeout 1800)
;; Change backup behavior to save in a directory, not in a miscellany of files
;; all over the place.
backup-by-copying t ; don’t clobber symlinks
‘((“.” . “~/.saves”)) ; don’t litter my fs tree
delete-old-versions t
kept-new-versions 6
kept-old-versions 2
version-control t) ; use versioned backups

The things above are self explanatory πŸ™‚

;; Show column number in mode line
(setq column-number-mode t)
;; Answer y or n instead of yes or no at minibar prompts.
(defalias ‘yes-or-no-p ‘y-or-n-p)
;; Fix the whole huge-jumps-scrolling-between-windows nastiness
(setq scroll-conservatively 5)
;; “Don’t hscroll unless needed”- ? More voodoo lisp.
(setq hscroll-margin 1)
;; What it says. Keeps the cursor in the same relative row during page ups and
;; page downs.
(setq scroll-preserve-screen-position t)
;; Accelerate the cursor when scrolling.
(load “accel” t t)
;; Start scrolling when 2 lines from top/bottom
(setq scroll-margin 2)
;;; Push the mouse out of the way when the cursor approaches.
(mouse-avoidance-mode ‘jump)
;; This apparently allows seamless editting of files in a tar/jar/zip file.
(auto-compression-mode 1)
;; Highlight regions so one can see what one is doing…
(transient-mark-mode 1)
;; Always end a file with a newline
(setq require-final-newline t)

These thing i just like. Not necessary.
Now we come to key binding which are very important.

;;; some nice key bindings
(global-set-key “\C-q” ‘goto-line)
(global-set-key [f1] ‘replace-string)
(global-set-key [f2] ‘other-window)
(global-set-key [f3] ‘other-frame)
(global-set-key [f4] ‘speedbar-get-focus)
(global-set-key [f5] ‘split-window-horizontally)
(global-set-key [f6] ‘buffer-menu)
(global-set-key [f7] ‘kill-buffer)
(global-set-key [next] ‘pager-page-down)
(global-set-key [prior] ‘pager-page-up)
(global-set-key [end] ‘end-of-line)
;;; nice but not as useful
;;;(global-set-key [C-up] ‘pager-row-up)
;;;(global-set-key [C-down] ‘pager-row-down)
(global-set-key [home] ‘My-smart-home)
(global-set-key [select] ‘My-smart-end)
(define-key global-map [M-home] ‘beginning-of-buffer)
(define-key global-map [C-home] ‘beginning-of-buffer)
(define-key global-map [M-end] ‘end-of-buffer)
(define-key global-map [C-end] ‘end-of-buffer)
(define-key global-map [C-down] ‘scroll-up)
(define-key global-map [C-up] ‘scroll-down)
(define-key global-map [C-left] ‘beginning-of-line)
(define-key global-map [C-right] ‘end-of-line)
(defun My-smart-home ()
“Odd home to beginning of line, even home to beginning of
(if (and (eq last-command ‘My-smart-home)
(/= (line-beginning-position) (point)))
(defun My-smart-end ()
“Odd end to end of line, even end to begin of text/code.”
(if (and (eq last-command ‘My-smart-end)
(= (line-end-position) (point)))
(defun end-of-line-text ()
“Move to end of current line and skip comments and trailing space.
Require `font-lock’.”
(let ((bol (line-beginning-position)))
(unless (eq font-lock-comment-face (get-text-property bol ‘face))
(while (and (/= bol (point))
(eq font-lock-comment-face
(get-text-property (point) ‘face)))
(backward-char 1))
(unless (= (point) bol)
(forward-char 1) (skip-chars-backward ” \t\n”)))))

Now from the above configuration you can learn lots of things. First, there are more than one way for defining a key binding. i have used many of them for the sake of the explanation. The wiki however prescribes only one of them, don’t remember which one, read the wiki . Second you can attach a series of commands to key sequence. (C-x Esc Esc) is especially useful to see the command sequence last executed. Thirdly you can see how functions are defined and hooks are made. ( More on these later )One major pain in the ass is that delete or backspace or end or home doesn’t work with emacs. That is not emacs fault but someone else it the culprit. Read this is for a details solution. The link i gave can be overwhelmingly detailed, but no pain no gain πŸ™‚
Some more pretty stuff coming up

;; Frame title : set to buffer name
(setq frame-title-format “Emacs – %f “)
(setq icon-title-format “Emacs – %b”)
;; Display line number in mode line
(setq line-number-mode 1)
;; Display column number in mode line
(setq column-number-mode 1)
;; Highlight words during query replacement
(setq query-replace-highlight t)
;; Highlight matches during search
(setq search-highlight t)
;; Ensure all contents of minibuffer visible
(setq resize-minibuffer-mode t)
;; Kill whole line
(setq kill-whole-line t)
;; Never backup
(setq backup-inhibited t)
;; Always kill/yank to/from clipboard
(setq x-selection-timeout 0)
(setq x-select-enable-clipboard t)
;; Enable some useful commands by default
(put ‘downcase-region ‘disabled nil)
(put ‘upcase-region ‘disabled nil)
(setq special-display-buffer-names ‘(“*Shell Command Output*”))
;; Set some limits
(setq max-specpdl-size 1024)

One last thing i want to tell is

;;Csharp stuff
(autoload ‘csharp-mode “csharp-mode”)

(setq auto-mode-alist (cons ‘(“\\.cs\\'” . csharp-mode) auto-mode-alist))
;; PHP stuff
(autoload ‘php-mode “php-mode”)
(setq auto-mode-alist (cons ‘(“\\.php\\'” . php-mode) auto-mode-alist))
(setq auto-mode-alist (cons ‘(“\\.phpt\\'” . php-mode) auto-mode-alist))

Now this is extremely useful. Here what i am telling emacs is that whenever a file with (dot)cs extension is opened by me load csharp-mode automatically. you can extended the list as shown for the php example.I think this is enough for this post. Will post more stuff later on.

Blogged with Flock

Tags: , ,


4 thoughts on “Emacs

  1. Hi guys! I need help. My credit score is 550. Is there a credit card for me? I have already applied for one and was denied. Yesterday I searched for good credit card sites and have found one with various credit cards. But how could I know what credit card is right for me? Please help. Thanks beforehand.

    discovery card 0%apr

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s