all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: pjb@informatimago.com (Pascal J. Bourguignon)
To: help-gnu-emacs@gnu.org
Subject: Re: How to get skills in elisp ?
Date: Mon, 25 May 2009 13:01:23 +0200	[thread overview]
Message-ID: <7c3aatcupo.fsf@pbourguignon.anevia.com> (raw)
In-Reply-To: 39c42ea3-0dc4-4364-a3b5-751b28b176b2@y7g2000yqa.googlegroups.com

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


  parent reply	other threads:[~2009-05-25 11:01 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-25  7:30 How to get skills in elisp ? Francis Moreau
2009-05-25  8:17 ` Drew Adams
     [not found] ` <mailman.7753.1243239425.31690.help-gnu-emacs@gnu.org>
2009-05-25  9:15   ` Francis Moreau
2009-05-25 10:22     ` Pascal J. Bourguignon
2009-05-25 11:50     ` Andreas Röhler
2009-05-25 12:42     ` Richard Riley
2009-05-25 13:51       ` Pascal J. Bourguignon
2009-05-25 14:18         ` Richard Riley
2009-05-26  7:58       ` Francis Moreau
2009-05-25 17:11     ` Drew Adams
     [not found]     ` <mailman.7774.1243271469.31690.help-gnu-emacs@gnu.org>
2009-05-25 19:41       ` Francis Moreau
2009-05-25 20:52         ` Drew Adams
2009-05-25 10:04 ` Tassilo Horn
2009-05-25 11:01 ` Pascal J. Bourguignon [this message]
2009-05-25 12:03   ` Andreas Röhler
2009-05-27 13:05   ` Thien-Thi Nguyen
  -- strict thread matches above, loose matches on Subject: below --
2009-05-28  7:09 Benjamin Badgley
2009-05-28 15:55 ` Drew Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7c3aatcupo.fsf@pbourguignon.anevia.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.