Your favorite Python-related (X)Emacs thingamajiks?

  • Thread starter Edvard Majakari
  • Start date
E

Edvard Majakari

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";
 
P

Peter Milliken

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top