From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: gebser@ameritech.net Newsgroups: gmane.emacs.help Subject: Re: Abbrevs and Comments Date: Mon, 3 Feb 2003 06:16:19 -0500 (EST) Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: Reply-To: gebser@ameritech.net NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: main.gmane.org 1044270915 25829 80.91.224.249 (3 Feb 2003 11:15:15 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 3 Feb 2003 11:15:15 +0000 (UTC) Cc: help-gnu-emacs@gnu.org Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18feZF-0006iS-00 for ; Mon, 03 Feb 2003 12:15:14 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18feb1-0003IW-02 for gnu-help-gnu-emacs@m.gmane.org; Mon, 03 Feb 2003 06:17:03 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 18feab-0002xx-00 for help-gnu-emacs@gnu.org; Mon, 03 Feb 2003 06:16:37 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 18feaS-0002eI-00 for help-gnu-emacs@gnu.org; Mon, 03 Feb 2003 06:16:30 -0500 Original-Received: from mailhost2-bcvloh.bcvloh.ameritech.net ([66.73.20.44] helo=mailhost.bcv2.ameritech.net) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18feaK-0002Ys-00 for help-gnu-emacs@gnu.org; Mon, 03 Feb 2003 06:16:20 -0500 Original-Received: from mailhost.bcv2.ameritech.net by mailhost.bcv2.ameritech.net convert rfc822-to-8bit; Mon, 3 Feb 2003 06:16:06 -0500 Original-Received: from heidegger.mousecar.net ([65.43.211.188]) by mailhost.bcv2.ameritech.net (InterMail vM.4.01.02.17 201-229-119) with ESMTP <20030203111606.UBLL16631.mailhost.bcv2.ameritech.net@heidegger.mousecar.net>; Mon, 3 Feb 2003 06:16:06 -0500 Original-To: Roberto Huelga In-Reply-To: X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:6227 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:6227 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: =3D = =3D El lunes, 13 ener, 2003, a las 13:09 Europe/Madrid, Roberto Huelga = =3D escribi=F3: =3D = =3D > Hello, and happy new year to every body (my first mail of the year)= =2E =3D > =3D > I recently modify my .emacs file to make use of abbrev and skeleto= ns = =3D > in c-mode and c++-mode. I make that "if" expands to "if() { }" and = all = =3D > is prefect. But When I'm writing a comment or a literal the abbrev = =3D > expands too. Is there a automatic way to don't expand in these = =3D > situations?. =3D > =3D I finally develop a automatic way, may be not optimal but work great= = =3D in my computer. I look the face in the current point and I modify the= = =3D local-abbrev-table in consequence. Insert this in .emacs to try it =3D = =3D (add-hook 'pre-abbrev-expand-hook 'abbrev-literal-test) =3D (defun abbrev-literal-test() =3D (let* ((face (get-text-property (point) 'face ))) =3D (if (or (equal face 'font-lock-comment-face) =3D (equal face 'font-lock-string-face) =3D (equal face 'font-lock-warning-face)) =3D (setq local-abbrev-table nil) =3D (setq local-abbrev-table (eval =3D (car =3D (read-from-string =3D (format "%s-abbrev-table" major-mode))))) =3D ))) =3D = =3D If someone optimise this or found a better way, please tell me. =3D = =3D = =3D = =3D _______________________________________________ =3D Help-gnu-emacs mailing list =3D Help-gnu-emacs@gnu.org =3D http://mail.gnu.org/mailman/listinfo/help-gnu-emacs =3D = -- = Happy Gui-Wei 4700