From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tim X Newsgroups: gmane.emacs.help Subject: Re: elisp questions for Advanced Closing brackets function Date: Wed, 21 May 2008 19:09:33 +1000 Organization: Rapt Technologies Message-ID: <87od70vx9u.fsf@lion.rapttech.com.au> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1211363751 22977 80.91.229.12 (21 May 2008 09:55:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 21 May 2008 09:55:51 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed May 21 11:56:24 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 1Jyl3X-0003UR-Pp for geh-help-gnu-emacs@m.gmane.org; Wed, 21 May 2008 11:56:24 +0200 Original-Received: from localhost ([127.0.0.1]:32878 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jyl2n-0006g9-4s for geh-help-gnu-emacs@m.gmane.org; Wed, 21 May 2008 05:55:37 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local02.nntp.dca.giganews.com!nntp.posted.internode!news.posted.internode.POSTED!not-for-mail Original-NNTP-Posting-Date: Wed, 21 May 2008 04:09:34 -0500 Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) Cancel-Lock: sha1:y/TgnQf2beYc06BLTEYTkJuX/z0= Original-Lines: 56 X-Usenet-Provider: http://www.giganews.com Original-NNTP-Posting-Host: 121.44.102.171 Original-X-Trace: sv3-ojiSGhckkAUO18cy9dLCrCiCZVsuPMykPGox1i55Pqb9wtG3HydKZoRNFwTQAYYc2BY5mN8n9kvLU8u!IyVCCiEjeA9e4/8RvhmcIgTDmy4kh1uyKgmGR85nzEL2NP49LRtR98m2z+4yRv15t15UuaEBT7s= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.39 Original-Xref: news.stanford.edu gnu.emacs.help:158830 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:54197 Archived-At: TheLonelyStar writes: > Hi, > > I have funtions in my .emacs, which inserts "[]" when one types "[" (and > same for "(" and "{"). > I also have functions which just jumps over a "]" when "]" is typed. > I want to make this function more advanced! > It should do the following: > When one types "]" it looks for the next character which is NOT a > whitespace. If it is "]", the functions just jumps after this. Otherwise it > inserts an "]". > I am just lerning elisp (just for this), but I am stuck. > My Problems: > - How do I check if the character under (point) is a whitespace? Read the emacs lisp reference manual on syntax tables. > - In an "if" statement, how do I put more than one expression into the else > case? Like this: > (if condition (do-if-case) ((do-else-case) (do-more-else-case)) You may be a little confused. The if statement only allows one expression in the 'if' part, but you can have multiple expressions in the else part - just put them inside a (). Note also that you should look at progn. Often, lisp style tends to use other conditional constructs when multiple expressions need to be executed, such as cond. Again, reading existing code will help you identify the more common idioms. > - If I have a funcion like this: > (defun adanced-closing-bracket (arg) > ...) > How do I compare (arg) to the character under point? > I'd strongly recommend you read the emacs lisp reference manual and you may get a bit out of Robert J Chassell's Introduction to Emacs Lisp. both are now bundled with emacs, but both can be found on the gnu website. I would also recommend checking out the emacs wiki. I realise you are doing much of this as a learning exercise, but I'm not sure how much you realise you are re-inventing an already overworked wheel. have a look at paredit mode. also, check what features emacs already has. In many cases all of this stuff is already there and of course, with source code. You can look at the code an learn a lot of useful techniques and tricks. tim -- tcross (at) rapttech dot com dot au