emacs is one of the better editors available for Linux machines. It may seem a bit unfriendly in the beginning, but after a while one starts to see what emacs is capable of, and how to change it to suite your own taste.
emacs can be used to a lot of things, even browsing the web, but my main use is programming in C and Perl, creating matlab m-files, editing configuration files and simple text files, and also writing HTML files, such as this one. The rest of this page will be about how i set up my .emacs-file to do what I want emacs to do.
For more information, take a look at http://www.gnu.org/software/emacs/
What is .emacs? From the file .emacs,
situated in your home directory (i.e. ~/.emacs) you
can change the way emacs behaves, and also include new features
into emacs in a (quite) easy way.
Beside the .emacs-file I have created a directory
named .emacs_lisp. This directory is intended for
lisp-files not included with emacs. These two things, the
.emacs-file and the .emacs_lisp
directory is all you need.
You must tell emacs to look for *.el-files in the
.emacs_lisp directory. This is done by adding the
following line to your .emacs file.
(setq load-path (cons "~/.emacs_lisp" load-path))
All files ending in .el mentioned later on on this
page should be placed in this directory.
This is the mode I use when creating html files, like this one. The lisp code can be downloaded from http://savannah.nongnu.org/projects/baol-hth
Just follow the information on the web page and in the lisp file.
All my html files have been run through the tidy program. A small program that checks the validity of your html code and formats it so that it look nice and is easy to read. It has a lot of switches so that you can get it to do what you want.
The tidy program can be found at http://tidy.sourceforge.net/
I use CVS to always have the latest version. If this sound interesting, do the following:
$ mkdir ~/src $ cd ~/src
cvs -d:pserver:anonymous@tidy.cvs.sourceforge.net:/cvsroot/tidy login
When asks for password, just press enter.
cvs -z3 -d:pserver:anonymous@tidy.cvs.sourceforge.net:/cvsroot/tidy co tidy
$ cd tidy/build/gmake $ make $ su -c "make install"
$ cd ~/src/tidy $ cvs update -d -P
and then create the binary as just mentioned.
Tidy can be used directly in emacs, which helps a lot. First fetch
the lisp code tidy.el from http://www.emacswiki.org/elisp/tidy.el.gz
In your .emacs file add
(autoload 'tidy-buffer "tidy" "Run Tidy HTML parser on current buffer" t) (autoload 'tidy-parse-config-file "tidy" "Parse the `tidy-config-file'" t) (autoload 'tidy-save-settings "tidy" "Save settings to `tidy-config-file'" t) (autoload 'tidy-build-menu "tidy" "Install an options menu for HTML Tidy." t) ;; For other modes (like html-helper-mode) simple change the variables ;; `html-mode-hook' and `html-mode-map' to whatever is appropriate e.g. (defun my-html-mode-hook () "Customize my html-helper-mode." (tidy-build-menu html-helper-mode-map) (local-set-key [(control c) (control c)] 'tidy-buffer) (setq sgml-validate-command "tidy")) (add-hook 'html-helper-mode-hook 'my-html-mode-hook)
My configuration file for Tidy, ~/.tidyrc, looks like
this
// HTML Tidy configuration file ascii-chars: no break-before-br: yes char-encoding: latin1 doctype: transitional indent: yes indent-attributes: yes wrap: 75 wrap-asp: no wrap-jste: no wrap-php: no wrap-sections: no
There is also a css mode. It can be fetched from http://www.garshol.priv.no/download/software/css-mode/index.html
An alternative may be found at http://www.emacswiki.org/elisp/css-mode.el
To activate it just add the following lines to your
.emacs file
;; css-mode (http://www.garshol.priv.no/download/software/css-mode/index.html)
(autoload 'css-mode "css-mode")
(setq auto-mode-alist
(cons '("\\.css\\'" . css-mode) auto-mode-alist))
I like the look of the C code in the Linux kernel. To get that
style, add the following to your .emacs file:
;; C-mode according to Linux style
(defun linux-c-mode ()
"C mode with adjusted defaults for use with the Linux kernel."
(interactive)
(c-mode)
(c-set-style "K&R")
(setq c-basic-offset 8))
(add-hook 'c-mode-hook 'turn-on-auto-fill)
(add-hook 'c++-mode-hook 'turn-on-auto-fill)
(setq auto-mode-alist (cons '(".*/.*\\.[ch]$" . linux-c-mode)
auto-mode-alist))
The cperl-mode is a part of the package emacs-el in RedHat/Fedora.
In your .emacs file add
;; Perl
;;
;; Start cperl-mode instead of perl-mode
(setq auto-mode-alist (cons '("\\.\\([pP][Llm]\\|al\\)$" . cperl-mode)
auto-mode-alist))
;;
;; You can either fine-tune the bells and whistles of this mode or
;; bulk enable them by putting
;(setq cperl-hairy t)
;;
;; use cperl mode if perl is in the #!
(add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
Fetch the latest matlab.el file from http://www.mathworks.com/matlabcentral/files/104/matlab.el
In your .emacs file add
;; Matlab mode
;;
(autoload 'matlab-mode "matlab" "Enter MATLAB mode." t)
(setq auto-mode-alist (cons '("\\.m\\'" . matlab-mode) auto-mode-alist))
(autoload 'matlab-shell "matlab" "Interactive MATLAB mode." t)
A very good mode for LaTeX-writing is the AUCTeX mode. You can download it from http://savannah.gnu.org/projects/auctex/ or if you are using Fedora, fetch it Fedora Extras with the yum command.
In your .emacs-file add
;; AUCTeX (require 'tex-site)