Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Writing a script to add comments to a python file
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Joshua Moore  
View profile  
 More options Jul 15 2012, 7:45 pm
Newsgroups: gnu.emacs.help
From: Joshua Moore <joshua.marshall.mo...@gmail.com>
Date: Sun, 15 Jul 2012 16:45:20 -0700 (PDT)
Local: Sun, Jul 15 2012 7:45 pm
Subject: Writing a script to add comments to a python file
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?

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, edit the lines or where to save the script.

Any help is appreciated.

--
Josh


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Bokma  
View profile  
 More options Jul 15 2012, 9:26 pm
Newsgroups: gnu.emacs.help
From: John Bokma <j...@castleamber.com>
Date: Sun, 15 Jul 2012 20:26:21 -0500
Local: Sun, Jul 15 2012 9:26 pm
Subject: Re: Writing a script to add comments to a python file

Joshua Moore <joshua.marshall.mo...@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?

It's already there. Maybe it's a better idea to find out what's all
available? A few times I wanted to add something to Emacs only to find
out (often via Google) it's already there.

Anyway:

M x comment-dwim

bound here (default) to:

M ;

> 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, edit the lines or
> where to save the script.

> Any help is appreciated.

Buy "An introduction into programming Lisp" or read it online:
http://www.gnu.org/software/emacs/emacs-lisp-intro/

--
John Bokma                                                               j3b

Blog: http://johnbokma.com/        Perl Consultancy: http://castleamber.com/
Perl for books:    http://johnbokma.com/perl/help-in-exchange-for-books.html


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jambunathan K  
View profile  
 More options Jul 15 2012, 11:35 pm
Newsgroups: gnu.emacs.help
From: Jambunathan K <kjambunat...@gmail.com>
Date: Mon, 16 Jul 2012 09:05:17 +0530
Local: Sun, Jul 15 2012 11:35 pm
Subject: Re: Writing a script to add comments to a python file

Joshua Moore <joshua.marshall.mo...@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..
--


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »