home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / emacs / 3966 < prev    next >
Encoding:
Text File  |  1993-01-13  |  31.7 KB  |  985 lines

  1. Xref: sparky comp.emacs:3966 gnu.emacs.help:5350
  2. Newsgroups: comp.emacs,gnu.emacs.help
  3. Path: sparky!uunet!cs.utexas.edu!torn!skule.ecf!drill.me!ie.utoronto.ca!garym
  4. From: garym@ie.utoronto.ca (Gary Murphy)
  5. Subject: Re: model for .emacs file
  6. Message-ID: <C0s18E.EoA@ie.utoronto.ca>
  7. Organization: University of Toronto, Department of Industrial Engineering
  8. References: <1993Jan12.154544.17064@fuug.fi>
  9. Date: Wed, 13 Jan 1993 05:14:37 GMT
  10. Lines: 973
  11.  
  12. an3523@anon.penet.fi writes:
  13.  
  14. >Where is info available on how to set up an .emacs file
  15. >(that is, the language/commands necessary)
  16. >thanks
  17.  
  18. Why would you post this anonymously? :-)
  19.  
  20. Ok, here is the .emacs I've used for years, which is actually
  21. .Emacs.el, and virtually all the parts for this came from
  22. documentation or from this newsgroup, so it is time I put somethi{g
  23. back.  What follows is the file I start with when I get to a new site,
  24. and it contains numerous bits and pieces that were fixes and patches
  25. from other sites; I make no warrantees for the robustness or the
  26. appropriateness of this for your needs, and obviously, many of those
  27. reading this will find parts that are just plain broken or missing
  28. essential pieces.
  29.  
  30. The good news is this was cleaned up recently for internal
  31. distribution with a company I was consulting with, and that means it
  32. comes with instructions ... enjoy ...
  33.  
  34. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  35. ;;
  36. ;; .Emacs.el -- source for an auto-recompiling .emacs.elc
  37. ;;
  38. ;; 1988 by Gary Murphy (garym@cognos.uucp)
  39. ;; 1992 by Gary Murphy (gary.murphy@software.mitel.com or murphyg)
  40. ;; 1993 by Gary Murphy (garym@virtual.rose.utoronto.ca)
  41. ;;
  42. ;; This is a cleaned-up edition of my personal emacs start-up file, pieced
  43. ;; together over many difference sites over many years; I won't even pretend
  44. ;; to understand what most of this stuff means and you are on your own if you
  45. ;; want to customize anything.
  46. ;;
  47. ;; To save time on starting emacs (addressing a key complaint from vi-users)
  48. ;; I have my start-up stored as a self-recompiling file; the first time you
  49. ;; compile the file, you will have the overhead of the byte-compiler in memory
  50. ;; but on subsequent runs, unless the .Emacs.el changes, emacs will start
  51. ;; more quickly and will load without the compiler (unless you byte-compile
  52. ;; something else)
  53. ;;
  54. ;; useful tip: if you use X-Windows, load xemacs with a '-font screen' option
  55. ;;
  56. ;; Installation:
  57. ;;
  58. ;;    1) copy this file to .Emacs.el in your root directory
  59. ;;
  60. ;;    2) copy any relevant .el files from my home ~/emacs directory*
  61. ;;       in particular, you may want the following:
  62. ;;
  63. ;;       mail-aliases.el    code-stuff.el    gnus-speedups.el    gnus-wrap.el
  64. ;;       mail-abbrevs.el    shell-complete.el
  65. ;;
  66. ;;     * I am lobbying to have most of this moved to the emacs/lisp/local
  67. ;;       directory where it belongs.
  68. ;;
  69. ;;    3) make a home emacs directory and add the following line to your .cshrc file:
  70. ;;
  71. ;;    setenv EMACSLOADPATH ~/emacs:/usr/tools/emacs/lisp/local:/usr/tools/emacs/lisp
  72. ;;
  73. ;;    4) edit this file with emacs, changing occurances of USER to your login name
  74. ;;       this is most easily done with the M-% command
  75. ;;
  76. ;;    5) M-x eval-current-buffer
  77. ;;
  78. ;;    6) have fun
  79. ;;
  80. ;;       -- the planning is with the many; the decision is done alone --
  81. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  82.  
  83. ;; detect out of date start-up file and recompile.
  84. ;; note that this will keep the byte-compiler loaded for the duration
  85. ;; of the new session.
  86.  
  87. (defun Wait! ()
  88.   "If ~/.Emacs.el exists and is newer than ~/.emacs, recompile it to ~/.Emacs.elc and move the compiled version to ~/.emacs."
  89.   (cond
  90.    ((file-newer-than-file-p "~/.Emacs.el" "~/.emacs")
  91.     (let ((mode-line-format "") (mode-line-inverse-video nil))
  92.       (message "please standby: recompiling .Emacs.el ...")
  93.       (sit-for 1)
  94.       (byte-compile-file "~/.Emacs.el")
  95.       (rename-file "~/.Emacs.elc" "~/.emacs" t))
  96.     (load "~/.emacs" t t t)
  97.     (message ".emacs recompiled")
  98.     (sit-for 2)
  99.     )))
  100.  
  101. (Wait!)
  102.  
  103. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  104. ;; standard libraries to be included ...
  105. ;; ------------------------------------------------------------------------
  106.  
  107. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  108. ;; Rmail -
  109. ;; This sets your emacs environment to use the M-x rmail command
  110. ;;
  111. (setq rmail-primary-inbox-list (list "/usr/mail/garym" 
  112.                                      (expand-file-name "~/Mail/mbox")))
  113.  
  114. ;; set-up for the rmailout.el
  115. ;;
  116. ;; the output list will automagically set the file name when you save messages
  117. ;; in RMAIL format, something I almost never do ;-)
  118.  
  119. (setq rmail-output-directory (expand-file-name "~/Mail"))
  120. (setq rmail-output-files-alist
  121.       '(
  122.     ("Subj.*ISS" "ISS")
  123.     ("-.*begin" "../ppa.new")
  124.     ("To:.*pp[ac]" "mu")
  125.     ("To:.*nativenet" "nn")
  126.     ))
  127. (load-library "rmailout")
  128.  
  129. ;; change the quoting char and reply only to sender
  130.  
  131. (defun new-rmail-reply (recipients-too)
  132.   "Reply to the sender of the current message.
  133. Prefix argument means CC: all other recipients of original message."
  134.  (interactive "P")
  135.  (rmail-reply (not recipients-too))
  136.  (mail-yank-original 0)
  137.  (goto-char 1)
  138.  (re-search-forward mail-header-separator nil t)
  139.  (replace-regexp "^" ">"))
  140.  
  141. ;;; set up the z key to reply to sender & include message
  142. (setq rmail-mode-hook
  143.       '(lambda ()
  144.          (define-key rmail-mode-map "z" 'new-rmail-reply)))
  145.  
  146.  
  147. ;; minibuffer command history on C-n C-p
  148. ;;         (load-library "site/minibuf-mem")
  149.  
  150. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  151. ;;
  152. ;; automagically loaded libraries:
  153. ;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  154. ;; You may or may not have these available at your site.  If you are interested
  155. ;; in something here and it doesn't seem to exist, you can take a copy from
  156. ;; /home/staff/murphyg/emacs (if I have it)
  157.  
  158. ;; - comments and source files
  159.         (autoload 'code-comment-mode "code-stuff.el" 
  160.                   "Major mode for adding comments to source code." t)
  161.  
  162.         (autoload 'code-mode "code-stuff.el"
  163.                   "Major mode for editing source code." t)
  164.  
  165. ;; - a shell for each directory
  166.         (autoload 'sh "sh" "Shell mode with buffer per directory" t)
  167.  
  168. ;; - shell completion
  169.         (autoload 'my-shell-complete "shell-complete" "shell completion" t)
  170.         (autoload 'my-shell-completion-help
  171.                   "shell-complete" "shell completion list" t)
  172.  
  173. ;; - get around the mitel rmail preempting:
  174. ;;        (autoload 'rmail "/usr/tools/emacs/lisp/rmail" nil t)
  175.  
  176. ;; - filename completion, even in shells or with envirnment vars
  177.         (autoload 'complete-filename "filename" nil t)
  178.         (setq shell-mode-hook
  179.               (function (lambda () (local-set-key "\^I" 'complete-filename))))
  180.  
  181. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  182. ;; GNU Smalltalk system
  183.  
  184. (setq auto-mode-alist
  185.      (append  '(("\\.st" . smalltalk-mode))
  186.                 auto-mode-alist))
  187.  
  188. (autoload 'smalltalk-mode "/system/util/gnu/smalltalk-1.1/st.elc"
  189.           "GNU SmallTalk Version 1.1" t)
  190. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  191. ;; GNUS - emacs news reader
  192. ;;
  193. ;; I much prefer gnus over rn for handling my news.  Admittedly it is
  194. ;; many times slower than rn, but if you get a copy of my speedup code
  195. ;; it is quite acceptable.  You shouldn't be reading news anyway ;-)
  196.  
  197. (autoload 'gnus  "gnus-wrap" "Network News." t)
  198. (autoload 'gnus-post-news "gnuspost" "Posting Network News." t )
  199.  
  200. ;;; set gnus up
  201. (setq gnus-default-article-saver 'gnus-Subject-save-in-mail)
  202. (setq gnus-default-distribution "na")
  203. (setq gnus-interactive-post nil)
  204. (setq gnus-auto-select-next "quietly")
  205. (setq gnus-auto-center-subject nil)
  206.  
  207. ;;; NOTE NOTE NOTE: the getenv "HOST" below gets an environment
  208. ;;; variable that is automagically set by the tcsh shell. If you use
  209. ;;; the csh shell, you can either change the (getenv "HOST") to
  210. ;;; "yourmachine" or you can add a line to your .login as follows:
  211. ;;; setenv HOST `hostname`
  212. (setq gnus-nntp-server (getenv "HOST"))
  213.  
  214. (setq gnus-your-domain "Software.Mitel.COM")
  215.  
  216. ;;; define your favorite description of your organization.
  217. (setq gnus-your-organization "Applications Software II, MITEL Corporation, Kanata, Ontario, Canada")
  218.  
  219. (setq gnus-nntp-service nil)
  220. (setq gnus-use-generic-from t)
  221. (setq nnspool-active-file "/usr/spool/news/lib/active")
  222. (setq nnspool-history-file "/usr/spool/news/lib/history")
  223.  
  224. ;;; put your mail directory in here
  225. (setq gnus-article-save-directory "~/Mail/")
  226. (setq gnus-novice-user nil)
  227.  
  228. ;;; hooks - got it from the net, don't remember what it does, but I
  229. ;;; remember wanting to use it.
  230. (setq gnus-Article-mode-hook
  231.       '(lambda ()
  232.      (kill-local-variable 'global-mode-string)))
  233.  
  234. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  235. ;; set-up unix and keybinding environment stuff
  236. ;;
  237. ;; because I like to use the backspace key, I bind help to M-x
  238. ;; rather than C-h
  239.  
  240. (setq lpr-command "print")
  241. (setq lpr-switches (list "-2r"))
  242. (setq tab-width 4)
  243. (global-set-key "\b" 'delete-backward-char)
  244. (global-set-key "\M-o" 'mark-paragraph)
  245. (global-set-key "\M-h" 'help-for-help)
  246. (define-key global-map "\M-s" 'save-buffer)
  247. (setq default-tab-width 4)
  248. (setq dired-listing-switches "-algot")
  249.  
  250. ;some SUN keypad definitions
  251. (global-set-key "*dr" 'beginning-of-line)
  252. (global-set-key "*fr" 'end-of-line)
  253.  
  254. ; extra keys for NeWS and sunview
  255. ;;(global-set-key "\M-[208z" 'search-forward)
  256. ;;(global-set-key "\M-[211z" 'search-backward)
  257. ;;(global-set-key "\M-[209z" 'research-forward)
  258. ;;(global-set-key "\M-[212z" 'research-backward)
  259.  
  260. ;some VT220 keypad bindings
  261. ;(setq term-setup-hook 'my-vt220-keys)
  262. ;;(if (eq (string-match "vt[123]" (getenv "TERM")) 0)
  263. ;;    (setq term-setup-hook 'my-vt220-keys)
  264. ;;)
  265.  
  266. (setq c-mode-hook
  267.       '(lambda ()
  268.      (local-set-key "
  269. " 'newline-and-indent)
  270.      (local-set-key "OPB" 'compile)
  271.      (local-set-key "OPn" 'next-error)
  272.      (set-fill-column 77)
  273.      (auto-fill-mode 1)
  274.        )
  275. )
  276.  
  277. (setq emacs-lisp-mode-hook
  278.       '(lambda ()
  279.      (local-set-key "
  280. " 'newline-and-indent))
  281. )
  282.  
  283. (setq fundamental-mode-hook
  284.      '(lambda ()
  285.      (local-set-key "
  286. " 'newline-and-indent))
  287. )
  288.  
  289. ;;; set up shell mode
  290.  
  291. (setq shell-mode-hook '(lambda ()
  292. ;  (local-set-key "\C-u" 'kill-shell-input-maybe)
  293. ;  (local-set-key "\C-a" 'shell-beginning-of-line-maybe)
  294.   (local-set-key "^[\C-i" 'my-shell-completion-help)
  295.   (local-set-key "\C-c\C-i" 'my-shell-complete)
  296.   (local-set-key "    " 'my-shell-complete))
  297. )
  298.  
  299. (setq text-mode-hook
  300.  '(lambda () 
  301.     (set-fill-column 72)
  302.     (auto-fill-mode 1)
  303.     (setq paragraph-start (quote "^$\\|^ "))
  304.     (setq indent-line-function 'indent-relative-maybe)
  305.    (setq auto-fill-hook
  306.     '(lambda ()
  307.        (do-auto-fill)
  308.      )
  309.    )
  310.    (setq auto-fill-function
  311.     '(lambda ()
  312.        (do-auto-fill)
  313.      )
  314.    )
  315. ;    (setq fill-prefix (get-fill-prefix))
  316. ;    (setq paragraph-separate (quote "^[ .]\\|^@[a-zA-Z][^({[]"))
  317.   )
  318. )
  319.  
  320. (defun shell-script-mode ()
  321.   "Major mode for editing shell scripts."
  322.   (interactive)
  323.    (text-mode)
  324.    (set-fill-column 132)
  325. ;   (auto-fill-mode 1)
  326.    (setq mode-name "Shell Script")
  327.    (local-set-key "
  328. " 'newline-and-indent)
  329.    (setq indent-line-function 'indent-relative-maybe)
  330. )
  331.  
  332. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  333. ;; - RMail mods
  334. ;(defun mail-read-aliases nil
  335. ;  "Read the mail aliases database from ~/EMACSLOADPATH/mail-aliases.el"
  336. ;  (interactive)
  337. ;  (load "mail-aliases" nil t)
  338. ;  ; The above file defines the association list: imail-aliases
  339. ;  (setq mail-aliases nil)  ; Disable the built-in alias mechanism
  340. ;)
  341.  
  342. ;(mail-read-aliases)
  343.  
  344. ;(setq mail-mode-hook
  345. ;      '(lambda nil
  346. ;        (define-key mail-mode-map "\C-c\C-a" 'mail-interactive-insert-alias)
  347. ;        (set-fill-column 72)
  348. ;        (auto-fill-mode 1)
  349. ;    (setq tab-stop-list (list 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90))
  350. ;;    (setq mail-mode-hook nil)
  351. ;       )
  352. ;)
  353. ;
  354. ;(defun mail-interactive-insert-alias nil
  355. ;  "Insert a mail alias."
  356. ;  (interactive)
  357. ;  (insert (or
  358. ;        (cdr-safe (assoc 
  359. ;            (completing-read "Pick an alias: " 
  360. ;                     imail-aliases nil t) imail-aliases))
  361. ;        "")))
  362.  
  363. ;;  modify behaviour of send-mail-function
  364. (setq send-mail-function (function (lambda ()
  365.                      (interactive)
  366. ;                     (ding)
  367.                      (if (y-or-n-p "Add .signature? ")
  368.                      (mail-signature)
  369. ;                       (error ".signature not added.")
  370.                      )
  371.                      (if (y-or-n-p "Really send? ")
  372.                      (sendmail-send-it)
  373.                        (error "Send Aborted")
  374.                      )
  375.                    )
  376.               )
  377. )
  378.  
  379. ;;You could probably do it with:
  380. ;;  modify behaviour of send-mail-function to add ~/.signature
  381. ;(setq send-mail-function (function (lambda ()
  382. ;                     (interactive)
  383. ;                     (mail-signature)
  384. ;                     (sendmail-send-it))))
  385.  
  386.  
  387. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  388. ;; recording outgoing mail:
  389.  
  390.     (setq mail-archive-file-name "/usr/people/garym/Mail/rmail.out")
  391.  
  392. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  393. ;; shell name completion
  394. (defvar shell-word-regexp "\\s-"
  395.   "*Regexp delimiting words on shell command lines.")
  396.  
  397. (defun shell-mode-fns ()
  398.   "Add special shell mode functions."
  399.   (define-key shell-mode-map "\C-c." 'copy-last-shell-word)
  400.   (define-key shell-mode-map "\M-\t" 'complete-last-shell-word))
  401.  
  402. (defun copy-last-shell-word ()
  403.   "Copy the last word from the previous shell input and insert before point."
  404.   (interactive)
  405.   (let ((last-word-start (unwind-protect
  406.                  (save-excursion
  407.                    (goto-char last-input-end)
  408.                    (backward-char 1)
  409.                    (re-search-backward shell-word-regexp)
  410.                    (forward-char 1)
  411.                    (max last-input-start (point-marker))))))
  412.     (insert (buffer-substring last-input-end last-word-start))
  413.     (delete-char -1)))
  414.  
  415. (defun complete-last-shell-word ()
  416.   "Perform filename completion on the last word of the current line."
  417.   (interactive)
  418.   (let* ((end (point))
  419.      (beg (unwind-protect
  420.           (save-excursion
  421.             (re-search-backward shell-word-regexp)
  422.             (forward-char 1)
  423.             (max (marker-position (process-mark (get-buffer-process
  424.                              (current-buffer))))
  425.              (point)))))
  426.      (pattern (buffer-substring beg end))
  427.      (file (file-name-nondirectory pattern))
  428.      (dir (cond ((file-name-directory pattern))
  429.             (default-directory)))
  430.      (completion (file-name-completion file dir)))
  431.     (cond ((eq completion t))
  432.       ((null completion)
  433.        (message "No completions for \"%s\"" pattern)
  434.        (ding))
  435.       ((not (string= file completion))
  436.        (delete-region beg end)
  437.        (insert (concat (file-name-directory pattern) completion)))
  438.       (t
  439.        (message "Making Completion list...")
  440.        (with-output-to-temp-buffer " *Completions*"
  441.          (display-completion-list
  442.           (file-name-all-completions file dir)))
  443.        (message "Making completion list...%s" "done")))))
  444.  
  445. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  446. ;; set the status line to contain the current host
  447.  
  448. (setq short-hostname
  449.       (substring (system-name) 0 (string-match "\\." (system-name))))
  450.  
  451. (setq-default mode-line-format
  452.   '("--%1*%1*-" mode-line-buffer-identification "   " global-mode-string
  453.     "   %[("
  454.     mode-name minor-mode-alist "%n" mode-line-process
  455.     ")%]----"
  456.     (-3 . "%p") 
  457.     "----<"
  458.     short-hostname
  459.     ">-%-")
  460.   )
  461. (display-time)
  462.  
  463. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  464. ;;  Restore previous environment (if any)
  465. ;;(load-library "em-config.el")
  466. ;;(emc-restore)
  467.  
  468. ;;   Follow the above with this code to enable saving of Emacs state
  469. ;;   when quitting a session:
  470.  
  471. (defun save-buffers-kill-emacs (&optional arg)
  472. "Offer to save each buffer, save file configuration, then kill this Emacs fork.
  473.  With prefix arg, silently save all file-visiting buffers, then kill."
  474.        (interactive "P")
  475.        (save-some-buffers arg t)
  476. ;;       (emc-save)
  477.        (kill-emacs))
  478.  
  479. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  480. ;; matching braces:
  481. (defun match-paren (arg)
  482.   "Go to the matching parenthesis if on parenthesis otherwise insert %."
  483.   (interactive "p")
  484.   (cond 
  485.     ((looking-at "[([{]") (forward-sexp 1) (backward-char))
  486.     ((looking-at "[])}]") (forward-char) (backward-sexp 1))
  487.     (t (self-insert-command (or arg 1)))))
  488.  
  489. (global-set-key "%" 'match-paren)
  490.  
  491. ;;Just put the cursor on a { [ or ( and hit '%' and it'll jump to the
  492. ;;matching { [ or (.
  493.  
  494. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  495. ;; all set ... lets go emacs!
  496. (server-start)
  497. ;;--
  498. ;;Gary Lawrence Murphy ---------------- garym@virtual.rose.utoronto.ca
  499. ;;279 Fifth Avenue/Ottawa Ontario/Canada K1S 2N4 ------ (613) 230-6255
  500. ;;The true destination is always just here, now ----------------------
  501.  
  502. From garym@virtual.rose.utoronto.ca Wed Jan  6 14:41:15 1993
  503. Date:     Wed, 6 Jan 1993 13:56:16 -0500
  504. From: Gary Lawrence Murphy <garym@virtual.rose.utoronto.ca>
  505. To: garym@ie.utoronto.ca
  506. Subject: emacs.el
  507.  
  508. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  509. ;;
  510. ;; .Emacs.el -- source for an auto-recompiling .emacs.elc
  511. ;;
  512. ;; 1988 by Gary Murphy (garym@cognos.uucp)
  513. ;; 1992 by Gary Murphy (gary.murphy@software.mitel.com or murphyg)
  514. ;; 1993 by Gary Murphy (garym@virtual.rose.utoronto.ca)
  515. ;;
  516. ;; This is a cleaned-up edition of my personal emacs start-up file, pieced
  517. ;; together over many difference sites over many years; I won't even pretend
  518. ;; to understand what most of this stuff means and you are on your own if you
  519. ;; want to customize anything.
  520. ;;
  521. ;; To save time on starting emacs (addressing a key complaint from vi-users)
  522. ;; I have my start-up stored as a self-recompiling file; the first time you
  523. ;; compile the file, you will have the overhead of the byte-compiler in memory
  524. ;; but on subsequent runs, unless the .Emacs.el changes, emacs will start
  525. ;; more quickly and will load without the compiler (unless you byte-compile
  526. ;; something else)
  527. ;;
  528. ;; useful tip: if you use X-Windows, load xemacs with a '-font screen' option
  529. ;;
  530. ;; Installation:
  531. ;;
  532. ;;    1) copy this file to .Emacs.el in your root directory
  533. ;;
  534. ;;    2) copy any relevant .el files from my home ~/emacs directory*
  535. ;;       in particular, you may want the following:
  536. ;;
  537. ;;       mail-aliases.el    code-stuff.el    gnus-speedups.el    gnus-wrap.el
  538. ;;       mail-abbrevs.el    shell-complete.el
  539. ;;
  540. ;;     * I am lobbying to have most of this moved to the emacs/lisp/local
  541. ;;       directory where it belongs.
  542. ;;
  543. ;;    3) make a home emacs directory and add the following line to your .cshrc file:
  544. ;;
  545. ;;    setenv EMACSLOADPATH ~/emacs:/usr/tools/emacs/lisp/local:/usr/tools/emacs/lisp
  546. ;;
  547. ;;    4) edit this file with emacs, changing occurances of USER to your login name
  548. ;;       this is most easily done with the M-% command
  549. ;;
  550. ;;    5) M-x eval-current-buffer
  551. ;;
  552. ;;    6) have fun
  553. ;;
  554. ;;       -- the planning is with the many; the decision is done alone --
  555. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  556.  
  557. ;; detect out of date start-up file and recompile.
  558. ;; note that this will keep the byte-compiler loaded for the duration
  559. ;; of the new session.
  560.  
  561. (defun Wait! ()
  562.   "If ~/.Emacs.el exists and is newer than ~/.emacs, recompile it to ~/.Emacs.elc and move the compiled version to ~/.emacs."
  563.   (cond
  564.    ((file-newer-than-file-p "~/.Emacs.el" "~/.emacs")
  565.     (let ((mode-line-format "") (mode-line-inverse-video nil))
  566.       (message "please standby: recompiling .Emacs.el ...")
  567.       (sit-for 1)
  568.       (byte-compile-file "~/.Emacs.el")
  569.       (rename-file "~/.Emacs.elc" "~/.emacs" t))
  570.     (load "~/.emacs" t t t)
  571.     (message ".emacs recompiled")
  572.     (sit-for 2)
  573.     )))
  574.  
  575. (Wait!)
  576.  
  577. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  578. ;; standard libraries to be included ...
  579. ;; ------------------------------------------------------------------------
  580.  
  581. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  582. ;; Rmail -
  583. ;; This sets your emacs environment to use the M-x rmail command
  584. ;;
  585. (setq rmail-primary-inbox-list (list "/usr/mail/garym" 
  586.                                      (expand-file-name "~/Mail/mbox")))
  587.  
  588. ;; set-up for the rmailout.el
  589. ;;
  590. ;; the output list will automagically set the file name when you save messages
  591. ;; in RMAIL format, something I almost never do ;-)
  592.  
  593. (setq rmail-output-directory (expand-file-name "~/Mail"))
  594. (setq rmail-output-files-alist
  595.       '(
  596.     ("Subj.*ISS" "ISS")
  597.     ("-.*begin" "../ppa.new")
  598.     ("To:.*pp[ac]" "mu")
  599.     ("To:.*nativenet" "nn")
  600.     ))
  601. (load-library "rmailout")
  602.  
  603. ;; change the quoting char and reply only to sender
  604.  
  605. (defun new-rmail-reply (recipients-too)
  606.   "Reply to the sender of the current message.
  607. Prefix argument means CC: all other recipients of original message."
  608.  (interactive "P")
  609.  (rmail-reply (not recipients-too))
  610.  (mail-yank-original 0)
  611.  (goto-char 1)
  612.  (re-search-forward mail-header-separator nil t)
  613.  (replace-regexp "^" ">"))
  614.  
  615. ;;; set up the z key to reply to sender & include message
  616. (setq rmail-mode-hook
  617.       '(lambda ()
  618.          (define-key rmail-mode-map "z" 'new-rmail-reply)))
  619.  
  620.  
  621. ;; minibuffer command history on C-n C-p
  622. ;;         (load-library "site/minibuf-mem")
  623.  
  624. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  625. ;;
  626. ;; automagically loaded libraries:
  627. ;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  628. ;; You may or may not have these available at your site.  If you are interested
  629. ;; in something here and it doesn't seem to exist, you can take a copy from
  630. ;; /home/staff/murphyg/emacs (if I have it)
  631.  
  632. ;; - comments and source files
  633.         (autoload 'code-comment-mode "code-stuff.el" 
  634.                   "Major mode for adding comments to source code." t)
  635.  
  636.         (autoload 'code-mode "code-stuff.el"
  637.                   "Major mode for editing source code." t)
  638.  
  639. ;; - a shell for each directory
  640.         (autoload 'sh "sh" "Shell mode with buffer per directory" t)
  641.  
  642. ;; - shell completion
  643.         (autoload 'my-shell-complete "shell-complete" "shell completion" t)
  644.         (autoload 'my-shell-completion-help
  645.                   "shell-complete" "shell completion list" t)
  646.  
  647. ;; - get around the mitel rmail preempting:
  648. ;;        (autoload 'rmail "/usr/tools/emacs/lisp/rmail" nil t)
  649.  
  650. ;; - get around a bug in the installation at virtual.rose:
  651.         (autoload 'rmail "/usr/local/emacs/lisp/rmail" nil t)
  652.         (autoload 'sendmail "/usr/local/emacs/lisp/sendmail" nil t)
  653.  
  654. ;; - filename completion, even in shells or with envirnment vars
  655.         (autoload 'complete-filename "filename" nil t)
  656.         (setq shell-mode-hook
  657.               (function (lambda () (local-set-key "\^I" 'complete-filename))))
  658.  
  659. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  660. ;; GNU Smalltalk system
  661.  
  662. (setq auto-mode-alist
  663.      (append  '(("\\.st" . smalltalk-mode))
  664.                 auto-mode-alist))
  665.  
  666. (autoload 'smalltalk-mode "/system/util/gnu/smalltalk-1.1/st.elc"
  667.           "GNU SmallTalk Version 1.1" t)
  668. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  669. ;; GNUS - emacs news reader
  670. ;;
  671. ;; I much prefer gnus over rn for handling my news.  Admittedly it is
  672. ;; many times slower than rn, but if you get a copy of my speedup code
  673. ;; it is quite acceptable.  You shouldn't be reading news anyway ;-)
  674.  
  675. (autoload 'gnus  "gnus-wrap" "Network News." t)
  676. (autoload 'gnus-post-news "gnuspost" "Posting Network News." t )
  677.  
  678. ;;; set gnus up
  679. (setq gnus-default-article-saver 'gnus-Subject-save-in-mail)
  680. (setq gnus-default-distribution "na")
  681. (setq gnus-interactive-post nil)
  682. (setq gnus-auto-select-next "quietly")
  683. (setq gnus-auto-center-subject nil)
  684.  
  685. ;;; NOTE NOTE NOTE: the getenv "HOST" below gets an environment
  686. ;;; variable that is automagically set by the tcsh shell. If you use
  687. ;;; the csh shell, you can either change the (getenv "HOST") to
  688. ;;; "yourmachine" or you can add a line to your .login as follows:
  689. ;;; setenv HOST `hostname`
  690. (setq gnus-nntp-server (getenv "HOST"))
  691.  
  692. (setq gnus-your-domain "Software.Mitel.COM")
  693.  
  694. ;;; define your favorite description of your organization.
  695. (setq gnus-your-organization "Applications Software II, MITEL Corporation, Kanata, Ontario, Canada")
  696.  
  697. (setq gnus-nntp-service nil)
  698. (setq gnus-use-generic-from t)
  699. (setq nnspool-active-file "/usr/spool/news/lib/active")
  700. (setq nnspool-history-file "/usr/spool/news/lib/history")
  701.  
  702. ;;; put your mail directory in here
  703. (setq gnus-article-save-directory "~/Mail/")
  704. (setq gnus-novice-user nil)
  705.  
  706. ;;; hooks - got it from the net, don't remember what it does, but I
  707. ;;; remember wanting to use it.
  708. (setq gnus-Article-mode-hook
  709.       '(lambda ()
  710.      (kill-local-variable 'global-mode-string)))
  711.  
  712. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  713. ;; set-up unix and keybinding environment stuff
  714. ;;
  715. ;; because I like to use the backspace key, I bind help to M-x
  716. ;; rather than C-h
  717.  
  718. (setq lpr-command "print")
  719. (setq lpr-switches (list "-2r"))
  720. (setq tab-width 4)
  721. (global-set-key "\b" 'delete-backward-char)
  722. (global-set-key "\M-o" 'mark-paragraph)
  723. (global-set-key "\M-h" 'help-for-help)
  724. (define-key global-map "\M-s" 'save-buffer)
  725. (setq default-tab-width 4)
  726. (setq dired-listing-switches "-algot")
  727.  
  728. ;some SUN keypad definitions
  729. (global-set-key "*dr" 'beginning-of-line)
  730. (global-set-key "*fr" 'end-of-line)
  731.  
  732. ; extra keys for NeWS and sunview
  733. ;;(global-set-key "\M-[208z" 'search-forward)
  734. ;;(global-set-key "\M-[211z" 'search-backward)
  735. ;;(global-set-key "\M-[209z" 'research-forward)
  736. ;;(global-set-key "\M-[212z" 'research-backward)
  737.  
  738. ;some VT220 keypad bindings
  739. ;(setq term-setup-hook 'my-vt220-keys)
  740. ;;(if (eq (string-match "vt[123]" (getenv "TERM")) 0)
  741. ;;    (setq term-setup-hook 'my-vt220-keys)
  742. ;;)
  743.  
  744. (setq c-mode-hook
  745.       '(lambda ()
  746.      (local-set-key "
  747. " 'newline-and-indent)
  748.      (local-set-key "OPB" 'compile)
  749.      (local-set-key "OPn" 'next-error)
  750.      (set-fill-column 77)
  751.      (auto-fill-mode 1)
  752.        )
  753. )
  754.  
  755. (setq emacs-lisp-mode-hook
  756.       '(lambda ()
  757.      (local-set-key "
  758. " 'newline-and-indent))
  759. )
  760.  
  761. (setq fundamental-mode-hook
  762.      '(lambda ()
  763.      (local-set-key "
  764. " 'newline-and-indent))
  765. )
  766.  
  767. ;;; set up shell mode
  768.  
  769. (setq shell-mode-hook '(lambda ()
  770. ;  (local-set-key "\C-u" 'kill-shell-input-maybe)
  771. ;  (local-set-key "\C-a" 'shell-beginning-of-line-maybe)
  772.   (local-set-key "^[\C-i" 'my-shell-completion-help)
  773.   (local-set-key "\C-c\C-i" 'my-shell-complete)
  774.   (local-set-key "    " 'my-shell-complete))
  775. )
  776.  
  777. (setq text-mode-hook
  778.  '(lambda () 
  779.     (set-fill-column 72)
  780.     (auto-fill-mode 1)
  781.     (setq paragraph-start (quote "^$\\|^ "))
  782.     (setq indent-line-function 'indent-relative-maybe)
  783.    (setq auto-fill-hook
  784.     '(lambda ()
  785.        (do-auto-fill)
  786.      )
  787.    )
  788.    (setq auto-fill-function
  789.     '(lambda ()
  790.        (do-auto-fill)
  791.      )
  792.    )
  793. ;    (setq fill-prefix (get-fill-prefix))
  794. ;    (setq paragraph-separate (quote "^[ .]\\|^@[a-zA-Z][^({[]"))
  795.   )
  796. )
  797.  
  798. (defun shell-script-mode ()
  799.   "Major mode for editing shell scripts."
  800.   (interactive)
  801.    (text-mode)
  802.    (set-fill-column 132)
  803. ;   (auto-fill-mode 1)
  804.    (setq mode-name "Shell Script")
  805.    (local-set-key "
  806. " 'newline-and-indent)
  807.    (setq indent-line-function 'indent-relative-maybe)
  808. )
  809.  
  810. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  811. ;; - RMail mods
  812. (defun mail-read-aliases nil
  813.   "Read the mail aliases database from ~/EMACSLOADPATH/mail-aliases.el"
  814.   (interactive)
  815.   (load "mail-aliases" nil t)
  816.   ; The above file defines the association list: imail-aliases
  817.   (setq mail-aliases nil)  ; Disable the built-in alias mechanism
  818. )
  819.  
  820. (mail-read-aliases)
  821.  
  822. (setq mail-mode-hook
  823.       '(lambda nil
  824.         (define-key mail-mode-map "\C-c\C-a" 'mail-interactive-insert-alias)
  825.         (set-fill-column 72)
  826.         (auto-fill-mode 1)
  827.     (setq tab-stop-list (list 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90))
  828. ;    (setq mail-mode-hook nil)
  829.        )
  830. )
  831.  
  832. (defun mail-interactive-insert-alias nil
  833.   "Insert a mail alias."
  834.   (interactive)
  835.   (insert (or
  836.         (cdr-safe (assoc 
  837.             (completing-read "Pick an alias: " 
  838.                      imail-aliases nil t) imail-aliases))
  839.         "")))
  840.  
  841. ;;  modify behaviour of send-mail-function
  842. (setq send-mail-function (function (lambda ()
  843.                      (interactive)
  844. ;                     (ding)
  845.                      (if (y-or-n-p "Add .signature? ")
  846.                      (mail-signature)
  847. ;                       (error ".signature not added.")
  848.                      )
  849.                      (if (y-or-n-p "Really send? ")
  850.                      (sendmail-send-it)
  851.                        (error "Send Aborted")
  852.                      )
  853.                    )
  854.               )
  855. )
  856.  
  857. ;;You could probably do it with:
  858. ;;  modify behaviour of send-mail-function to add ~/.signature
  859. ;(setq send-mail-function (function (lambda ()
  860. ;                     (interactive)
  861. ;                     (mail-signature)
  862. ;                     (sendmail-send-it))))
  863.  
  864.  
  865. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  866. ;; recording outgoing mail:
  867.  
  868.     (setq mail-archive-file-name "/home/garym/Mail/rmail.out")
  869.  
  870. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  871. ;; shell name completion
  872. (defvar shell-word-regexp "\\s-"
  873.   "*Regexp delimiting words on shell command lines.")
  874.  
  875. (defun shell-mode-fns ()
  876.   "Add special shell mode functions."
  877.   (define-key shell-mode-map "\C-c." 'copy-last-shell-word)
  878.   (define-key shell-mode-map "\M-\t" 'complete-last-shell-word))
  879.  
  880. (defun copy-last-shell-word ()
  881.   "Copy the last word from the previous shell input and insert before point."
  882.   (interactive)
  883.   (let ((last-word-start (unwind-protect
  884.                  (save-excursion
  885.                    (goto-char last-input-end)
  886.                    (backward-char 1)
  887.                    (re-search-backward shell-word-regexp)
  888.                    (forward-char 1)
  889.                    (max last-input-start (point-marker))))))
  890.     (insert (buffer-substring last-input-end last-word-start))
  891.     (delete-char -1)))
  892.  
  893. (defun complete-last-shell-word ()
  894.   "Perform filename completion on the last word of the current line."
  895.   (interactive)
  896.   (let* ((end (point))
  897.      (beg (unwind-protect
  898.           (save-excursion
  899.             (re-search-backward shell-word-regexp)
  900.             (forward-char 1)
  901.             (max (marker-position (process-mark (get-buffer-process
  902.                              (current-buffer))))
  903.              (point)))))
  904.      (pattern (buffer-substring beg end))
  905.      (file (file-name-nondirectory pattern))
  906.      (dir (cond ((file-name-directory pattern))
  907.             (default-directory)))
  908.      (completion (file-name-completion file dir)))
  909.     (cond ((eq completion t))
  910.       ((null completion)
  911.        (message "No completions for \"%s\"" pattern)
  912.        (ding))
  913.       ((not (string= file completion))
  914.        (delete-region beg end)
  915.        (insert (concat (file-name-directory pattern) completion)))
  916.       (t
  917.        (message "Making Completion list...")
  918.        (with-output-to-temp-buffer " *Completions*"
  919.          (display-completion-list
  920.           (file-name-all-completions file dir)))
  921.        (message "Making completion list...%s" "done")))))
  922.  
  923. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  924. ;; set the status line to contain the current host
  925.  
  926. (setq short-hostname
  927.       (substring (system-name) 0 (string-match "\\." (system-name))))
  928.  
  929. (setq-default mode-line-format
  930.   '("--%1*%1*-" mode-line-buffer-identification "   " global-mode-string
  931.     "   %[("
  932.     mode-name minor-mode-alist "%n" mode-line-process
  933.     ")%]----"
  934.     (-3 . "%p") 
  935.     "----<"
  936.     short-hostname
  937.     ">-%-")
  938.   )
  939. (display-time)
  940.  
  941. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  942. ;;  Restore previous environment (if any)
  943. ;;(load-library "em-config.el")
  944. ;;(emc-restore)
  945.  
  946. ;;   Follow the above with this code to enable saving of Emacs state
  947. ;;   when quitting a session:
  948.  
  949. (defun save-buffers-kill-emacs (&optional arg)
  950. "Offer to save each buffer, save file configuration, then kill this Emacs fork.
  951.  With prefix arg, silently save all file-visiting buffers, then kill."
  952.        (interactive "P")
  953.        (save-some-buffers arg t)
  954. ;;       (emc-save)
  955.        (kill-emacs))
  956.  
  957. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  958. ;; matching braces:
  959. (defun match-paren (arg)
  960.   "Go to the matching parenthesis if on parenthesis otherwise insert %."
  961.   (interactive "p")
  962.   (cond 
  963.     ((looking-at "[([{]") (forward-sexp 1) (backward-char))
  964.     ((looking-at "[])}]") (forward-char) (backward-sexp 1))
  965.     (t (self-insert-command (or arg 1)))))
  966.  
  967. (global-set-key "%" 'match-paren)
  968.  
  969. ;;Just put the cursor on a { [ or ( and hit '%' and it'll jump to the
  970. ;;matching { [ or (.
  971.  
  972. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  973. ;; all set ... lets go emacs!
  974. (server-start)
  975. ;;--
  976. ;;Gary Lawrence Murphy ---------------- garym@virtual.rose.utoronto.ca
  977. ;;279 Fifth Avenue/Ottawa Ontario/Canada K1S 2N4 ------ (613) 230-6255
  978. ;;The true destination is always just here, now ----------------------
  979.  
  980. -- 
  981. Gary Lawrence Murphy ---------------- garym@virtual.rose.utoronto.ca
  982. University of Toronto, Industrial Eng Dept    fax:    (416) 971-1373
  983. 4 Taddle Creek Rd, Toronto, Ont M5S 1A4       voice:  (416) 978-3776
  984. The true destination is always just here, now ----------------------
  985.