Path: utzoo!telly!attcan!utgpu!watmath!uunet!bu-cs!jbw From: jbw@bucsf.bu.edu (Joe Wells) Newsgroups: gnu.emacs Subject: Re: Any interesting .abbrev_defs? Message-ID: <40989@bu-cs.BU.EDU> Date: 23 Oct 89 16:14:41 GMT References: <1989Oct17.030717.18759@sun.soe.clarkson.edu> Sender: daemon@bu-cs.BU.EDU Organization: Boston University Computer Science Department Lines: 57 In-reply-to: nelson@sun.soe.clarkson.edu's message of 17 Oct 89 03:07:17 GMT 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@bu-it.bu.edu ...!harvard!bu-cs!bucsf!jbw (617) 375-6893 200-202 Bay State Rd., Box 1486, Boston, MA 02215, USA