]> code.delx.au - gnu-emacs/commitdiff
New function python-clone-local-variables
authorFabián Ezequiel Gallina <fgallina@cuca>
Thu, 17 May 2012 03:03:24 +0000 (00:03 -0300)
committerFabián Ezequiel Gallina <fgallina@gnu.org>
Thu, 17 May 2012 03:03:24 +0000 (00:03 -0300)
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

index 3d25f0b46c8b994273ce100ac05d24787500dbce..7ded2c897a8b832e51f914e963dae89ff3218cf1 100644 (file)
@@ -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)))
+
 \f
 ;;;###autoload
 (define-derived-mode python-mode fundamental-mode "Python"