From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: david@adboyd.com (J. David Boyd) Newsgroups: gmane.emacs.help Subject: Re: VIM can recognize #if 0 #endif as comment pair, how to do that in Emacs? Date: Mon, 20 Aug 2007 10:33:26 -0400 Message-ID: <877inq8edl.fsf@adboyd.com> References: <1187377332.321751.12480@50g2000hsm.googlegroups.com> <1187392828.827057.66510@w3g2000hsg.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1187620447 2387 80.91.229.12 (20 Aug 2007 14:34:07 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 20 Aug 2007 14:34:07 +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 Aug 20 16:34:04 2007 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 1IN8KS-0000EU-If for geh-help-gnu-emacs@m.gmane.org; Mon, 20 Aug 2007 16:34:04 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IN8KS-0004MI-DA for geh-help-gnu-emacs@m.gmane.org; Mon, 20 Aug 2007 10:34:04 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IN8KC-0004Lv-6B for help-gnu-emacs@gnu.org; Mon, 20 Aug 2007 10:33:48 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IN8K8-0004LT-OB for help-gnu-emacs@gnu.org; Mon, 20 Aug 2007 10:33:47 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IN8K8-0004LQ-I9 for help-gnu-emacs@gnu.org; Mon, 20 Aug 2007 10:33:44 -0400 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1IN8K7-0006ra-Ja for help-gnu-emacs@gnu.org; Mon, 20 Aug 2007 10:33:43 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1IN8K0-0004db-Sj for help-gnu-emacs@gnu.org; Mon, 20 Aug 2007 16:33:36 +0200 Original-Received: from 156-40.126-70.tampabay.res.rr.com ([70.126.40.156]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 20 Aug 2007 16:33:36 +0200 Original-Received: from david by 156-40.126-70.tampabay.res.rr.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 20 Aug 2007 16:33:36 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 86 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 156-40.126-70.tampabay.res.rr.com User-Agent: Gnus/5.1100000000000003 (Gnus v5.11) Emacs/22.1 (cygwin) Cancel-Lock: sha1:J1PB7vzUY+YD+4Tc+SYkq0fiQpo= X-Detected-Kernel: Linux 2.6, seldom 2.4 (older, 4) 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:46701 Archived-At: "Leo.Hou" writes: > On Aug 17, 1:20 pm, da...@adboyd.com (J. David Boyd) wrote: >> "Leo.Hou" writes: >> > Hi Experts, >> >> > I saw a friend using VIM and it recognizes #if 0 -- #endif as comment >> > pair and use the comment color for the code in between! >> >> > This is so cool because I had a big headache using emacs+etags jumping >> > into others' code, spent 5 minutes and then realized that emacs >> > brought me to some codes between a #if0 -- #endif pair. :'-( >> >> > Can anyone make Emacs to recognize this common convention and >> > highlight all the pieces between them as comment? >> >> > Thanks! >> >> > Leo >> >> Not _exactly_ what you are talking about, but I like this: >> >> >From C-h f hide-ifdef-mode >> >> hide-ifdef-mode is an interactive autoloaded Lisp function in `hideif'. >> (hide-ifdef-mode &optional arg) >> >> Toggle Hide-Ifdef mode. This is a minor mode, albeit a large one. >> With arg, turn Hide-Ifdef mode on if arg is positive, off otherwise. >> In Hide-Ifdef mode, code within #ifdef constructs that the C preprocessor >> would eliminate may be hidden from view. Several variables affect >> how the hiding is done: >> >> `hide-ifdef-env' >> An association list of defined and undefined symbols for the >> current buffer. Initially, the global value of `hide-ifdef-env' >> is used. >> >> `hide-ifdef-define-alist' >> An association list of defined symbol lists. >> Use `hide-ifdef-set-define-alist' to save the current `hide-ifdef-env' >> and `hide-ifdef-use-define-alist' to set the current `hide-ifdef-env' >> from one of the lists in `hide-ifdef-define-alist'. >> >> `hide-ifdef-lines' >> Set to non-nil to not show #if, #ifdef, #ifndef, #else, and >> #endif lines when hiding. >> >> `hide-ifdef-initially' >> Indicates whether `hide-ifdefs' should be called when Hide-Ifdef mode >> is activated. >> >> `hide-ifdef-read-only' >> Set to non-nil if you want to make buffers read only while hiding. >> After `show-ifdefs', read-only status is restored to previous value. >> >> Uses keymap "hide-ifdef-mode-map", which is not currently defined.- Hide quoted text - >> >> - Show quoted text - > > Thanks David! I tried it and I loved it except for one thing: I need > to M-x hide-ifdefs every time I open a new file. Can i add some hooks > or something like that to keep it on forever? Here's what I do for programming mode, in my .emacs: (load-library "cc-mode") (defun my-c-mode-common-hook () (c-set-style "user") (c-set-offset 'case-label '+) (c-set-offset 'substatement-open 0) (setq fill-column 75) (imenu-add-menubar-index) (add-hook 'c-mode-hook 'turn-on-cwarn-mode) (add-hook 'c-mode-hook 'hide-ifdef-mode)) (add-hook 'c-mode-common-hook 'my-c-mode-common-hook) Hope this helps. I don't really remember how I came about using this method of initialization, but its been in my .emacs file for years and years and years now. Dave