From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?ISO-8859-1?Q?Andreas_R=F6hler?= Newsgroups: gmane.emacs.help Subject: Re: How to get skills in elisp ? Date: Mon, 25 May 2009 14:03:49 +0200 Message-ID: <4A1A8925.4000705@easy-emacs.de> References: <39c42ea3-0dc4-4364-a3b5-751b28b176b2@y7g2000yqa.googlegroups.com> <7c3aatcupo.fsf@pbourguignon.anevia.com> 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 1243253002 2368 80.91.229.12 (25 May 2009 12:03:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 25 May 2009 12:03:22 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: "Pascal J. Bourguignon" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon May 25 14:03:15 2009 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 1M8Ytb-00042s-AC for geh-help-gnu-emacs@m.gmane.org; Mon, 25 May 2009 14:03:12 +0200 Original-Received: from localhost ([127.0.0.1]:44097 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M8Yta-0005v5-Ke for geh-help-gnu-emacs@m.gmane.org; Mon, 25 May 2009 08:03:10 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M8YtF-0005v0-20 for help-gnu-emacs@gnu.org; Mon, 25 May 2009 08:02:49 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M8YtA-0005uT-GF for help-gnu-emacs@gnu.org; Mon, 25 May 2009 08:02:48 -0400 Original-Received: from [199.232.76.173] (port=39930 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M8YtA-0005uL-EG for help-gnu-emacs@gnu.org; Mon, 25 May 2009 08:02:44 -0400 Original-Received: from moutng.kundenserver.de ([212.227.126.186]:57837) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1M8Yt9-00040Z-Dp for help-gnu-emacs@gnu.org; Mon, 25 May 2009 08:02:43 -0400 Original-Received: from [192.168.178.27] (p54BEB153.dip0.t-ipconnect.de [84.190.177.83]) by mrelayeu.kundenserver.de (node=mrelayeu5) with ESMTP (Nemesis) id 0ML25U-1M8Ysd1pvK-0001oh; Mon, 25 May 2009 14:02:12 +0200 User-Agent: Thunderbird 2.0.0.19 (X11/20081227) In-Reply-To: <7c3aatcupo.fsf@pbourguignon.anevia.com> X-Provags-ID: V01U2FsdGVkX19EhlbzTBjAG0UWkcKuMcNmBh0bU03Z8GZIqbu vQNblfVmkaWRXWB8Ez9WeuLxdadPZWo3ZXkzrtKtenimA8VQmp 6bk4nLX9S8MhVleWwM6FMrU2tzfeYxxzhvgU8Fbwos= X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. 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:64684 Archived-At: Pascal J. Bourguignon wrote: > Francis Moreau writes: > > =20 >> Hello, >> >> I finally took time to start learning elisp hence nobody can call me >> an dumb emacs user ;) >> >> I started by reading the info files containing the Gnu Emacs Lisp >> Reference Manual although I haven't read it entirely. >> >> But now I got the main picture of the language but I would need some >> practice since the reference manual lack of examples before I feel >> confortable enough to start writing my own elisp scripts. >> >> Could anybody give me some direction at that point ? >> =20 > > If you know an emacs key stroke, you can know what command it's bound > to with: C-h k > > > In the help window you will usually have a link to the _source_ of the > command. (You can click on it, or use TAB to move the cursor on it > and type RET). > > Some functions are implemented in C, so you may get some C source. > Not very interesting (these are the primitives of emacs lisp). Try > another command. > > If you know the name of a function, you can get its help page with: > C-h f RET When you are browsing some emacs lisp > source, you can also have the cursor positionned on a function name > and type C-h f RET. > > > > =20 >> Also I would like to know how people debug their scripts ? Are there >> any tricks ?=20 >> =20 > > We don't debug, our functions are perfect the first time. > =20 Well, after seven days or so god stopped programming because it was fine.= :) For all children born before that day however, M-x edebug-defun might be an option. Cheers > The trick is bottom-up programming. > > > =20 >> For now I just write some forms and evaluate them with 'C-j'. >> =20 > > Yes, that's what you should do. > > For example, assuming you want to implement a function to capitalize > each word in the selection, you could do: > > (let ((start 2137) (end 2248)) ; these numbers I got then using M-: (po= int) > (buffer-substring start end)) > C-u C-x C-e ; is what I type to get the result inserted in the buffer. = > ; Also C-x C-e works in any more, contrarily to C-j. > -->=20 > #("For example, assuming you want to implement a function to capitalize= > each word in the selection, you could do: > " 0 68 (justification left fontified t) 68 69 (fontified t justificatio= n left) 69 107 (justification left fontified t) 107 111 (justification le= ft fontified t)) ; This is a string with properties. > > (let ((start 2137) (end 2248)) > (split-string C-h f (buffer-substring start end)) ; after typing a fu= nction name, C-h f RET gives the help > ^^^^^^^^^^^^^^^^^^ > > (let ((start 2137) (end 2248)) > (split-string (buffer-substring start end))) > --> > (#("For" 0 3 (fontified t justification left)) #("example," 0 8 (fontif= ied t justification left)) #("assuming" 0 8 (fontified t justification le= ft)) #("you" 0 3 (fontified t justification left)) #("want" 0 4 (fontifie= d t justification left)) #("to" 0 2 (fontified t justification left)) #("= implement" 0 9 (fontified t justification left)) #("a" 0 1 (fontified t j= ustification left)) #("function" 0 8 (fontified t justification left)) #(= "to" 0 2 (fontified t justification left)) #("capitalize" 0 10 (fontified= t justification left)) #("each" 0 4 (fontified t justification left)) #(= "word" 0 4 (fontified t justification left)) #("in" 0 2 (fontified t just= ification left)) #("the" 0 3 (fontified t justification left)) #("selecti= on," 0 10 (fontified t justification left)) #("you" 0 3 (fontified t just= ification left)) #("could" 0 5 (fontified t justification left)) #("do:" = 0 3 (fontified t justification left))) > > (let ((start 2137) (end 2248)) > (dolist (word (split-string (buffer-substring start end))) > (insert (capitalize word) " "))) > > For Example, Assuming You Want To Implement A Function To Capitalize Ea= ch Word In The Selection, You Could Do:=20 > --> nil > > (let ((start 2137) (end 2248)) > (let ((text (buffer-substring start end))) > (delete-region start end) > (goto-char start) > (dolist (word (split-string text)) > (insert (capitalize word) " ")))) > > C-x C-e (it works, check between characters 2137 and 2248). > > (defun my-capitalize-region (start end) > (interactive "r") > (let ((text (buffer-substring start end))) > (delete-region start end) > (goto-char start) > (dolist (word (split-string text)) > (insert (capitalize word) " ")))) > > > Toto Foo Bar Titi Quux=20 > > Select the above lowercase words, M-x my-capitalize-region RET it > works, no debugging. > > > =20