I'm trying to define a custom Python skeleton and have found there are two macros in python.el that might be of use here.

After poking around and looking at the value for python-skeleton-autoinsert it revealed there is...


python-mode-skeleton-abbrev-table is a variable defined in

[## 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 def 0 0 class 0 0 0 0 0 0 0 0 0 0 0 0 try 0 0 0 0 0 0 0 0 0 0 0 0 0 0 while 0 0 0 for 0 0 0 0 0 0]


Abbrev table for Python mode skeletons.

Value is slightly confusing but I also found...


python-define-auxiliary-skeleton is a macro defined in python.el.gz.

(python-define-auxiliary-skeleton NAME &optional DOC &rest SKEL)

Define a python-mode auxiliary skeleton using NAME DOC and SKEL.

The skeleton will be bound to python-skeleton-NAME.


My aim is to have a skeleton that inserts the following (correctly indented for the position but I think that is taken care of by the functions), getting a prompt for the <value> and inserting it so that the output is...


First Attempt

Tried the following and it evaluated without error...

;; Define a skeleton for printing
(python-define-auxiliary-skeleton print-debug
  "Insert a print statement that will show the value of the argument."
  "Enter the variable/object name: "
  "print(f\"{" str "=}\")")

Checking the value of python-mode-skeleton-abbrev-table this hasn't been added though.


  1. I don't understand what the values of &optional and &rest are so I'm unsure if I'm defining this correctly.

  2. Once I've got the definition correct how would I get this included in python-mode-skeleton-abbrev-table (or otherwise registered/recognised) so that the skeleton is available with the others (so I can bind it to a key sequence)?

1 Answer 1


If you look at the python skeleton commands, you will find their names use a single dash after the 'namespace'. Using your print-debug definition example, the created python-skeleton--print-debug has two dashes after after the namespace part. So we jump to the python-skeleton definitions (using M-x find-function). We find that they have been defined using python-skeleton-define and that python-define-auxiliary-skeleton has been used only for 'auxiliary' skeletons (skeletons used by other skeletons, like the else skeleton in the if skeleton).

So you should simpy replace python-define-auxiliary-skeleton with python-skeleton-define in your exmple definition and your code will work fine (the functions take the same arguments, and you have interpreted &optional and &rest correctly. You can find their meanings in the elisp documentation).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.