From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: How to get skills in elisp ? Date: Mon, 25 May 2009 13:01:23 +0200 Organization: Anevia SAS Message-ID: <7c3aatcupo.fsf@pbourguignon.anevia.com> References: <39c42ea3-0dc4-4364-a3b5-751b28b176b2@y7g2000yqa.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1243251656 30852 80.91.229.12 (25 May 2009 11:40:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 25 May 2009 11:40:56 +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 May 25 13:40:49 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 1M8YXw-0004W3-JV for geh-help-gnu-emacs@m.gmane.org; Mon, 25 May 2009 13:40:48 +0200 Original-Received: from localhost ([127.0.0.1]:50209 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M8YXw-0001cq-1T for geh-help-gnu-emacs@m.gmane.org; Mon, 25 May 2009 07:40:48 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!newsfeed.esat.net!dedekind.zen.co.uk!zen.net.uk!hamilton.zen.co.uk!proxad.net!feeder2-2.proxad.net!cleanfeed4-a.proxad.net!nnrp1-1.free.fr!not-for-mail Original-Newsgroups: gnu.emacs.help Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.101 (Gnus v5.10.10) Emacs/22.2 (gnu/linux) Cancel-Lock: sha1:YmFlMmZlMzBiODgwOTI0YWUwYThkNDkxYjQzMTg0YjEyM2QyNjRiZQ== Original-Lines: 100 Original-NNTP-Posting-Date: 25 May 2009 13:01:24 CEST Original-NNTP-Posting-Host: 88.170.236.224 Original-X-Trace: 1243249284 news-3.free.fr 20329 88.170.236.224:46259 Original-X-Complaints-To: abuse@proxad.net Original-Xref: news.stanford.edu gnu.emacs.help:169449 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:64682 Archived-At: Francis Moreau writes: > 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 ? 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. > Also I would like to know how people debug their scripts ? Are there > any tricks ? We don't debug, our functions are perfect the first time. The trick is bottom-up programming. > For now I just write some forms and evaluate them with 'C-j'. 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-: (point) (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. --> #("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 justification left) 69 107 (justification left fontified t) 107 111 (justification left 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 function 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 (fontified t justification left)) #("assuming" 0 8 (fontified t justification left)) #("you" 0 3 (fontified t justification left)) #("want" 0 4 (fontified t justification left)) #("to" 0 2 (fontified t justification left)) #("implement" 0 9 (fontified t justification left)) #("a" 0 1 (fontified t justification 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 justification left)) #("the" 0 3 (fontified t justification left)) #("selection," 0 10 (fontified t justification left)) #("you" 0 3 (fontified t jus tification 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 Each Word In The Selection, You Could Do: --> 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 Select the above lowercase words, M-x my-capitalize-region RET it works, no debugging. -- __Pascal Bourguignon__