Tuesday, June 20, 2006

Emacs Remap Keys

This tip is about mapping keys. This example will map the compile function to F10 and will map F11 to jump to the next error. By default to compile something you would have to issue the compile command by using Mx compile and then to go to the next error Cx `. However this tip makes it even easier. Just add the following lines inside your custom hook as seen in my previous post.

Add these lines:
(local-set-key [f10] 'compile)
(local-set-key [f11] 'next-error)

Now you will be ready to compile your code with F10 and then jump to the next error with F11. If you want to change it to a different key just change [f10] to the key you want.

Monday, June 19, 2006

Indentation Celebration

This tip is how to setup a custom configuration for C# files along with how to setup custom indentation.

First to define a custom hook for C# define your function
(defun my-chsarp-mode-hook ()
--insert custom csharp setings--)
then you need to add the hook
(add-hook 'csharp-mode-hook 'my-csharp-mode-hook)

Here is the settings to have tabs be 4 spaces and have {} line up. Also this will line up argument list even with variable names.

(defun my-csharp-mode-hook()
(setq c-basic-offset 4)
(c-set-offset 'substatement-open 0)
(c-set-offset 'statement-cont 4)
(c-set-offset 'topmost-intro-cont 0)
(c-set-offset 'block-open 0)
(c-set-offset 'arglist-intro c-lineup-arglist-intro-after-paren)
(c-set-offset 'arglist-cont-nonempty 4))

Saturday, June 17, 2006

Welcome to the Church of Emacs

Thanks to Tristan for his post about emacs abbreviations for LaTeX. It got me to try out emacs as my default editor for coding and such. So I decided that I will document any tips or tricks that I stumble upon during my journey.

The first tip is going to be how to get a mode for C# programming.

To start off you need to download the code for C# mode that can be obtain here.

If you don't have a version of CC Mode of 5.30.x or greater you will need to get a newer version from here.

To check what version of CC Mode you currently have open a C file with emacs and use Mx c-version.

To install csharp mode run the following commands:
mkdir -p ~/elisp
cp csharp-mode.el ~/elisp

Now to enable csharp mode you need to add the following to your .emacs file:

(add-to-list 'load-path "~/elisp")
(autoload 'csharp-mode "csharp-mode-0.5.0" "Major mode for editing C# code." t)
(setq auto-mode-alist (append '(("\\.cs$" . csharp-mode)) auto-mode-alist))

If you have any questions about this just add a comment. Look for tips on customizing your emacs environment in the upcoming post.