From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jambunathan K Newsgroups: gmane.emacs.help Subject: Re: Writing a script to add comments to a python file Date: Mon, 16 Jul 2012 09:05:17 +0530 Message-ID: <81fw8swf7u.fsf@gmail.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1342409739 30975 80.91.229.3 (16 Jul 2012 03:35:39 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 16 Jul 2012 03:35:39 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Joshua Moore Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jul 16 05:35:38 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Sqc5u-0003Hg-Pz for geh-help-gnu-emacs@m.gmane.org; Mon, 16 Jul 2012 05:35:34 +0200 Original-Received: from localhost ([::1]:39402 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sqc5t-00054A-PV for geh-help-gnu-emacs@m.gmane.org; Sun, 15 Jul 2012 23:35:33 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:49653) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sqc5p-000544-2f for help-gnu-emacs@gnu.org; Sun, 15 Jul 2012 23:35:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sqc5n-0006sr-Sv for help-gnu-emacs@gnu.org; Sun, 15 Jul 2012 23:35:29 -0400 Original-Received: from mail-yw0-f41.google.com ([209.85.213.41]:38536) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sqc5n-0006rR-NX for help-gnu-emacs@gnu.org; Sun, 15 Jul 2012 23:35:27 -0400 Original-Received: by yhr47 with SMTP id 47so4896610yhr.0 for ; Sun, 15 Jul 2012 20:35:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=VDZtNKXBevOBkZAi9afCjl2K3PTrLomB107zQOXBCJc=; b=HzqdwHg4Wfq9xLdo99snI/o0HB2bdLjyaDvfEJUpMYPfP0upGRBJXBNO65BSAmydIQ kOB0tH3hB9uXKpAsxmesy/1Ey75IqLAlBRJORpZ8221IzzUf9lpLNWLENiH1eQHF7pg6 Uo9tC64/aWot3k68C5v4ZjYVlXLkzPGV7ZsuMZmVN4Qygcj5Plz9aBRXyGT32aHAey3B qlWLYQmcGXlZMZqp5Nj10handbcET/eReNGMmJMNkZH+ustmKfH6foJtHILl8UACt7C5 wqGYvQ6m/tDmgudRnMwnN3XaaiKdGoUpomcjPtyvkcq0LERiV0hhUe/Mm8aOtoE2u8/K YPCw== Original-Received: by 10.66.73.132 with SMTP id l4mr19802894pav.30.1342409726472; Sun, 15 Jul 2012 20:35:26 -0700 (PDT) Original-Received: from JAMBU-NETBOOK ([115.241.71.85]) by mx.google.com with ESMTPS id pe2sm10984189pbc.59.2012.07.15.20.35.22 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 15 Jul 2012 20:35:25 -0700 (PDT) In-Reply-To: (Joshua Moore's message of "Sun, 15 Jul 2012 16:45:20 -0700 (PDT)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (windows-nt) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.213.41 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:85875 Archived-At: Joshua Moore 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.. --