form inserting print

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

form inserting print

Andreas Röhler-2
Hi python-mode folks,

form below should speed up writing print-statements in Python a
little bit.

(defun druck (&optional arg)
  "Inserts a print statement out of current `(car kill-ring)' by default, inserts ARG instead if delivered. "
  (interactive "*")
  (lexical-let* ((name (or arg (car kill-ring)))
                (form (cond ((eq major-mode 'python-mode)
                            (concat "print \"" name ": %s \" % " name)))))
    (insert form)))

Opinions?

Cheers

Andreas

--
https://code.launchpad.net/~a-roehler/python-mode
https://code.launchpad.net/s-x-emacs-werkstatt/
_______________________________________________
Python-mode mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-mode
Reply | Threaded
Open this post in threaded view
|

Re: form inserting print

Georg Brandl-3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am 12.03.2010 10:51, schrieb Andreas Roehler:

> Hi python-mode folks,
>
> form below should speed up writing print-statements in Python a
> little bit.
>
> (defun druck (&optional arg)
>   "Inserts a print statement out of current `(car kill-ring)' by default, inserts ARG instead if delivered. "
>   (interactive "*")
>   (lexical-let* ((name (or arg (car kill-ring)))
>                 (form (cond ((eq major-mode 'python-mode)
>                             (concat "print \"" name ": %s \" % " name)))))
>     (insert form)))
>
> Opinions?

Wouldn't that be the job of one of the numerous snippet packages that are
floating around?  I'm using yasnippet myself, and it works very well.
(I know that python.el has some definitions for skeleton mode, but
python-mode.el doesn't, and I'm not sure it should.)

Georg
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)

iEYEARECAAYFAkuaFbAACgkQN9GcIYhpnLDOGgCgsLnSpHSv000OzmCvrxwZDXzx
cwQAni9nFX3hIeZ3Di3bCtVHaCAClnlm
=Syty
-----END PGP SIGNATURE-----
_______________________________________________
Python-mode mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-mode
Reply | Threaded
Open this post in threaded view
|

Re: form inserting print

Barry Warsaw
On Mar 12, 2010, at 11:21 AM, Georg Brandl wrote:

>Wouldn't that be the job of one of the numerous snippet packages that are
>floating around?  I'm using yasnippet myself, and it works very well.
>(I know that python.el has some definitions for skeleton mode, but
>python-mode.el doesn't, and I'm not sure it should.)

I'm not sure either.  python-mode.el does contain some hooks for imenu so
there's some precedence.  I guess if we're going to support such
functionality, it should be via standard available hooks.

I don't use stuff like that much though, so I don't have a strong opinion
either way.

-Barry

_______________________________________________
Python-mode mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-mode

signature.asc (853 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: form inserting print

Andreas Röhler-2
In reply to this post by Georg Brandl-3
Georg Brandl wrote:

> Am 12.03.2010 10:51, schrieb Andreas Roehler:
>> Hi python-mode folks,
>
>> form below should speed up writing print-statements in Python a
>> little bit.
>
>> (defun druck (&optional arg)
>>   "Inserts a print statement out of current `(car kill-ring)' by default, inserts ARG instead if delivered. "
>>   (interactive "*")
>>   (lexical-let* ((name (or arg (car kill-ring)))
>>                 (form (cond ((eq major-mode 'python-mode)
>>                             (concat "print \"" name ": %s \" % " name)))))
>>     (insert form)))
>
>> Opinions?
>
> Wouldn't that be the job of one of the numerous snippet packages that are
> floating around?

Probably.

 I'm using yasnippet myself, and it works very well.

For me too.

> (I know that python.el has some definitions for skeleton mode, but
> python-mode.el doesn't, and I'm not sure it should.)

Thanks for the hint.

`python-expand-template' works fine for me. For conditionals starting with `if' or `try' it
should pay having it.

Andreas

>
> Georg
_______________________________________________
Python-mode mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-mode
Reply | Threaded
Open this post in threaded view
|

Re: form inserting print

Andreas Röhler-2
In reply to this post by Barry Warsaw
Barry Warsaw wrote:

> On Mar 12, 2010, at 11:21 AM, Georg Brandl wrote:
>
>> Wouldn't that be the job of one of the numerous snippet packages that are
>> floating around?  I'm using yasnippet myself, and it works very well.
>> (I know that python.el has some definitions for skeleton mode, but
>> python-mode.el doesn't, and I'm not sure it should.)
>
> I'm not sure either.  python-mode.el does contain some hooks for imenu so
> there's some precedence.  I guess if we're going to support such
> functionality, it should be via standard available hooks.
>
> I don't use stuff like that much though, so I don't have a strong opinion
> either way.
>
> -Barry


Hi Barry,

created a new branch, added skeletons inserting
compound statements from python.el

Thought it's easier to debug/maintain having it in a
separate file `python-mode-skeletons.el'

Below a bash-script used for checking. RET or
<space> should start the skeleton.

Cheers

Andreas

--
https://code.launchpad.net/~a-roehler/python-mode
https://code.launchpad.net/s-x-emacs-werkstatt/

;;;;;;;;;;;;;

LOCAL_PYTHON_BRANCH_PATH= ... edit

emacs -q -L $HOME/$LOCAL_PYTHON_BRANCH_PATH --debug-init -l $HOME/${LOCAL_PYTHON_BRANCH_PATH}/python-mode.el --find-file=$HOME/my-test.py --eval=\"(erase-buffer)\" --eval=\"(abbrev-mode 1)\" --eval='(insert \"for\")' --funcall=describe-mode &"


_______________________________________________
Python-mode mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-mode