Your favorite Python-related (X)Emacs thingamajiks?

Discussion in 'Python' started by Edvard Majakari, Mar 2, 2004.

  1. I just thought to share mine:

    (define-skeleton esm-skel-python-def
    "Inserts a new python function definition at point."
    "method name: "
    "def " str
    "("
    ("argument, %s: "
    str & ", ") & -2 & "):" | -1 & "():"
    \n
    >"\"\"\"" ("comment: " str) ".\"\"\"" \n)


    (define-abbrev python-mode-abbrev-table "def" "" 'esm-skel-python-def)

    It's not very neat, but it does create a simple, consistent Python def
    whenever you type 'def ' and prompts for a name, list of arguments and
    comment for the method. Some day I'll try to make it more intelligent and
    automatically add 'self' as the first parameter, if I'm inside a class.

    --
    # Edvard Majakari Software Engineer
    # PGP PUBLIC KEY available Soli Deo Gloria!

    $_ = '456476617264204d616a616b6172692c20612043687269737469616e20'; print
    join('',map{chr hex}(split/(\w{2})/)),uc substr(crypt(60281449,'es'),2,4),"\n";
     
    Edvard Majakari, Mar 2, 2004
    #1
    1. Advertising

  2. If you're interested in code abbreviations (aka skeletons) then you might
    want to look at ELSE - it has a (reasonably) complete set of definitions for
    the entire Python language. It's well documented (40+ page users manual) and
    you don't need any funny unreadable hieroglyphics to create a new construct
    like you do with skeleton.el :) e.g. the following is the definition of a
    Python def statement in ELSE's template language:

    DEFINE PLACEHOLDER FUNCDEF -
    /LANGUAGE="Python" -
    /NOAUTO_SUBSTITUTE -
    /DESCRIPTION=""
    /DUPLICATION=CONTEXT_DEPENDENT -
    /SEPARATOR="" -
    /TYPE=NONTERMINAL -

    "def {identifier} ([defparameter]...):"
    " [document_string]"
    " {statement}..."
    ""

    END DEFINE

    ELSE provides commands to navigate backwards and forwards between
    placeholders (the text enclosed by {}'s and []'s - which are [obviously]
    persistent BTW, you don't "lose" them between edit sessions or by expanding
    a new abbreviation like you do with skeleton.el) and when you start typing
    into one of them it gets deleted automatically and replaced by the
    characters being typed.

    It can be viewed and downloaded at http://www.zipworld.com.au/~peterm

    Regards,
    Peter


    "Edvard Majakari" <> wrote in message
    news:...
    >
    > I just thought to share mine:
    >
    > (define-skeleton esm-skel-python-def
    > "Inserts a new python function definition at point."
    > "method name: "
    > "def " str
    > "("
    > ("argument, %s: "
    > str & ", ") & -2 & "):" | -1 & "():"
    > \n
    > >"\"\"\"" ("comment: " str) ".\"\"\"" \n)

    >
    > (define-abbrev python-mode-abbrev-table "def" "" 'esm-skel-python-def)
    >
    > It's not very neat, but it does create a simple, consistent Python def
    > whenever you type 'def ' and prompts for a name, list of arguments and
    > comment for the method. Some day I'll try to make it more intelligent and
    > automatically add 'self' as the first parameter, if I'm inside a class.
    >
    > --
    > # Edvard Majakari Software Engineer
    > # PGP PUBLIC KEY available Soli Deo Gloria!
    >
    > $_ = '456476617264204d616a616b6172692c20612043687269737469616e20'; print
    > join('',map{chr hex}(split/(\w{2})/)),uc

    substr(crypt(60281449,'es'),2,4),"\n";
    >
     
    Peter Milliken, Mar 2, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. clintonG

    Your Favorite RegEx Library?

    clintonG, Oct 8, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    391
    Frankie
    Oct 8, 2005
  2. clintonG
    Replies:
    8
    Views:
    523
    =?Utf-8?B?TWFyZHk=?=
    Jan 11, 2006
  3. Matt
    Replies:
    40
    Views:
    1,836
    Ioannis Vranos
    Apr 21, 2004
  4. Admin
    Replies:
    28
    Views:
    752
    Tim Lesher
    Jul 25, 2005
  5. Chris Rebert

    Re: Your Favorite Python Book

    Chris Rebert, May 11, 2009, in forum: Python
    Replies:
    3
    Views:
    294
    Lou Pecora
    May 15, 2009
Loading...

Share This Page