Emacs

From KallestadWiki

Jump to: navigation, search

I'm a big fan of text editors. I've been using vi and ultraedit pretty extensively over the last decade, and I've ventured into emacs from time to time, but the learning curve was just too much for me to overcome, that is, until recently.

Emacs provides very close to the same experience in linux as it does in windows. It's interface seems very 1980's. But the trade-off for the archaic interface is extensibility and productivity.

For anybody learning emacs, the best way, in my opinion, is to take on the task of learning yet another programming language. Those things that you like to do in various IDE's - eclipse, visual studio, etc. are going to come to mind as you start to write example scripts and programs. You'll have to google how to get them done in emacs, and you'll soon realize that almost everything you can do in those environments is something that someone has already built for emacs.

There are three plugins that I think are important:

  • Yasnippet - which provides the ability to build templates that can easily be called up and categorized per language. Imagine if you will, typing for and TAB within a perl file and it builds the for loop for you with indentation and basic structure. Helpful, yes. Now imagine doing the same in C, Python, Java, Haskell, or Lisp. There are a lot of defaults, but you can also download plenty of samples and build in your own. All of a sudden, the possibility of typo's is drastically removed and you have consistency in your code. Template out your comment blocks, frequently re-typed code snippets, etc.
  • color-theme - pretty basic re-coloring for ease-on-the-eyes. I also use zenburn as the theme. If you go that route, you'll want to update the background-color for yas/field-highlight-face in yasnippet.el
  • Cedet - Cedet is an IDE-inator for emacs. It brings in intellisense, code generation, semantic analysis, and a host of other goodies. Cedet and color-theme slow down loading of emacs.

Contents

Working in Emacs

A few commands to get started with, ones I really like are Bold:

Basics

  • C-x C-f open/create a file
  • C-x C-s save the file
  • C-x C-w save as
  • C-x C-v close current file & open new file
  • C-x b create/switch buffers- like switching windows. follow with a "?" to see a list of open buffers
    • C-x b -> or <- next or previous buffer
  • C-x k kill buffer/file
  • C-x C-b show buffer list
  • C-z suspend/minimize emacs
  • C-X C-c close down emacs
  • M-g-g goto line number
  • C-Space Set beginning mark (for region marking for example)
  • M-W copy the marked region
  • C-Y paste
  • M-Y cycle through paste buffer (after C-Y)
  • C-? Undo (or C-u)
  • C-_ Redo (have to use C-SHIFT--)
  • M-? auto-complete current word
  • C-g cancel command
  • C-s search, enter to complete search
  • M-% (M-Shift-5) search/replace followed by ! to replace all
  • C-x 1 make current buffer only window
  • C-x 2 split window horizontally
  • C-x 3 split window vertically (on a wide screen, this sets up nicely for looking at two files simultaneously


  • C-f forward char
  • C-b backward char
  • C-p previous line
  • C-n next line
  • M-f forward one word
  • M-b backward one word
  • C-a beginning of line
  • C-e end of line
  • C-v one page up
  • M-v scroll down one page
  • M-< beginning of text
  • M-> end of text

yasnippet

TAB - insert named template at current position. i.e. for[TAB] to insert template name "for"

Rare

  • C-x i insert file at cursor position
  • M-x eshell open a shell
  • M-x auc-mode, C-SPACE start column editing
    • ESC-n to insert auto-incremented numbers
    • M-x auc-mode again, end auc-mode (auc-mode also enables C-c C-v for copy paste, which will throw you for a loop once you are used to emacs)
  • C-H help
  • M-u uppercase word from cursor position to end
  • M-l lowercase word from cursor position to end
  • M-c uppercase first letter of word
  • C-t transpose two characters
  • M-x revert-buffer revert unsaved changes
  • M-; comment at end of line
  • M-x comment-region comment highlighted region
    • M-x uncomment-region
  • M-q reformat comments

Customizations I'll get around to

  • binding a key to [C-e ; C-j] (end of line, semicolon, return and auto-indent) for cc-mode and derivatives
  • binding a key to [C-e \ C-j] (end of line, backslash, return and auto-indent) for python-mode
  • splitting out my .emacs file into appropriate separate files so I can move installs from one system to another easily
  • integrating git

Various Notes

  • unbound is pretty cool for finding an empty keystroke to assign a command to.
  • in cedet to get the intellisense menus to work like all the screenshots I've seen, I had to add the following code to me .emacs file
(defun my-cedet-hook()
 (local-set-key (kbd "M-RET") 'semantic-ia-complete-symbol-menu))
 (add-hook 'c-mode-common-hook 'my-cedet-hook)
  • the above binds ALT-ENTER (M-RET in emacs) to open up the intellisense menu. I haven't needed to create tags for anything yet.
  • haven't gotten around to throwing it in my .emacs, but M-x column-mode gives you the column number as well as the line number.
  • note to self - learn auto-fill mode, commenting quick keys
Personal tools