all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Writing a script to add comments to a python file
@ 2012-07-15 23:45 Joshua Moore
  2012-07-16  1:26 ` John Bokma
  2012-07-16  3:35 ` Jambunathan K
  0 siblings, 2 replies; 3+ messages in thread
From: Joshua Moore @ 2012-07-15 23:45 UTC (permalink / raw)
  To: help-gnu-emacs

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Writing a script to add comments to a python file
  2012-07-15 23:45 Writing a script to add comments to a python file Joshua Moore
@ 2012-07-16  1:26 ` John Bokma
  2012-07-16  3:35 ` Jambunathan K
  1 sibling, 0 replies; 3+ messages in thread
From: John Bokma @ 2012-07-16  1:26 UTC (permalink / raw)
  To: help-gnu-emacs

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?

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Writing a script to add comments to a python file
  2012-07-15 23:45 Writing a script to add comments to a python file Joshua Moore
  2012-07-16  1:26 ` John Bokma
@ 2012-07-16  3:35 ` Jambunathan K
  1 sibling, 0 replies; 3+ messages in thread
From: Jambunathan K @ 2012-07-16  3:35 UTC (permalink / raw)
  To: Joshua Moore; +Cc: help-gnu-emacs

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



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-07-16  3:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-15 23:45 Writing a script to add comments to a python file Joshua Moore
2012-07-16  1:26 ` John Bokma
2012-07-16  3:35 ` Jambunathan K

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.