help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to get skills in elisp ?


From: Andreas Röhler
Subject: Re: How to get skills in elisp ?
Date: Mon, 25 May 2009 14:03:49 +0200
User-agent: Thunderbird 2.0.0.19 (X11/20081227)

Pascal J. Bourguignon wrote:
> Francis Moreau <francis.moro@gmail.com> 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 <key-stroke>
>
>
> 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 <function-name> 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.
>   

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.
>
>
>   
>> 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 justification 
> 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.
>
>
>   






reply via email to

[Prev in Thread] Current Thread [Next in Thread]