all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Abbrevs and Comments
@ 2003-01-13 12:09 Roberto Huelga
  2003-01-26 17:44 ` Roberto Huelga
  0 siblings, 1 reply; 4+ messages in thread
From: Roberto Huelga @ 2003-01-13 12:09 UTC (permalink / raw)


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?.

	Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Abbrevs and Comments
       [not found] <mailman.211.1042460105.21513.help-gnu-emacs@gnu.org>
@ 2003-01-13 12:32 ` Romain FRANCOISE
  0 siblings, 0 replies; 4+ messages in thread
From: Romain FRANCOISE @ 2003-01-13 12:32 UTC (permalink / raw)


Roberto Huelga <rhuelga@multinterior.com> writes:

> 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 don't know an automated way to do this, but typing C-q before the
space or the punctuation just after the word prevents it from being
expanded, e.g. the sequence i f C-q SPC will give "if " and not the
expanded version.

-- 
Romain FRANCOISE <romain@orebokech.com> | I live my life alone, alone,
it's a miracle -- http://orebokech.com/ | I think I like it this way.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Abbrevs and Comments
  2003-01-13 12:09 Abbrevs and Comments Roberto Huelga
@ 2003-01-26 17:44 ` Roberto Huelga
  2003-02-03 11:16   ` gebser
  0 siblings, 1 reply; 4+ messages in thread
From: Roberto Huelga @ 2003-01-26 17:44 UTC (permalink / raw)



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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Abbrevs and Comments
  2003-01-26 17:44 ` Roberto Huelga
@ 2003-02-03 11:16   ` gebser
  0 siblings, 0 replies; 4+ messages in thread
From: gebser @ 2003-02-03 11:16 UTC (permalink / raw)
  Cc: help-gnu-emacs


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() { }".


hth,
kf

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
= Help-gnu-emacs@gnu.org
= http://mail.gnu.org/mailman/listinfo/help-gnu-emacs
= 

-- 
Happy Gui-Wei 4700

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-02-03 11:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-01-13 12:09 Abbrevs and Comments Roberto Huelga
2003-01-26 17:44 ` Roberto Huelga
2003-02-03 11:16   ` gebser
     [not found] <mailman.211.1042460105.21513.help-gnu-emacs@gnu.org>
2003-01-13 12:32 ` Romain FRANCOISE

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.