From d2190c5795c2848f144ab034b4b397d51c89f5c4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fabi=C3=A1n=20Ezequiel=20Gallina?= Date: Thu, 17 May 2012 00:03:24 -0300 Subject: [PATCH] New function python-clone-local-variables Copied from org.el: it allows the `python-shell-make-comint' to be simplified. It copies all local variables from a buffer to the current. --- lisp/progmodes/python.el | 56 ++++++++++++---------------------------- 1 file changed, 16 insertions(+), 40 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 3d25f0b46c8..7ded2c897a8 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -1266,48 +1266,10 @@ non-nil the buffer is shown." (let* ((cmdlist (split-string-and-unquote cmd)) (buffer (apply 'make-comint proc-name (car cmdlist) nil (cdr cmdlist))) - (python-shell-interpreter-1 python-shell-interpreter) - (python-shell-interpreter-args-1 python-shell-interpreter-args) - (python-shell-prompt-regexp-1 python-shell-prompt-regexp) - (python-shell-prompt-output-regexp-1 - python-shell-prompt-output-regexp) - (python-shell-prompt-block-regexp-1 - python-shell-prompt-block-regexp) - (python-shell-completion-setup-code-1 - python-shell-completion-setup-code) - (python-shell-completion-string-code-1 - python-shell-completion-string-code) - (python-eldoc-setup-code-1 python-eldoc-setup-code) - (python-eldoc-string-code-1 python-eldoc-string-code) - (python-ffap-setup-code-1 python-ffap-setup-code) - (python-ffap-string-code-1 python-ffap-string-code) - (python-shell-setup-codes-1 python-shell-setup-codes)) + (current-buffer (current-buffer))) (with-current-buffer buffer (inferior-python-mode) - (set (make-local-variable 'python-shell-interpreter) - python-shell-interpreter-1) - (set (make-local-variable 'python-shell-interpreter-args) - python-shell-interpreter-args-1) - (set (make-local-variable 'python-shell-prompt-regexp) - python-shell-prompt-regexp-1) - (set (make-local-variable 'python-shell-prompt-output-regexp) - python-shell-prompt-output-regexp-1) - (set (make-local-variable 'python-shell-prompt-block-regexp) - python-shell-prompt-block-regexp-1) - (set (make-local-variable 'python-shell-completion-setup-code) - python-shell-completion-setup-code-1) - (set (make-local-variable 'python-shell-completion-string-code) - python-shell-completion-string-code-1) - (set (make-local-variable 'python-eldoc-setup-code) - python-eldoc-setup-code-1) - (set (make-local-variable 'python-eldoc-string-code) - python-eldoc-string-code-1) - (set (make-local-variable 'python-ffap-setup-code) - python-ffap-setup-code-1) - (set (make-local-variable 'python-ffap-string-code) - python-ffap-string-code-1) - (set (make-local-variable 'python-shell-setup-codes) - python-shell-setup-codes-1)))) + (python-clone-local-variables current-buffer)))) (when pop (pop-to-buffer proc-buffer-name))))) @@ -2480,6 +2442,20 @@ Return the index of the matching item, or nil if not found." (when member-result (- (length seq) (length member-result))))) +;; Stolen from org-mode +(defun python-clone-local-variables (from-buffer &optional regexp) + "Clone local variables from FROM-BUFFER. +Optional argument REGEXP selects variables to clone and defaults +to \"^python-\"." + (mapc + (lambda (pair) + (and (symbolp (car pair)) + (string-match (or regexp "^python-") + (symbol-name (car pair))) + (set (make-local-variable (car pair)) + (cdr pair)))) + (buffer-local-variables from-buffer))) + ;;;###autoload (define-derived-mode python-mode fundamental-mode "Python" -- 2.39.5