From b62854c59bcf639586d2a6e9a73bac6b2e9fcd3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20R=C3=B6hler?= Date: Tue, 7 Jul 2015 14:16:30 +0200 Subject: [PATCH] Execute-region forms reconsidered --- devel/python-mode-utils.el | 52 +++++- python-components-execute-region.el | 251 +++++++++++++++++----------- 2 files changed, 203 insertions(+), 100 deletions(-) diff --git a/devel/python-mode-utils.el b/devel/python-mode-utils.el index a99e3e4e..6c47af70 100644 --- a/devel/python-mode-utils.el +++ b/devel/python-mode-utils.el @@ -280,7 +280,7 @@ (setq py-options (list "" "switch" "no-switch" "dedicated")) -(setq py-full-options (list "switch" "no-switch" "dedicated" "dedicated-switch")) +(setq py-full-options (list "" "switch" "no-switch" "dedicated" "dedicated-switch")) (defvar py-commands (list "py-python-command" "py-ipython-command" "py-python3-command" "py-python2-command" "py-jython-command") @@ -3419,6 +3419,48 @@ Stores data in kill ring. Might be yanked back using `C-y'. \" (write-file (concat py-install-directory "/python-components-narrow.el"))) +;; python-components-execute-region +(defun write--execute-region () + (dolist (ele py-shells) + (setq ele (format "%s" ele)) + (dolist (pyo py-full-options) + (insert "(defun py-execute-region") + (unless (string= "" ele) (insert (concat "-" ele))) + (unless (string= "" pyo) (insert (concat "-" pyo))) + (insert (concat " (beg end &optional shell filename proc file) + \"Execute region " ele)) + (insert ".\" + (interactive \"r\")\n") + (unless (string= "" pyo) + (insert " (let (") + (py--insert-split-switch-forms pyo) + (insert ")\n ")) + (insert " (py--execute-base beg end ") + (if (string= "" ele) + (insert "shell") + (insert (concat "'" ele))) + (insert " filename proc file))") + (unless (string= "" pyo)(insert ")")) + (insert "\n\n") + ))) + +(defun py-write-execute-region () + "Uses `py-execute-region-forms'. " + (interactive) + (set-buffer (get-buffer-create "python-components-execute-region.el")) + (erase-buffer) + (insert ";;; python-components-execute-region.el --- execute-region forms\n") + (insert arkopf) + (when (called-interactively-p 'any) (switch-to-buffer (current-buffer)) + (emacs-lisp-mode)) + (write--execute-region) + (insert "(provide 'python-components-execute-region) +;;; python-components-execute-region.el ends here\n") + (write-file (concat py-install-directory "/python-components-execute-region.el"))) + + + + (defun py--insert-split-switch-doku (pyo) (cond ((string= pyo "switch") (insert "Switch to output buffer. Ignores `py-switch-buffers-on-execute-p'. ")) @@ -3429,12 +3471,17 @@ Stores data in kill ring. Might be yanked back using `C-y'. \" (cond ((string= pyo "switch") ;; (insert (make-string 2 ?\ )) (insert "(py-switch-buffers-on-execute-p t)")) + ((string= pyo "dedicated-switch") + ;; (insert (make-string 2 ?\ )) + (insert "(py-switch-buffers-on-execute-p t)\n") + (insert (make-string 8 ?\ )) + (insert "(py-split-window-on-execute t)")) ((string= pyo "no-switch") ;; (insert (make-string 2 ?\ )) (insert "(py-switch-buffers-on-execute-p nil)")) ((string= pyo "dedicated") ;; (insert (make-string 2 ?\ )) - (insert "(py-dedicated-process-p t)")))) + (insert "(py-dedicated-process-p t)")))) (defun write-most-of-forms () "Let's see if we can write/update forms at once. " @@ -3454,6 +3501,7 @@ Stores data in kill ring. Might be yanked back using `C-y'. \" (py-write-mark-forms) (py-write-up-down-forms) (py-write-execute-forms) + (py-write-execute-region) ;; (py-write-edit-forms) ;; (write-execute-region-forms) ) diff --git a/python-components-execute-region.el b/python-components-execute-region.el index 6932df7e..c98531c9 100644 --- a/python-components-execute-region.el +++ b/python-components-execute-region.el @@ -1,9 +1,8 @@ -;;; python-components-execute-region.el --- Execute region forms +;;; python-components-execute-region.el --- execute-region forms ;; Copyright (C) 2015 Andreas Röhler ;; Author: Andreas Röhler - ;; Keywords: languages, convenience ;; This program is free software; you can redistribute it and/or modify @@ -26,189 +25,245 @@ ;;; Code: -(defun py-execute-region (beg end) - "Execute region. " +(defun py-execute-region (beg end &optional shell filename proc file) + "Execute region ." (interactive "r") - (py--execute-base beg end)) + (py--execute-base beg end shell filename proc file)) -(defun py-execute-region-switch (beg end) - "Execute region switch. " +(defun py-execute-region-switch (beg end &optional shell filename proc file) + "Execute region ." (interactive "r") (let ((py-switch-buffers-on-execute-p t)) - (py--execute-base beg end))) + (py--execute-base beg end shell filename proc file))) -(defun py-execute-region-no-switch (beg end) - "Execute region no-switch. " +(defun py-execute-region-no-switch (beg end &optional shell filename proc file) + "Execute region ." (interactive "r") (let ((py-switch-buffers-on-execute-p nil)) - (py--execute-base beg end))) + (py--execute-base beg end shell filename proc file))) -(defun py-execute-region-dedicated (beg end) - "Execute region dedicated. " +(defun py-execute-region-dedicated (beg end &optional shell filename proc file) + "Execute region ." (interactive "r") (let ((py-dedicated-process-p t)) - (py--execute-base beg end))) + (py--execute-base beg end shell filename proc file))) + +(defun py-execute-region-dedicated-switch (beg end &optional shell filename proc file) + "Execute region ." + (interactive "r") + (let ((py-switch-buffers-on-execute-p t) + (py-split-window-on-execute t)) + (py--execute-base beg end shell filename proc file))) -(defun py-execute-region-python (beg end) - "Execute region Python. " +(defun py-execute-region-ipython (beg end &optional shell filename proc file) + "Execute region ipython." (interactive "r") - (py--execute-base beg end "python")) + (py--execute-base beg end 'ipython filename proc file)) -(defun py-execute-region-python-switch (beg end) - "Execute region Python switch. " +(defun py-execute-region-ipython-switch (beg end &optional shell filename proc file) + "Execute region ipython." (interactive "r") (let ((py-switch-buffers-on-execute-p t)) - (py--execute-base beg end "python"))) + (py--execute-base beg end 'ipython filename proc file))) -(defun py-execute-region-python-no-switch (beg end) - "Execute region Python no-switch. " +(defun py-execute-region-ipython-no-switch (beg end &optional shell filename proc file) + "Execute region ipython." (interactive "r") (let ((py-switch-buffers-on-execute-p nil)) - (py--execute-base beg end "python"))) + (py--execute-base beg end 'ipython filename proc file))) -(defun py-execute-region-python-dedicated (beg end) - "Execute region Python dedicated. " +(defun py-execute-region-ipython-dedicated (beg end &optional shell filename proc file) + "Execute region ipython." (interactive "r") (let ((py-dedicated-process-p t)) - (py--execute-base beg end "python"))) + (py--execute-base beg end 'ipython filename proc file))) + +(defun py-execute-region-ipython-dedicated-switch (beg end &optional shell filename proc file) + "Execute region ipython." + (interactive "r") + (let ((py-switch-buffers-on-execute-p t) + (py-split-window-on-execute t)) + (py--execute-base beg end 'ipython filename proc file))) -(defun py-execute-region-python2 (beg end) - "Execute region Python2. " +(defun py-execute-region-ipython2.7 (beg end &optional shell filename proc file) + "Execute region ipython2.7." (interactive "r") - (py--execute-base beg end "python2")) + (py--execute-base beg end 'ipython2.7 filename proc file)) -(defun py-execute-region-python2-switch (beg end) - "Execute region Python2 switch. " +(defun py-execute-region-ipython2.7-switch (beg end &optional shell filename proc file) + "Execute region ipython2.7." (interactive "r") (let ((py-switch-buffers-on-execute-p t)) - (py--execute-base beg end "python2"))) + (py--execute-base beg end 'ipython2.7 filename proc file))) -(defun py-execute-region-python2-no-switch (beg end) - "Execute region Python2 no-switch. " +(defun py-execute-region-ipython2.7-no-switch (beg end &optional shell filename proc file) + "Execute region ipython2.7." (interactive "r") (let ((py-switch-buffers-on-execute-p nil)) - (py--execute-base beg end "python2"))) + (py--execute-base beg end 'ipython2.7 filename proc file))) -(defun py-execute-region-python2-dedicated (beg end) - "Execute region Python2 dedicated. " +(defun py-execute-region-ipython2.7-dedicated (beg end &optional shell filename proc file) + "Execute region ipython2.7." (interactive "r") (let ((py-dedicated-process-p t)) - (py--execute-base beg end "python2"))) + (py--execute-base beg end 'ipython2.7 filename proc file))) -(defun py-execute-region-python3 (beg end) - "Execute region Python3. " +(defun py-execute-region-ipython2.7-dedicated-switch (beg end &optional shell filename proc file) + "Execute region ipython2.7." (interactive "r") - (py--execute-base beg end "python3")) + (let ((py-switch-buffers-on-execute-p t) + (py-split-window-on-execute t)) + (py--execute-base beg end 'ipython2.7 filename proc file))) -(defun py-execute-region-python3-switch (beg end) - "Execute region Python3 switch. " +(defun py-execute-region-ipython3 (beg end &optional shell filename proc file) + "Execute region ipython3." + (interactive "r") + (py--execute-base beg end 'ipython3 filename proc file)) + +(defun py-execute-region-ipython3-switch (beg end &optional shell filename proc file) + "Execute region ipython3." (interactive "r") (let ((py-switch-buffers-on-execute-p t)) - (py--execute-base beg end "python3"))) + (py--execute-base beg end 'ipython3 filename proc file))) -(defun py-execute-region-python3-no-switch (beg end) - "Execute region Python3 no-switch. " +(defun py-execute-region-ipython3-no-switch (beg end &optional shell filename proc file) + "Execute region ipython3." (interactive "r") (let ((py-switch-buffers-on-execute-p nil)) - (py--execute-base beg end "python3"))) + (py--execute-base beg end 'ipython3 filename proc file))) -(defun py-execute-region-python3-dedicated (beg end) - "Execute region Python3 dedicated. " +(defun py-execute-region-ipython3-dedicated (beg end &optional shell filename proc file) + "Execute region ipython3." (interactive "r") (let ((py-dedicated-process-p t)) - (py--execute-base beg end "python3"))) + (py--execute-base beg end 'ipython3 filename proc file))) + +(defun py-execute-region-ipython3-dedicated-switch (beg end &optional shell filename proc file) + "Execute region ipython3." + (interactive "r") + (let ((py-switch-buffers-on-execute-p t) + (py-split-window-on-execute t)) + (py--execute-base beg end 'ipython3 filename proc file))) -(defun py-execute-region-ipython (beg end) - "Execute region IPython. " +(defun py-execute-region-jython (beg end &optional shell filename proc file) + "Execute region jython." (interactive "r") - (py--execute-base beg end "ipython")) + (py--execute-base beg end 'jython filename proc file)) -(defun py-execute-region-ipython-switch (beg end) - "Execute region IPython switch. " +(defun py-execute-region-jython-switch (beg end &optional shell filename proc file) + "Execute region jython." (interactive "r") (let ((py-switch-buffers-on-execute-p t)) - (py--execute-base beg end "ipython"))) + (py--execute-base beg end 'jython filename proc file))) -(defun py-execute-region-ipython-no-switch (beg end) - "Execute region IPython no-switch. " +(defun py-execute-region-jython-no-switch (beg end &optional shell filename proc file) + "Execute region jython." (interactive "r") (let ((py-switch-buffers-on-execute-p nil)) - (py--execute-base beg end "ipython"))) + (py--execute-base beg end 'jython filename proc file))) -(defun py-execute-region-ipython-dedicated (beg end) - "Execute region IPython dedicated. " +(defun py-execute-region-jython-dedicated (beg end &optional shell filename proc file) + "Execute region jython." (interactive "r") (let ((py-dedicated-process-p t)) - (py--execute-base beg end "ipython"))) + (py--execute-base beg end 'jython filename proc file))) -(defun py-execute-region-ipython2.7 (beg end) - "Execute region IPython2.7. " +(defun py-execute-region-jython-dedicated-switch (beg end &optional shell filename proc file) + "Execute region jython." (interactive "r") - (py--execute-base beg end "ipython2.7")) + (let ((py-switch-buffers-on-execute-p t) + (py-split-window-on-execute t)) + (py--execute-base beg end 'jython filename proc file))) -(defun py-execute-region-ipython2.7-switch (beg end) - "Execute region IPython2.7 switch. " +(defun py-execute-region-python (beg end &optional shell filename proc file) + "Execute region python." + (interactive "r") + (py--execute-base beg end 'python filename proc file)) + +(defun py-execute-region-python-switch (beg end &optional shell filename proc file) + "Execute region python." (interactive "r") (let ((py-switch-buffers-on-execute-p t)) - (py--execute-base beg end "ipython2.7"))) + (py--execute-base beg end 'python filename proc file))) -(defun py-execute-region-ipython2.7-no-switch (beg end) - "Execute region IPython2.7 no-switch. " +(defun py-execute-region-python-no-switch (beg end &optional shell filename proc file) + "Execute region python." (interactive "r") (let ((py-switch-buffers-on-execute-p nil)) - (py--execute-base beg end "ipython2.7"))) + (py--execute-base beg end 'python filename proc file))) -(defun py-execute-region-ipython2.7-dedicated (beg end) - "Execute region IPython2.7 dedicated. " +(defun py-execute-region-python-dedicated (beg end &optional shell filename proc file) + "Execute region python." (interactive "r") (let ((py-dedicated-process-p t)) - (py--execute-base beg end "ipython2.7"))) + (py--execute-base beg end 'python filename proc file))) + +(defun py-execute-region-python-dedicated-switch (beg end &optional shell filename proc file) + "Execute region python." + (interactive "r") + (let ((py-switch-buffers-on-execute-p t) + (py-split-window-on-execute t)) + (py--execute-base beg end 'python filename proc file))) -(defun py-execute-region-ipython3 (beg end) - "Execute region IPython3. " +(defun py-execute-region-python2 (beg end &optional shell filename proc file) + "Execute region python2." (interactive "r") - (py--execute-base beg end "ipython3")) + (py--execute-base beg end 'python2 filename proc file)) -(defun py-execute-region-ipython3-switch (beg end) - "Execute region IPython3 switch. " +(defun py-execute-region-python2-switch (beg end &optional shell filename proc file) + "Execute region python2." (interactive "r") (let ((py-switch-buffers-on-execute-p t)) - (py--execute-base beg end "ipython3"))) + (py--execute-base beg end 'python2 filename proc file))) -(defun py-execute-region-ipython3-no-switch (beg end) - "Execute region IPython3 no-switch. " +(defun py-execute-region-python2-no-switch (beg end &optional shell filename proc file) + "Execute region python2." (interactive "r") (let ((py-switch-buffers-on-execute-p nil)) - (py--execute-base beg end "ipython3"))) + (py--execute-base beg end 'python2 filename proc file))) -(defun py-execute-region-ipython3-dedicated (beg end) - "Execute region IPython3 dedicated. " +(defun py-execute-region-python2-dedicated (beg end &optional shell filename proc file) + "Execute region python2." (interactive "r") (let ((py-dedicated-process-p t)) - (py--execute-base beg end "ipython3"))) + (py--execute-base beg end 'python2 filename proc file))) -(defun py-execute-region-jython (beg end) - "Execute region Jython. " +(defun py-execute-region-python2-dedicated-switch (beg end &optional shell filename proc file) + "Execute region python2." (interactive "r") - (py--execute-base beg end "jython")) + (let ((py-switch-buffers-on-execute-p t) + (py-split-window-on-execute t)) + (py--execute-base beg end 'python2 filename proc file))) -(defun py-execute-region-jython-switch (beg end) - "Execute region Jython switch. " +(defun py-execute-region-python3 (beg end &optional shell filename proc file) + "Execute region python3." + (interactive "r") + (py--execute-base beg end 'python3 filename proc file)) + +(defun py-execute-region-python3-switch (beg end &optional shell filename proc file) + "Execute region python3." (interactive "r") (let ((py-switch-buffers-on-execute-p t)) - (py--execute-base beg end "jython"))) + (py--execute-base beg end 'python3 filename proc file))) -(defun py-execute-region-jython-no-switch (beg end) - "Execute region Jython no-switch. " +(defun py-execute-region-python3-no-switch (beg end &optional shell filename proc file) + "Execute region python3." (interactive "r") (let ((py-switch-buffers-on-execute-p nil)) - (py--execute-base beg end "jython"))) + (py--execute-base beg end 'python3 filename proc file))) -(defun py-execute-region-jython-dedicated (beg end) - "Execute region Jython dedicated. " +(defun py-execute-region-python3-dedicated (beg end &optional shell filename proc file) + "Execute region python3." (interactive "r") (let ((py-dedicated-process-p t)) - (py--execute-base beg end "jython"))) + (py--execute-base beg end 'python3 filename proc file))) + +(defun py-execute-region-python3-dedicated-switch (beg end &optional shell filename proc file) + "Execute region python3." + (interactive "r") + (let ((py-switch-buffers-on-execute-p t) + (py-split-window-on-execute t)) + (py--execute-base beg end 'python3 filename proc file))) (provide 'python-components-execute-region) ;;; python-components-execute-region.el ends here