[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: abbrevs, skeletons, and comments

From: Stefan Monnier
Subject: Re: abbrevs, skeletons, and comments
Date: Tue, 12 Jun 2007 09:50:21 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux)

> In a module I'm writing, I'd like to bind abbrevs to code skeletons,
> similar to what is done e.g. by sml-mode.  But expanding the abbrevs
> makes no sense when the point is inside a comment (or a string
> literal).  So I'd like to conditionally stop expansion.

That's a good point.  An easy way to do that is instead of defining the
abbrev as

    (define-abbrev sml-mode-abbrev-table ,name "" ',fsym nil 'system)

where `fsym' is the name of the skeleton function, you can define it as

    (define-abbrev sml-mode-abbrev-table ,name ""
                   (lambda () (unless (nth 8 (syntax-ppss))
                                (call-interactively ',fsym)))
                   nil 'system)

Hmm... ah no, then it just erases the abbrev's name, so you have to adjust
the function so it re-inserts the text.  And then you have the issue of
whether or not the space that follows the abbrev name was/is inserted,
....  Yuck!

I guess this deserves a feature-request via M-x report-emacs-bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]