|
davin.50webs.com
New Zealanders making it harder to hate computers
|
|
My Own Personal Additions to Emacs
Abstract
In the ten years that I have used the Emacs editor, I have written
approximately 18,000 lines of Emacs Lisp to customise the program so
that it behaves exactly like how I want it to. This article
presents six additions to Emacs (my most important customisations)
that I have made in the form of eight
Emacs Lisp (*.el) files. The Lisp files presented in this
document should work on all dialects of Emacs, including but not
limited to Gnu Emacs and XEmacs.
Please email me if you encounter any
problems installing these files in your local Emacs system. The files
linked to from this document fall under
the Gnu General
Public License.
1. How to install these features
To install an arbitrary Emacs Lisp file foo.el to your own local
Emacs system, simply copy foo.el to one of the directories pointed
to by the variable load-path and add the line
(require 'foo) to your .emacs file. If you do not
already have a .emacs file, create one in the directory that the
environment variable HOME points to. If your HOME variable is
not set, as might be the case if you are using
Microsoft Windows, then you first need to set it to a
appropriate value for your system. Examples of sensible values for
HOME on Windows systems include c:/ or c:/home or d:/
(if your d:/ drive is a hard disk) or whatever. It is important
that the directory pointed to by HOME actually exists, so you can
put your .emacs file into it.
2. An automated backup system
Here are the features of my automated backup system:
- Puts timestamps on archive (*.tar, *.tar.gz and *.zip) files if they don't already have one.
- Keeps all but the latest N timestamped archive files, where N is an arbitrary positive integer.
- Copies the latest archive files to a different hard drive for
a poor man's R.A.I.D. (Redundant Array of Inexpensive Disks) system.
- Searches for files that the hard drive corrupts, deletes or renames because of hardware failure.
The file bak.el contains the following
important functions:
- datify-dir takes an argument dirname and for each file in
directory dirname timestamps it with the current date and time.
For example, if there is a file foo.tar in the directory
dirname, then it renames it to foo-YYYYMMDD-hhmmss.tar where
the following apply (in order): YYYY is the current year, MM
is the current month, DD is the current day of the month, hh
is the current hour (in a 24 hour clock), mm is the current
minute and ss is the current second.
- cull-duplicates takes a directory argument dirname
and an integer number-to-keep and deletes all but the
latest number-to-keep files for each archive.
The file bak-windows.el contains the function
bak-windows--copy-to-c-drive copies the latest archives from my
d:/ drive to my c:/ drive.
The file checksum.el has the
command M-x checksum which searches for files that have been
corrupted, deleted or renamed. This system was invented out of
necessity as one of my hard drives started behaving erratically, most
likely due to overheating. The command computes the 32-bit checksum
of the file, internally calling the Gnu Shell Command cksum
and comparing it with the corresponding value in the Database of
Checksums which is a collection of checksums each taken after the
last time each file was saved within Emacs. Note that modification of
files outside of Emacs will cause a false positive. If that happens,
then the Database of Checksums needs to be rebuilt. Most
implementations of Emacs can only store 28-bit integers but this only
weakens the error detecting capabilities of the system by a factor of
232 / 228 = 16. To use my system, you will need
to redefine the function checksum--get-file-list to choose the
files that you wish to include in the system.
3. A C++ class browser
The file cbrow.el (cbrow stands for
Class Browser) implements a C++ class browser. Pressing f5
inside a method of a source file (e.g. *.cpp or *.cc) takes
you to corresponding line for that function in the the header file for
that class. Pressing enter at this point takes you back to the
source file. Otherwise pressing f5 takes you to a summary list of
all the classes in your program. To use this code, you will need to
customise the function cbrow--init which can be found at the end
of cbrow.el.
4. A recoverable file deletion system
The file trashcan.el contains a
recoverable file deletion system that behaves like the trash can or
recycle bin that many operating systems, present and past, show on
their screens. This system creates special directories known as
trashcan directories to hold files that can be deleted or
undeleted (restored/recovered). On Unix systems there is one trashcan
directory for each user and the default values are $HOME/.TRASHCAN
for each value of $HOME. On Windows systems there are trashcan
directories at the following default locations: a:\TRASHCAN,
b:\TRASHCAN, c:\TRASHCAN etc.
This system changes the behaviour of the "x" key in dired mode
from permanently deleting files to a two stage system. If you are not
in a trashcan directory, then the selected files are moved into a
trashcan directory. If you are already in a trashcan directory, the
the selected files are permanently deleted. Files in a trashcan
directory can be restored by viewing that directory in dired mode,
selecting some files and executing the command
M-x trashcan-restore. All of the files in a trashcan
directory can also be permanently deleted in one hit by issuing the
command M-x trashcan-empty. The name "trashcan" comes from
my old Amiga
Computer which I still have fond memories of!
Click
here to download a tarball containing trashcan.el.
Note: This code has been submitted to the
Emacs
Lisp List at
Cambridge University, England.
5. The current function/method on the mode-line
The file cfm.el (cfm stands for
Current Function/Method) causes the current function (C/C++) or
method (C++/Java) to be printed on the modeline. This is useful when
you are inside a large method and you can't remember which
function/method you are in.
6. An integrity checker for burnt CD's
The file archive-compare.el
contains the function archive-compare--zips that checks the
integrity of CD's burnt using my CD burner. This function makes use
of the
Five Minute Principle which is used by builders to assess the
quality of their buildings: if the building stays erect for five
minutes after completion, then it will remain erect forever!
Translated to the operation of the integrity checker: if the data is
still intact after five minutes after the CD is burnt, then it will
remain intact for a long time. Internally this function executes the
my own shell command
compare-files.cc which takes two file arguments, compares them
and prints the result of the comparison to std::cout.
7. Some useful directory functions
The file directory-files-deep.el
contains the following useful functions that generalise the built-in
function directory-files:
- directory-files-no-dotdotdot omits the directories "."
and "..".
- directory-files-subdirs only lists subdirectories.
- directory-files-no-subdirs only lists non-subdirectories and
omits the directories "." and "..".
- directory-files-deep lists all the files in the given
directory plus any files in any subdirectories (direct or indirect)
of that directory, minus the directories "." and "..".
| Main Menu
| Research Projects
| Photo Album
| Curriculum Vitae
| Greatest Artists
|
| Email Address
| Computer Games
| Web Design
| Programming
| Other Links
|
| Debugging Macros
| String Class I
| Linked List System I
| Java for C Programmers
| Naming Convention
|
| String Class II
| How I use m4
| Strings III
| Symmetrical I/O
| Linked List System II
|
| Run-Time Type Info
| Virtual Methods
| An Array System
| Science & Religion
| Submodes
|
| Nested Packages
| Memory Leaks
| Garbage Collection
| Internet & Poverty
| What is Knowledge?
|
| Limits of Evolution
| Emacs Additions
| Function Plotter
|
Please report any broken links to the webperson
Last modified: Sat Aug 29 17:31:30 NZST 2009
© Copyright 1999-2009 Davin Pearson.