Joshua Moore <joshua.marshall.mo...
> 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
Then do a
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.
> 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
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
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.
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..