Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: "Jim Blandy" <jimb@red-bean.com>
To: "Tom Tromey" <tromey@redhat.com>,
	 	"Thiago Jung Bauermann" <bauerman@br.ibm.com>,
	 	"gdb ml" <gdb@sourceware.org>
Subject: Re: repo to work on python scripting support
Date: Tue, 25 Mar 2008 18:37:00 -0000	[thread overview]
Message-ID: <8f2776cb0803251118o316d261erb340d67bb0580967@mail.gmail.com> (raw)
In-Reply-To: <20080325114520.GA21688@caradoc.them.org>

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.


  reply	other threads:[~2008-03-25 18:18 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-16  0:42 Thiago Jung Bauermann
2008-03-16  2:55 ` Tom Tromey
2008-03-24 17:16   ` Thiago Jung Bauermann
2008-03-25 11:45     ` Tom Tromey
2008-03-25 13:53       ` Daniel Jacobowitz
2008-03-25 18:37         ` Jim Blandy [this message]
2008-03-25 18:52           ` Daniel Jacobowitz
2008-03-25 18:53             ` Jim Blandy
2008-03-25 19:18             ` Tom Tromey
2008-03-27  6:41               ` Jim Blandy
2008-03-27 17:57                 ` Paul Koning
2008-03-25 19:31           ` Paul Koning
2008-03-25 20:18             ` Tom Tromey
2008-03-25 20:31               ` Paul Koning
2008-03-26  3:23                 ` Tom Tromey
2008-03-26 12:55                 ` Jim Blandy
2008-03-26 17:29                   ` Paul Koning
2008-03-26 17:58                     ` Daniel Jacobowitz
2008-03-26 18:41                     ` Tom Tromey
2008-03-26 20:04                       ` Paul Koning
2008-03-26 22:45                     ` Jim Blandy
2008-03-26 18:05       ` Doug Evans
2008-03-26 18:13         ` Daniel Jacobowitz
2008-03-26 18:25           ` Tom Tromey
2008-03-26 18:41             ` Daniel Jacobowitz
2008-03-26 18:55               ` Tom Tromey
2008-03-26 20:57                 ` Daniel Jacobowitz
2008-03-26 21:01                 ` Thiago Jung Bauermann
2008-03-27 14:11           ` Jim Blandy
2008-03-27 16:49             ` Paul Koning
2008-03-26 18:23         ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8f2776cb0803251118o316d261erb340d67bb0580967@mail.gmail.com \
    --to=jimb@red-bean.com \
    --cc=bauerman@br.ibm.com \
    --cc=gdb@sourceware.org \
    --cc=tromey@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox