Posts Tagged ‘Emacs’


Bite Sized Emacs

Wednesday, April 14th, 2010

Emacs is a big complicated beast. You can spend lots of time looking through the documentation, but sometimes it’s nice to enjoy a quick bite of Emacs goodness.

Table of Contents:
1: Custom Keystrokes
2: Indenting only as far as you feel comfortable
3: Indentation on steroids
4: Colorful shells
5: Colorful men
6: No more beeping, only flashing
7: Turn off annoying menu bar
8: Customizing font appearance
9: Line wrapping on horizontally split windows
10: Normal looking line wraps
11: Auto backup a little smarter
12: Autocomplete
13: Jumping the line
14: Moving from one window to the other easilly
15: Delete the entire word
16: Enabling the Num Pad
17: Making and storing macros
18: Word Count

Morsel 1 – Custom keystrokes

Make your own custom keystrokes.

Morsel 2 – Indenting only as far as you feel comfortable

Change the indentation rules in cc-mode to as many spaces as you want (I use 4, which looks like normal tabs on other editors, some people use 8, or 2, or whatever).
Edit your .emacs.d/init.el (depending it could be ~/.emacs, ~/.emacs.el, or ~/.emacs.d/init.el) like this (substitute the number you want where I write 4):

  1. ;; define indents as 4 spaces in cc-mode
  2. (setq c-basic-offset 4
  3.       tab-width 4
  4.       indent-tabs-mode t)

Read the rest of this entry »



Three Steps to Making a Custom Keystroke Shortcut in Emacs

Monday, April 12th, 2010

This one’s short (ish?) and sweet. It describes how to make your own global key bindings for functions of your choice in Emacs.

  1. Type “C-h b” in Emacs. This will bring up a list of all the current keybindings.
  2. Type “C-s [KEYBINDING YOU WANT WRITTEN OUT]” to double check that the shortcut isn’t taken using search. For example to check that “C-c t” isn’t taken type “C-s C-c t”.
  3. Modify your .emacs.d/init.el file like this
    1. ;; [USEFUL COMMENTS]
    2. (global-set-key (kbd "[KEYSTROKES WRITTEN OUT]") '[FUNCTION NAME])

For example to set C-c g to trigger goto-line:

  1. ;; Define C-c g as a shortcut for goto-line.
  2. (global-set-key (kbd "C-c g") 'goto-line)

That’s all there is to it. A little bit more about setting key binding in the GNU Emacs Manual.

If you want to use a key that you don’t know the code of simply press, “C-c h [KEY OF INTEREST]“. For example “C-c h [F5]” shows: ” is undefined”, so I would use (kbd “<f5>”)

Read the rest of this entry »



Some Standard Emacs Commands / Keystrokes

Thursday, April 8th, 2010

“C-” is your CTRL key. “M-” is your Meta key, usually ALT or ESC.

Hover over a section to expand it, or:

  • Buffers (they’re like Tabs)
    • Close (kill) buffer ==> C-x k
    • List buffers ==> C-x C-b
    • Switch to next buffer ==> C-x RIGHT
    • Switch to other buffer ==> C-x b
    • Switch to previous buffer ==> C-x LEFT
  • Coding
    • You have to be in outline-minor-mode for many of these. To get there type ==> M-x outline-minor-mode
    • The keystroke shortcuts for these functions have changed quite a bit recently. To check yours, type “C-h b” and look for the command.
    • Collapse all functions  ==>  M-x hide-other
    • Evaluate the Lisp S-expression before the cursor and print result in mini-buffer ==> C-x C-e
    • Hide body of one function ==> M-x hide-subtree
    • Show all functions ==> M-x show-all
    • Show body of one collapsed function ==> M-x show-subtree
  • Debugging
    • After all of the following commands type ENTER and
      the name of the file you want to debug and ENTER.
    • Run DBX (cli) ==> M-x dbx
    • Run GDB (graphic like IDE interface) ==> M-x gdb
    • Run Java debugger ==> M-x jdb
    • Run Perl interpreter in debug mode ==> M-x perldb
    • Run Python debugger ==> M-x pdb
    • Run SDB (cli) ==> M-x sdb
    • Run XDB (cli) ==> M-x xdb
  • Editing
    • Copy region (after you marked ‘beginning’ w C-SPACE) ==> M-W
    • Cut (after you marked ‘beginning’ w C-SPACE) ==> C-W
    • Kill (delete) rest of line ==> C-k
    • Kill (delete) rest of sentence ==> M-k
    • Kill (delete) rest of word ==> M-d
    • Paste marked region (yank) ==> C-y
    • Set mark begin here (for copy, paste, etc.) ==> C-SPACE
    • Set mark and highlight marked area ==> C-SPACE C-SPACE
    • Spell check entire file (buffer) ==> M-x spell-buffer
    • Spell check word ==> M-$
  • Files
    • Compare differences between two files ==> M-x ediff
    • Insert file into buffer ==> C-x i
    • Open a file ==> C-x C-f
    • Quit and Save ==> C-x C-c
    • Refresh buffer after file has been edited elsewhere ==> M-x revert-buffer
    • Replace this with other file ==> C-x C-v
    • Save all ==> C-x s
    • Save file ==> C-x C-s
    • Show directory explorer (dired) ==> C-x d
    • Show number of lines in file ==> C-x l (letter “el”)
    • Suspend and exit to shell (type %emacs in shell to resume) ==> C-z
  • Fonts
  • Formatting
    • Indent line appropriately (according to mode) ==> TAB
    • Indent marked (see Editing) region ==> C- M- \
    • Tabbing (to next Tab stop) ==> M-i
  • Help
    • Describe function run by keystrokes in a window (more info)
      ==> C-h k [COMMAND]
    • RUN TUTORIAL ==> C-h t
    • Show all keyboard shortcuts (key bindings) in effect ==> C-h b
    • Show commands containing a word you type (apropos) ==> C-h a
    • Show function run by keystrokes in echo area (quick info)
      ==> C-h c [COMMAND]
    • Show manual section for function run by kestrokes
      ==> C-h K [COMMAND]
  • Modes (using Emacs for different stuff)
    • Debugging (gdb) mode ==> M- x gdb
    • Shell mode ==> M- x shell
  • Movement
    • Beginning of file ==> C-x [
    • Beginning of line ==> C-a
    • Beginning of sentence ==> M-a
    • Center cursor vertically ==> C-l (letter "el")
    • End of file ==> C-x ]
    • End of line ==> C-e
    • End of sentence ==> M-e
    • Go to line ==> M- x goto-line
    • Next word ==> M- f or M-RIGHT
    • Previous word ==> M- b or M-LEFT
    • Next screen (scroll down) ==> C-v
    • Previous screen (scroll up) ==> M-v
    • Scroll down OTHER window ==> C- M- v
  • Search / Search and Replace
    • Interactive / Incremental Search (highlight as you type) ==> C-s
    • Keep going with current search after editing ==> C-s C-s
    • Next highlighted item ==> C-s
    • Previous highlighted item ==> C-r
    • Search and replace (from cursor to end of file). Type ? for help in replacing. ==> M-%
    • Search using a regular expression ==> M-C-s
    • Select next search string (while in incremental search mode)
      ==> M-n
    • Select previous search string (while in incremental search mode)
      ==> M-p
  • Undo
    • Undo is very good in Emacs, you should look into it in detail
    • Abort command ==> C-g
    • Undo a change ==> C-x u or C-_
  • Windows
    • Close all other windows ==> C-x 1
    • Close this window (“zero”) ==> C-x 0
    • Make window narrower ==> C-x {
    • Make window wider ==> C-x }
    • Make window taller ==> C-x ^
    • Make window shorter ==> M-x shrink-window
    • Move cursor to other window (letter “oh”) ==> C-x o
    • Split this window with a horizontal line ==> C-x 2
    • Split this window with a vertical line ==> C-x 3
  • Some of my own keystroke definitions
    • To make these definitions work, you would have to define them yourself. I include them as a seed for ideas.
    • Go to line # ==> C-c g
    • Move down five lines ==> C-n
    • Move up five lines ==> C-p
    • Outline-minor-mode hide-other ==> C-c c
    • Outline-minor-mode hide-subtree ==> C-c h
    • Outline-minor-mode show-all ==> C-c a
    • Outline-minor-mode show-subtree ==> C-c s
    • Trigger word auto completion ==> TAB
    • Twittering mode (for an Emacs Twitter client) ==> C-c t
    • Woman (in color manual pages) ==> C-c w

*This is a work in progress – Content and presentation are evolving*
Read the rest of this entry »



A Completely Random Guide to Emacs

Friday, April 2nd, 2010

Emacs is more than a text editor. It’s a beast that runs on everything from Unix to Windows.

There are already many Emacs tutorials and FAQs, so I’ll just highlight the things that I found interesting.

Emacs has a ton of commands you can use. These commands are generally accessed by typing Ctr + some letter or M + some letter. The M here stands not for the letter, but for the Meta key… often “Esc.”

This is where Emacs begins to get interesting. But before I proceed:

M-x tetris

Read the rest of this entry »



blog