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

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

Re: Writing a script to add comments to a python file


From: Jambunathan K
Subject: Re: Writing a script to add comments to a python file
Date: Mon, 16 Jul 2012 09:05:17 +0530
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (windows-nt)

Joshua Moore <joshua.marshall.moore@gmail.com> writes:

> Hi gnu.emacs.help
>
> I've been using the basic features of emacs for a while now, and would
> like to add my own functions to it.
>
> What would be a good way to implement a command that adds a comment
> symbol (#) to a selected region in a python file?

1. Mark the region.  
2. Do a M-;.  Semi-colon is the comment char in elisp.

For more inforamtion do 
   C-h K M-;

Now that you know what the command is do a 

  M-x find-function RET comment-dwim 

and get a feel for how elisp looks like and how elaborate this generic
function is.  Remember it works in all programming modes including
python.

Then do a

  C-h i
  g Emacs Lisp Intro

Finish that tutorial in *full*.  It is well worth your time.

Now you are all set to become a full-fledged programmer.

Now go back to the `comment-dwim' implementation and see how it moves
around the buffer, modifies the buffer etc.

Last but not the least, learn to use the info manual very well.

You can also look at Emacswiki's elisp cookbook.
  http://emacswiki.org/emacs/ElispCookbook

> I can read and write a little bit of lisp-like languages, but I don't
> know how to access the region of selected text, 

C-h f interactive
C-s  region

Do you know a command that acts on region? Yes `comment-dwim'.

  C-h f comment-dwim
  See how the `r' interactive spec is used.

> edit the lines or where to save the script.

For editing lines you need to understand regexes or string related
functions.

  C-h d string

It will show up a bunch of functions that will have string in them.  Go
on a treaure hunt and pick what interests you.

You can also use the info manual.

  C-h i
  g elisp
  I string

Again, go on a treasure hunt.

> Any help is appreciated.

Remember you don't learn elisp in a day.  

You pick a pebble here, a pebble there.  Before you know your sack is
full and you have a booty worth sharing..
-- 



reply via email to

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