From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21517 invoked by alias); 25 Mar 2008 18:18:33 -0000 Received: (qmail 21508 invoked by uid 22791); 25 Mar 2008 18:18:32 -0000 X-Spam-Check-By: sourceware.org Received: from fk-out-0910.google.com (HELO fk-out-0910.google.com) (209.85.128.189) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 25 Mar 2008 18:18:15 +0000 Received: by fk-out-0910.google.com with SMTP id 26so4469457fkx.8 for ; Tue, 25 Mar 2008 11:18:12 -0700 (PDT) Received: by 10.82.186.19 with SMTP id j19mr21876673buf.2.1206469092377; Tue, 25 Mar 2008 11:18:12 -0700 (PDT) Received: by 10.82.162.12 with HTTP; Tue, 25 Mar 2008 11:18:12 -0700 (PDT) Message-ID: <8f2776cb0803251118o316d261erb340d67bb0580967@mail.gmail.com> Date: Tue, 25 Mar 2008 18:37:00 -0000 From: "Jim Blandy" To: "Tom Tromey" , "Thiago Jung Bauermann" , "gdb ml" Subject: Re: repo to work on python scripting support In-Reply-To: <20080325114520.GA21688@caradoc.them.org> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <1205538908.6643.138.camel@localhost.localdomain> <1206369478.29533.15.camel@localhost.localdomain> <20080325114520.GA21688@caradoc.them.org> X-Google-Sender-Auth: 69e0ecc1b94be8f6 X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2008-03/txt/msg00222.txt.bz2 It's worth putting some investment into the way arguments get handled, to make writing commands as easy as possible. For example, in Emacs Lisp, any function you write in Lisp can be turned into a command just by adding an "interactive spec" to it, which says how to prompt the user for the function's arguments. It's still just an ordinary function that you can call from Lisp code, but if you invoke it as an editing command, Emacs knows how to prompt for arguments for it. The interactive spec is either a bit of arbitrary lisp code that returns a list of arguments to pass, or just a string with magic character codes that are shorthand for the most common cases. For example, if I have a function that writes the currently selected region to a file, it might take three arguments: (start end filename) and its interactive spec might be: (interactive "rFFile to write to: ") where the 'r' passes the start and end of the currently selected region as 'start' and 'end', and the 'F' means "filename", to be prompted for with the following text. With 'F', emacs will do filename completion; with 'f', it'll do completion, and also insist that the file exists. A function that was going to read the file would use 'f'. The point here is that it becomes dirt-easy to write most of the interactive functions you'd care to. You get the interactivity out of the way and focus on the meat of your command. I don't know the most Pythonish way of doing things, but it seems to me that Python could register not functions, but objects, to be callable with $(). The object could have an 'interactive' member to specify how to call it (say, "e" might mean, evaluate an expression and pass its value to me, and "s" might mean, just hand it to me as a string), and then some other method to actually do the call. class Strcmp (GdbCommand): interactive = 'ee' def doit (expr1, expr2): // compare expr1 and expr2 as strings strcmp = Strcmp (); or something. Surely someone here is more fluent in Python than I am.