Monday, 28 June 2010

Using tags file with emacs


 
M-.       goes to the symbol definition
M-0 M-.   goes to the next matching definition
M-*       return to your starting point


M-x tags-search <type your regexp>       initiate a search
M-,                                      go to the next match

Making my etags file

Recursively find .py files and pipe them into etags.

find . -regex '.*py' -print | etags -

Tuesday, 27 April 2010

Emacs Kill Commands

Emacs kill commands. Italic text in parenthesis is the elisp command.
  • C-w : Kill region (kill-region).
  • M-w : Save region as last killed text without actually killing it (kill-ring-save). Some programs call this “copying.”
  • M-d : Kill word (kill-word). 
  • M-<BS>:kill word backwards (backward-kill-word). 
  • C-x <BS> : Kill back to beginning of sentence (backward-kill-sentence).
  • M-k : Kill to end of sentence (kill-sentence).  
  • M-k : Kill to end of sentence (kill-sentence).    
  • C-M-k : Kill the following balanced expression (kill-sexp).  
  • M-z char : Kill through the next occurrence of char (zap-to-char).
  • M-\ : Kill whitespace forward.

Thursday, 18 February 2010

Emacs Snippets

m-x occur << wow! awesome

Monday, 15 February 2010

Python Snippets

With a regular expression,

import re
newstring = re.sub(r"\b(\w)(?![2'])", r'\1x', oldstring)

should be fine. If you're allergic to res,

news = ' '.join(x + 'x' if len(x)==1 else x for x in olds.split())

is a concise way of expressing a similar transformation (if length-one is really the only thing you need to check before appending 'x' to an item).

Thursday, 2 April 2009

Emacs - Marking

set mark here                        C-@ or C-SPC
exchange point and mark C-x C-x
set mark arg words away M-@
mark paragraph M-h
mark page C-x C-p
mark sexp C-M-@
mark function C-M-h
mark entire buffer C-x h

Sunday, 22 March 2009

Emacs - navigation

  • C-f Move forward a character
  • C-b Move backward a character
  • M-f Move forward a word
  • M-b Move backward a word
  • C-n Move to next line
  • C-p Move to previous line
  • C-a Move to beginning of line
  • C-e Move to end of line
  • M-a Move back to beginning of sentence
  • M-e Move forward to end of sentence
  • C-v move forward one screen
  • M-v move backward one screen
  • M-<> go to start/end of file
  • C-M-a: Go to the beginning of the current function or class - This doesn't always work for me
  • C-M-e: Go to the end of the current function or class
  • C-c C-n: Jump to the next statement.
  • C-c C-u: Go up one block
  • C-l : Centre screen on cursor.