[gnu.emacs] Any interesting .abbrev_defs?

nelson@sun.soe.clarkson.edu (Russ Nelson) (10/17/89)

Does anyone have interesting .abbrev_defs that they'd like to share with
the world?
-- 
--russ (nelson@clutx [.bitnet | .clarkson.edu])
Live up to the light thou hast, and more will be granted thee.
A recession now appears more than 2 years away -- John D. Mathon, 4 Oct 1989.

tdw@cl.cam.ac.uk (Tim Wilson) (10/18/89)

In article <1989Oct17.030717.18759@sun.soe.clarkson.edu>
nelson@clutx.clarkson.edu writes: 

 > Does anyone have interesting .abbrev_defs that they'd like to share with
 > the world?

My .abbrev_defs is probably one of the least worth sharing, but I use
it a lot myself.  I use it to store `mail aliases', instead of using
~/.mailrc, for example (in edit-abbrev format)
	"timw"	       2    "Tim Wilson <tdw@uk.ac.cam.cl>"

I prefer abbrevs to .mailrc aliases since I see the expansion
immediately---and more importantly, I immediately notice the absence
of expansion caused by typos or using aliases I haven't defined.  

What about other mail programs?  The only other mail program I use is
more(1) (faster startup then emacs -f vm), so this point doesn't affect me.

Acknowledgement: The idea was stolen from the Acorn Research Centre
mail reader (ARCmail) for Unipress emacs.

Here's the code:

---- From my .emacs -----------------------------------------------------------
(autoload 'sendmail-abbrev-setup "sendmail-abbrevs"
	  "Load sendmail abbreviations" nil)

(setq mail-mode-hook
      '(lambda ()
	 (sendmail-abbrev-setup)
	 ;; [others omitted]
))
-------------------------------------------------------------------------------

---- sendmail-abbrevs.el ------------------------------------------------------
;;; Turn on abbrev mode for sendmail, and load abbreviations.
;;; Last edited: Tue Jun  6 08:55:51 1989 by Tim Wilson

(define-abbrev-table 'sendmail-mode-abbrev-table ())

(defun sendmail-abbrev-setup ()
  ;;
  ;; Load abbrevs unless we have done so already
  ;;
  (if (not mail-abbrevs-loaded) 	; Defined in sendmail.el
      (if (file-readable-p abbrev-file-name)
	  (progn
	    (read-abbrev-file abbrev-file-name)	; Ie default abbrev table
	    (setq mail-abbrevs-loaded t))))
  (setq local-abbrev-table sendmail-mode-abbrev-table)
  (abbrev-mode 1))
-------------------------------------------------------------------------------

ARCmail added the wrinkle that mail alias expansion only took place in
the header.  However, I omitted this feature since I quite often want
to include mail addresses in the body of a message---and anyway, very
few of my abbrevs are English words.

Improved implemention:  How about defining abbrevs equivalent to
.mailrc? (We already have a parser for .mailrc in mailalias.el.)

Improvements and suggestions welcome.

--
Tim Wilson			Janet:  tdw@uk.ac.cam.cl
				Nsfnet: tdw%cl.cam.ac.uk@nsfnet-relay.ac.uk
+44 223 334624			Uucp:   ...!mcvax!ukc!cam-cl!tdw

jbw@bucsf.bu.edu (Joe Wells) (10/23/89)

In article <1989Oct17.030717.18759@sun.soe.clarkson.edu> nelson@sun.soe.clarkson.edu (Russ Nelson) writes:

   Does anyone have interesting .abbrev_defs that they'd like to share with
   the world?

Here you go:

(define-abbrev-table 'c-mode-abbrev-table '(
    ("return" "return" c-space-hook 75)
    ("if" "if" c-space-hook 112)
    ("while" "while" c-space-hook 7)
    ("switch" "switch" c-space-hook 1)
    ("for" "for" c-space-hook 15)
    ))

(defun c-space-hook ()
  (cond ((and (eq this-command 'self-insert-command)
	      (eq last-command-char ? )
	      (not (c-in-comment))
	      (not (c-in-string)))
	 (insert ? )
	 (insert-parentheses nil)
	 (setq unread-command-char ?\C-?))))

(defun c-in-comment ()
  (let ((point (point))
	(real-comment-start "/*"))
    (save-excursion
      (if (not (search-backward real-comment-start nil t))
	  nil
	(while (c-in-string)
	  (search-backward real-comment-start nil t))
	(if (not (looking-at real-comment-start))
	    nil
	  (if (not (search-forward "*/" nil t))
	      t
	    (>= (match-beginning 0) point)))))))

;; this code is technically incorrect, but should work for most cases
;; I don't check c-in-string to avoid thinking about infinite recursion
(defun c-in-string ()
  (interactive)
  (let ((point (point)))
    (save-excursion
      (while (progn (beginning-of-line nil)
		    (and (not (bobp)) (eq ?\\ (char-after (- (point) 2)))))
	(forward-char -1))
      (or (bobp) (forward-char -1))
      (while (re-search-forward "[^\"]\"" point t 2))
      (re-search-forward "[^\"]\"" point t))))

-- 
Joe Wells <jbw@bucsf.bu.edu>
jbw%bucsf.bu.edu@bu-it.bu.edu
...!harvard!bu-cs!bucsf!jbw
(617) 375-6893
200-202 Bay State Rd., Box 1486, Boston, MA 02215, USA