From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Suvayu Ali Newsgroups: gmane.emacs.help Subject: manipulating abbreviation mode hooks Date: Sun, 09 May 2010 18:38:47 -0700 Message-ID: <4BE763A7.20100@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1273455569 24169 80.91.229.12 (10 May 2010 01:39:29 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 10 May 2010 01:39:29 +0000 (UTC) To: Emacs mailing list Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon May 10 03:39:28 2010 connect(): No such file or directory Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OBHxu-00049F-DB for geh-help-gnu-emacs@m.gmane.org; Mon, 10 May 2010 03:39:26 +0200 Original-Received: from localhost ([127.0.0.1]:47633 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OBHxt-0002EV-Ns for geh-help-gnu-emacs@m.gmane.org; Sun, 09 May 2010 21:39:25 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1OBHxW-0002Dt-EK for help-gnu-emacs@gnu.org; Sun, 09 May 2010 21:39:02 -0400 Original-Received: from [140.186.70.92] (port=47956 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OBHxR-0002BR-AI for help-gnu-emacs@gnu.org; Sun, 09 May 2010 21:39:02 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OBHxM-0004ap-0c for help-gnu-emacs@gnu.org; Sun, 09 May 2010 21:38:57 -0400 Original-Received: from mail-vw0-f41.google.com ([209.85.212.41]:46594) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OBHxL-0004aZ-SM for help-gnu-emacs@gnu.org; Sun, 09 May 2010 21:38:51 -0400 Original-Received: by vws12 with SMTP id 12so2487991vws.0 for ; Sun, 09 May 2010 18:38:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:message-id:date:from :user-agent:mime-version:to:subject:content-type :content-transfer-encoding; bh=4yG995u1JQkkXKEwpTM9neo/Bg0IIU0nxK+8dusgGKo=; b=L2hG8dDjWxwOsct7gsPq2rqPmBnW4yRKcCU9RCHjNcKJ2cR5eIBd2+zigAvxwUWnVu xy2MS5dxLDwTpIvS4dw9HD7VIMkdYcUowrSIlYh4gaFDAmYytcxaPtRAbNzfwBdzwPxF fmE7aXw1TJmQ0W0SBNOBXTr1syQ3Dd72A/2ds= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; b=IUmQfNLiHBsV5z5ZwUccAq1pOS1SDJoazTuq0n5TNTSesfrh3IMIFdQzzn8Ne8kyV2 kqX3ZS0VEcv2CrBNQ1glSU4as8NAR/XTjt5pmaENZXd0yidDI3BhPpiH4T0H5Ich390p 8fKsGJMHvIWLPqH3rXLr3DB9AC2P9sHdW+gXo= Original-Received: by 10.220.63.78 with SMTP id a14mr2723254vci.124.1273455529908; Sun, 09 May 2010 18:38:49 -0700 (PDT) Original-Received: from bhishma.homelinux.net (d207-6-164-45.bchsia.telus.net [207.6.164.45]) by mx.google.com with ESMTPS id b22sm40325590vcp.20.2010.05.09.18.38.48 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 09 May 2010 18:38:49 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100330 Fedora/3.0.4-1.fc11 Lightning/1.0b2pre Thunderbird/3.0.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:73621 Archived-At: Hi everyone, I'm not sure I'll be able to explain what I am trying to do but I'll give it a shot nonetheless. I wrote some abbreviations for the c++ mode (e.g. `for' expands to the entire for loop construct, if..else, ...). However when ever I use any of those abbrevs within a comment, it still expands to the loop. From the info node, "(elisp)Top:: > *Note Abbrevs:: > Abbrev Expansion" I got the hint to use `abbrev-expand-functions' hook. To start out simple, I tried to implement this for shell-script mode abbrev table, and the text-mode abbrev table. So in a scratch buffer I tried this, > (defun foo () > (interactive) > (if (not (save-excursion > (and > (forward-line 0) > (eq (char-after) ?#)))) > (print "src") > (let ((local-abbrev-table text-mode-abbrev-table)) > (print "comments") > (funcall 'expand-abbrev)) > )) This worked as expected, my text mode abbreviations were expanded on a line starting with #, but didn't expand otherwise. But when I put the following in my ~/.emacs, I get no such behaviour. > (defun my-shell-script-mode-abbrev-expand-function () > (if (not (save-excursion > (forward-line 0) > (eq (char-after) ?#))) > (funcall 'expand-abbrev) > (let ((local-abbrev-table text-mode-abbrev-table)) > (funcall 'expand-abbrev)))) > > (add-hook 'shell-script-mode-hook > '(lambda () > (add-hook 'abbrev-expand-functions > 'my-shell-script-mode-abbrev-expand-function > nil t))) Once this is solved, my second question is how do I implement this for c++-mode? I can't figure out how to match to `//' or a `/* ... */' block. I'm a newbie in lisp, so a little guidance would be very appreciated. :) TIA -- Suvayu Open source is the future. It sets us free.