This is part of The Pile, a partial archive of some open source mailing lists and newsgroups.
Newsgroups: comp.emacs Date: Tue Dec 2 23:54:23 2003 From: doom@kzsu.stanford.edu (Joseph Brenner) Subject: Re: .emacs files References: <vsq2elhr8kbi05@corp.supernews.com> --text follows this line-- "Mark Rance" <mrr@pcisys.network> writes: > Does anyone here have a .emacs file that you're proud of and, therefore. > desirous to share? A number of people have .emacs far more polished than mine, and you can find those out on the web in the places indicated. I'll give you a quick run-down of some features I like in my .emacs though. (Note, I'm running GNU emacs 21.1.1) I've got some things like this, to add new locations to my "load-path" so that emacs can find new places I've stashed elisp files: ; for random code from the emacswiki site (setq load-path (append load-path '("/usr/lib/emacs/site-lisp/emacswiki"))) I've been playing around with desktop.el and session.el. Neither seem to quite do what I want... desktop.el does too much and session.el does to little. If you're a mouse-oriented person I might recommend playing with session.el though: ; Trying the "session.el" approach rather than the "desktop.el" (require 'session) (add-hook 'after-init-hook 'session-initialize) It's far too easy to hit C-x C-c by accident (considering I type C-x C-s all day long). Like most people I have some way of disabling this, but mine is probably sillier than most (I think I wanted visual confirmation when I hit it by accident, to make sure that that was really the problem and not some sort of emacs crash bug): ; C-x C-c runs the command save-buffers-kill-emacs by default, ; but that's too dangerous: (defun doom-x-c-me-not-dont-kill-me-please-no-no () "Inane dummy command to run instead of save-buffers-kill-emacs" (interactive) ;;; (desktop-save "~/") ;;; sneaky, doing something useful here. (message "You just hit C-x C-c.")) (global-set-key "\C-x\C-c" 'doom-x-c-me-not-dont-kill-me-please-no-no) By the way, you might note that when I create an emacs extension, I tend to prepend my username "doom-". Makes it easier to find a command when all I can remember is that I wrote it... I don't even remember what this does, but here it is: (setq enable-local-variables nil) [I bet this prevents the use of a Local Variables: table at the bottom of a file, which is arguably a security hole.] I wanted my searches to default to case sensitive, but haven't solved the problem yet: (setq case-fold-search nil) ;;; does this have to be run by each mode-hook??? ;;; doesn't want to work globally. This bit takes some getting used to, but over-all I think I like it... you know how if you've got multiple buffers open editing files with the same name (e.g. index.html) emacs distinguishes them with a <2> <3> and so on? Using uniquify will use the directory name to distinguish, like "index.html|public_html" and "index.html|htdocs": ; improve silly emacs buffer name uniquification (no more appending "<2>", etc): (require 'uniquify) (setq uniquify-buffer-name-style 'post-forward) It's a good idea for emacs to know your email address: (setq user-mail-address "doom@kzsu.stanford.edu") I do things like this because I'm a cranky, mouse-hating old-fart that would've switched to xemacs a long time ago if I wanted my screen cluttered up with GUI nonsense: (scroll-bar-mode -1) (menu-bar-mode -1) (tool-bar-mode -1) ; emacs 21 Drawback to the above: it looks like people are now writing software that isn't useable if you're not a gay mouser (e.g. session.el has a menu that you can't seem to access without the menu bar). I dunno if this is still necessary, but I've done this for a long time: ;For displaying Latin-1 (ISO 8859) characters (standard-display-european 1); This can be a little dangerous though, in that you might accidentally send out a piece of email with something that *looks* like an ordinary quote or apostrophe, but actually isn't and shouldn't be used if you can avoid it. Another oldie, so that the time always appears in the status bar: ;Show the time in the status bar (also "Mail" notification) (display-time) Another touch that I like: ; Adding column number display in status bar. ; (The second line does this. The first is probably redundant: on by default) (setq line-number-mode t) (setq column-number-mode t) Unix software tends to kick you into whatever editor you've specified with the EDITOR environment variable. Serious emacs users don't like to continually start-up new emacs though... instead they use "emacsclient" E.g. in my ~/.bash_profile file, I have the line: export EDITOR=emacsclient Combined with this in my .emacs: ; needed so that EDITOR can be set to emacsclient (server-start) This means that when some other software wants me to use an editor, instead of a whole new emacs, I get a new buffer opened up in my existing emacs. This works *really* well when you get in the habit of using a shell inside of emacs (Esc-x shell). The following is pretty cool, but doesn't work well enough for me to have it uncommented (it messes with what X window ends up on top, at least using my window manager, icewm): ; emacs is cool ;(mouse-avoidance-mode 'exile) ;(mouse-avoidance-mode 'banish) ; not to mention silly: ;(mouse-avoidance-mode 'proteus) ;(mouse-avoidance-mode 'cat-and-mouse) I switch back and forth between how big I want my emacs font to be when I start up: ; The big font that I always seem to want (set-frame-font "10x20") ; next size down: ; (set-frame-font "9x15") This section is pretty key for me, and hopefully self-explanatory: ;;; whitespace handling: (add-hook 'write-file-functions 'delete-trailing-whitespace) ; Q: What do I change to get emacs to automatically insert a ; newline when I cursor down past the end of the file? ; A: (setq next-line-add-newlines 't) ; force emacs to always use spaces for tabbing (setq-default indent-tabs-mode nil) I am a big fan of light text on dark backgrounds, hence I do lots of tweaking of the default colors. (Note, if you want to come up with a color scheme of your own, M-x list-colors-display is your friend): ;;; ;;; color scheme ; Provides a (base?) color scheme for additional frames: (add-to-list 'default-frame-alist '(foreground-color . "Thistle")) (add-to-list 'default-frame-alist '(background-color . "Black")) (add-to-list 'default-frame-alist '(cursor-color . "Orchid")) (add-to-list 'default-frame-alist '(mouse-color . "GreenYellow")) (add-to-list 'default-frame-alist '(border-color . "DarkOliveGreen")) (add-to-list 'default-frame-alist '(border-color . "Thistle")) ;Highlighting the region (transient-mark-mode t) (set-face-foreground 'region "Black") (set-face-background 'region "DarkOliveGreen") ;hacking the rest of the color scheme: (set-foreground-color "Thistle") (set-background-color "Black") (set-cursor-color "Orchid") (set-mouse-color "GreenYellow") (set-face-foreground 'modeline "Black") (set-face-background 'modeline "DarkSlateBlue") ; Does this do anything? (set-border-color "DarkOliveGreen") ;(set-border-color "Thistle") ; This sets the text color for highlighted text (e.g. when running ispell) (set-face-foreground 'highlight "PaleGreen") (set-face-background 'highlight "BlueViolet") ;(set-face-background 'highlight "Black") ; Helps find the parenthesis that matches whichever one you've cursored to: (show-paren-mode) (set-face-foreground 'show-paren-match-face "PaleGreen") (set-face-background 'show-paren-match-face "BlueViolet") (set-face-foreground 'show-paren-mismatch-face "yellow") (set-face-background 'show-paren-mismatch-face "firebrick") ; Experimenting with just turning on font-lock everywhere (global-font-lock-mode 1) ; (makes some other settings below redundant) I've got a lot of keymap changes of course... one thing I like is to make it easier to get into other "search" modes besides the usual incremental search: ;;; keymap changes (global-set-key [f8] 're-search-forward) (global-set-key [f9] 'search-forward) ; (cool, this last change is great: it obliterates the weird ; notion that there's a "find" key on this keyboard for search-forward ; to be bound to.) (And the first one, f8 I actually use sometimes). I use my insert key as "insert-register", and I've been experimenting with f3 as a shorter synonym for "C-x r s s": (global-set-key [insert] 'insert-register) (global-set-key [f3] 'copy-to-register) This fixes some odd behavior that bugs some people (emacs shouldn't be automatically be sticking newlines in files that didn't have 'em before, I'd say): (setq require-final-newline nil) Here's a passage I lifted from the .emacs file of a "Mike Coleman" many years ago... You may not believe it now, but once upon a time the help command was not bound to "f1", but rather to the backspace key... yes: "backspace for help". Those were exciting times. Many an interesting debate was had on whether this stupidity had some virtue in encouraging people to learn how to customize their emacs in order to fix it... Anyway, I'm in the habit of using "M-h" for help, rather than "f1". I guess a bunch of this stuff is un-needed now: ; Fix stupid EMACS problem. ; (global-set-key "\C-h" 'delete-backward-char) (global-set-key "\C-?" 'delete-backward-char) (setq search-delete-char ?\^h) (define-key esc-map "h" 'help-command) (define-key esc-map "?" 'help-command) (define-key esc-map "\C-h" 'backward-kill-word) (define-key help-map "\M-h" 'help-for-help) (define-key help-map "\M-?" 'help-for-help) If you don't compile your code from inside of emacs, you need to jump to lines by line number quite often: (global-set-key "\C-xL" 'goto-line) A few confusing things that I don't like to have happen by accident: ;;; the disabled list (put 'downcase-region 'disabled nil) (put 'narrow-to-region 'disabled nil) Pretty frequently I go browsing around and find a particular file, then I want to do something like paste the full-path to it into an email message, or into a file of personal notes. This makes it a hell of a lot of eaiser (My First Elisp. *sniff*): (defun doom-filename-to-register () "Save the current filename to register f and also the kill ring" (interactive "*") (set-register ?f (buffer-file-name)) (kill-new (buffer-file-name))) (global-set-key "\C-c\C-f" 'doom-filename-to-register) ; Bugs in the above: ; (1) won't work if the buffer is ; write protected. Toggle write-protect before and after? ; (2) this "global" setting gets pre-empted in too many other modes. ; switch to the another binding? ; Alternately, set it in every map you think you need it? (add-hook 'cperl-mode-hook '(lambda () (define-key cperl-mode-map "\C-c\C-f" 'doom-filename-to-register))) (add-hook 'doomfile-mode-hook '(lambda () (define-key doomfile-mode-map "\C-c\C-f" 'doom-filename-to-register))) (add-hook 'html-mode-hook '(lambda () (define-key html-mode-map "\C-c\C-f" 'doom-filename-to-register))) A nice little trick lifted from the O'Reilly book "Writing GNU Emacs Extensions": ; Inserts the date stamp at point, from Glickstein page 48. (defun insert-current-time () "Insert the current time" (interactive "*") (insert (current-time-string))) (global-set-key "\C-c\C-d" 'insert-current-time) I've got more stuff from Glickstein's book, but what the hell, maybe you should just read it yourself... I really dislike minimizing my emacs by accident by hitting C-z so I always have it bound to something else. It *used* to be I used it as a synonym for M-w: ; I hate closing the window by accident with C-z, and ; I like to copy text from read-only windows, so let's try this: ;;; (global-set-key "\C-z" 'copy-region-as-kill) I recommend setting it to *something* useful (note: Glickstein has a suggestion for it that I use these days). Oh, and some time when you're in need of distraction or enlightenment, try doing a M-x zone. If you do this a lot, you may find you want to set this variable also: ; zone much less often (setq zone-idle 3600) I usually like to have auto-fill on my default, and I'm a big fan of tight right margins, hence the default-fill-column of 60: (setq default-major-mode 'text-mode) (setq text-mode-hook 'turn-on-auto-fill) (setq default-fill-column 60) (setq Tex-mode-hook 'turn-on-auto-fill) I'm running out of breath here, so I'm going to keep this brief. I like the "omit" features of "dired-x" (though you gotta be careful to *remember* you're using it, and that your dired buffers will not necessarily be showing you everything that's there): ; Adding the"Extra" dired features -- pasted from info for ; "dired-x", Node: "Installation" (add-hook 'dired-load-hook (function (lambda () (load "dired-x") ;; Set dired-x global variables here. For example: ;; (setq dired-guess-shell-gnutar "gtar") ;; (setq dired-x-hands-off-my-keys nil) (setq dired-omit-extensions '("CVS/" ".o" "~" ".bin" ".lbin" ".fasl" ".ufsl" ".a" ".ln" ".blg" ".bbl" ".elc" ".lof" ".glo" ".idx" ".lot" ".dvi" ".fmt" ".tfm" ".class" ".fas" ".lib" ".x86f" ".sparcf" ".lo" ".la" ".toc" ".log" ".aux" ".cp" ".fn" ".ky" ".pg" ".tp" ".vr" ".cps" ".fns" ".kys" ".pgs" ".tps" ".vrs" ".idx" ".lof" ".lot" ".glo" ".blg" ".bbl" ".cp" ".cps" ".fn" ".fns" ".ky" ".kys" ".pg" ".pgs" ".tp" ".tps" ".vr" ".vrs")) ))) (add-hook 'dired-mode-hook (function (lambda () ;; Set dired-x buffer-local variables here. For example: (setq dired-omit-files-p t) ))) This is one way to take control of your dired's default sort order: ; dired "ls" options. a t sorts most recently modified first. ; t - most recently modified first ; r - reverses sort order ; a - all; l - long (l is required... not sure about a) ; also: ; -X sort alphabetically by entry extension ; -S sort by file size ; -v sort by version ; --sort=WORD ; extension -X, none -U, size -S, time -t, version -v ; status -c, time -t, atime -u, access -u, use -u (setq dired-listing-switches "-al") Buuut... these days I do it differently. This is a way to get dired to sort directories separately up top: (load-library "ls-lisp") (setq ls-lisp-dirs-first t) I like to have a shell buffer named "shell-misc" at all times (I have a bunch of keystroke macros that go and run shell commands over in the "shell-misc", so it has to exist for them to work): (defun doom-create-shell-misc () "opens a shell buffer names it shell-misc" (interactive) (shell) (rename-buffer "shell-misc")) (doom-create-shell-misc) If you ever run printouts from inside of emacs, most likely you'll want to use M-x ps-print-buffer to do it... so these settings might be helpful: ; Supressing headers with ps-print-buffer (setq ps-print-header nil) ;(setq ps-font-family 'Courier) (setq ps-font-family 'Helvetica) ;(setq ps-font-family 'Palatino) ;(setq ps-font-family 'Times) ;(setq ps-font-family 'NewCenturySchlbk) Let's see... I'll skip the gnus setup, the mh-e setup... Oh, actually why don't I show you this one piece of elisp as an example. If you're more comfortable using a scripting language like perl or bash or something, this is a really dirt simple technique of running it from emacs with a simple elisp wrapper... self-explanatory I hope... replace "momail" with whatever script you want to run, and delete this bit "(mh-rescan-folder)"... or more likely, replace it with whatever elisp you need to run after the script: (defun doom-momail-classic () "refile mh inbox mail using the shell script momail" (interactive) (message (shell-command-to-string "momail")) (mh-rescan-folder)) Oh, one more hint... understand thy hooks, and you can get an elisp command to run automatically at the right moment: (add-hook 'mh-inc-folder-hook 'doom-momail-classic) Well I guess that's (more than) enough... one last thing. If you're into perl hacking, know that cperl-mode is a bit better than perl-mode, and you may want some settings like this: (add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode)) (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode)) (add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode)) You will probably not want a setting like this: ;;; (setq cperl-hairy t) ; **BLEH** But you will almost certainly want a setting like this: ;;; Trying to fix obnoxious cperl-mode trailing-space highlighting. (setq cperl-invalid-face (quote off)) ===