From f5238f044d2f142f1940b93e3761e1f5bfd7ef7c Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Wed, 9 Jan 2013 11:43:10 -0500 Subject: py functions: random assingment, shebang, exit --- conf/km-func.el | 20 ++++++++++++++++++++ conf/km-python.el | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 conf/km-python.el (limited to 'conf') diff --git a/conf/km-func.el b/conf/km-func.el index 48a2f35..3366363 100644 --- a/conf/km-func.el +++ b/conf/km-func.el @@ -25,3 +25,23 @@ name (file-name-nondirectory new-name))))))) (global-set-key (kbd "C-x C-r") 'km/rename-current-buffer-file) + +(defun km/shebang (&optional lang) + (interactive "s\language (default python):") + (if (= (length lang) 0) + (setq lang "python")) + (insert "#!/usr/bin/env " lang "\n")) +(global-set-key (kbd "C-c s") 'km/shebang) + +(defun km/insert-random-string (&optional strlen) + "Insert a random string (default length: 5)" + (interactive) + (unless strlen + (setq strlen 5)) + (let (mycharset (ii 0) ) + (setq mycharset ["a" "b" "c" "d" "e" "f" "g" "h" "i" + "j" "k" "l" "m" "n" "o" "p" "q" "r" + "s" "t" "u" "v" "w" "x" "y" "z"]) + (while (< ii strlen) + (insert (elt mycharset (random (length mycharset)))) + (setq ii (1+ ii))))) diff --git a/conf/km-python.el b/conf/km-python.el new file mode 100644 index 0000000..f3d1b08 --- /dev/null +++ b/conf/km-python.el @@ -0,0 +1,18 @@ +(defun km/python-sysexit () + (interactive) + (insert "sys.exit()")) + +(defun km/python-random-assignment () + (interactive) + (km/insert-random-string 10) + (insert " = None")) + +(defun km/python-shebang () + (interactive) + (km/shebang "python")) + +(defun km/python-hook () + (local-set-key (kbd "C-c p r") 'km/python-random-assignment) + (local-set-key (kbd "C-c p e") 'km/python-sysexit) + (local-set-key (kbd "C-c p s") 'km/python-shebang)) +(add-hook 'python-mode-hook 'km/python-hook) -- cgit v1.2.3