From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: sunway Newsgroups: gmane.emacs.help Subject: Re: Is there any elisp functions to tell whether the cursor is in a comment block? Date: Sun, 13 Jul 2008 18:36:59 -0700 (PDT) Organization: http://groups.google.com Message-ID: <71bcf427-442c-45b8-95d6-5f8289c85297@z72g2000hsb.googlegroups.com> References: <87tzetis7w.fsf@DEBLAP1.BeNet> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1215999648 22199 80.91.229.12 (14 Jul 2008 01:40:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 14 Jul 2008 01:40:48 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jul 14 03:41:36 2008 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.50) id 1KID4K-0005d8-58 for geh-help-gnu-emacs@m.gmane.org; Mon, 14 Jul 2008 03:41:36 +0200 Original-Received: from localhost ([127.0.0.1]:58385 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KID3R-0002jA-SK for geh-help-gnu-emacs@m.gmane.org; Sun, 13 Jul 2008 21:40:41 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!z72g2000hsb.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 36 Original-NNTP-Posting-Host: 123.127.134.57 Original-X-Trace: posting.google.com 1215999419 11269 127.0.0.1 (14 Jul 2008 01:36:59 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Mon, 14 Jul 2008 01:36:59 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: z72g2000hsb.googlegroups.com; posting-host=123.127.134.57; posting-account=ngAdqwoAAAA0uK1OfC15kE5UvDiCOvxy User-Agent: G2/1.0 X-HTTP-UserAgent: Opera/9.51 (X11; Linux i686; U; zh-cn),gzip(gfe),gzip(gfe) X-HTTP-Via: 1.0 localhost.localdomain:8080 (squid/2.6.STABLE18) Original-Xref: news.stanford.edu gnu.emacs.help:160177 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:55526 Archived-At: I will recommend YAsnippet package to you [ code.google.com/p/ yasnippet ] and (add-hook 'c-mode-hook '(lambda () (setq yas/buffer-local-condition '(if (nth 8 (syntax-ppss (point))) '(require-snippet-condition . force-in- comment) t)))) will do what you want. On Jul 14, 1:55=A0am, Joe Bloggs wrote: > bojohan+n...@dd.chalmers.se (Johan Bockg=E5rd) writes: > > sunway writes: > > >> for example, if the cursor is in a normal c code block, I want 'if ' > >> to be expanded to 'if () {}', if it is in the comment block, I prefer > >> 'if ' not be expanded. > > > ;; Non-nil when inside comment or string > > (nth 8 (syntax-ppss (point))) > > > -- > > Johan Bockg=E5rd > > I want to do that too, how do I do a conditional abbrev? > Currently I have: > > (define-abbrev c-mode-abbrev-table "for" > =A0 "" 'c-style-for-loop) > (define-abbrev c++-mode-abbrev-table "for" > =A0 "" 'c-style-for-loop) > > how would I make it only expand in uncommented code?