[Top][All Lists]

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

Re: Abbrevs and Comments

From: gebser
Subject: Re: Abbrevs and Comments
Date: Mon, 3 Feb 2003 06:16:19 -0500 (EST)

Abbrevs can correspond only to specific modes.  This functionality is
already built into emacs.  For example, if you're in cc-mode (what you
get when you open hello.c), put the cursor on the word "if", do "C-x
ail", you'll be prompted for an "expansion" for the word "if".  Type in 
"if() { }" (and run "M-x write-abbrev-file" if you want to save it for 
future sessions), thereafter whenever you type "if" AND are in cc-mode, 
emacs will expand it to "if() { }".  However, this will also occur in 
cc-mode when you're composing a comment-- probably not what you'd want.  
Get around this by making up some other word to replace "if", such as 
"iiff" or "si", and have that expand to "if() { }".


Roberto Huelga at 18:44 (UTC+0100) on Sun, 26 Jan 2003 said:

= El lunes, 13 ener, 2003, a las 13:09 Europe/Madrid, Roberto Huelga 
= escribió:
= > Hello, and happy new year to every body (my first mail of the year).
= >
= >     I recently modify my .emacs file to make use of abbrev and skeletons 
= > in c-mode and c++-mode. I make that "if" expands to "if() { }" and all 
= > is prefect. But When I'm writing a comment or a literal the abbrev 
= > expands too. Is there a automatic way to don't expand in these 
= > situations?.
= >
=       I finally develop a automatic way, may be not optimal but work great 
= in my computer. I look the face in the current point and I modify the 
= local-abbrev-table in consequence. Insert this in .emacs to try it
= (add-hook 'pre-abbrev-expand-hook 'abbrev-literal-test)
= (defun abbrev-literal-test()
=    (let* ((face (get-text-property (point) 'face )))
=      (if (or (equal face 'font-lock-comment-face)
=           (equal face 'font-lock-string-face)
=           (equal face 'font-lock-warning-face))
=       (setq local-abbrev-table nil)
=        (setq local-abbrev-table (eval
=                               (car
=                                (read-from-string
=                                 (format "%s-abbrev-table" major-mode)))))
=        )))
=       If someone optimise this or found a better way, please tell me.
= _______________________________________________
= Help-gnu-emacs mailing list

Happy Gui-Wei 4700

reply via email to

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