aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2014-12-26 17:59:33 -0300
committerFabián Ezequiel Gallina2014-12-26 17:59:33 -0300
commit7284a174abc03c9ccf45aa43c939585beea351b7 (patch)
tree21024e515aa72b5280618d3a6a29f8fd0598a5f5
parent8cf42182b8da79bb4a2f2f704fa0d627304f5165 (diff)
downloademacs-7284a174abc03c9ccf45aa43c939585beea351b7.tar.gz
emacs-7284a174abc03c9ccf45aa43c939585beea351b7.zip
python.el: Generate clearer shell buffer names.
* lisp/progmodes/python.el (python-shell-get-process-name) (python-shell-internal-get-process-name): Use `buffer-name`. (python-shell-internal-get-or-create-process): Simplify. * test/automated/python-tests.el (python-shell-get-process-name-1) (python-shell-internal-get-process-name-1): Cleanup. (python-shell-get-process-name-2) (python-shell-internal-get-process-name-2): New tests. (python-shell-calculate-command-1) (python-shell-calculate-process-environment-3) (python-shell-calculate-exec-path-2, python-shell-make-comint-1) (python-shell-make-comint-2, python-shell-make-comint-4) (python-shell-get-process-1, python-util-clone-local-variables-1): Replace obsolete function and variable references with current.
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/progmodes/python.el44
-rw-r--r--test/ChangeLog13
-rw-r--r--test/automated/python-tests.el99
4 files changed, 77 insertions, 87 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 8d231a487e3..755499bdaae 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12014-12-26 Fabián Ezequiel Gallina <fgallina@gnu.org>
2
3 python.el: Generate clearer shell buffer names.
4
5 * progmodes/python.el (python-shell-get-process-name)
6 (python-shell-internal-get-process-name): Use `buffer-name`.
7 (python-shell-internal-get-or-create-process): Simplify.
8
12014-12-26 Dmitry Gutov <dgutov@yandex.ru> 92014-12-26 Dmitry Gutov <dgutov@yandex.ru>
2 10
3 Add basic xref apropos implementation to elisp-mode. 11 Add basic xref apropos implementation to elisp-mode.
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 47c6a90bbde..bd8c734e0b9 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -2087,36 +2087,18 @@ and `python-shell-output-prompt-regexp' using the values from
2087 2087
2088(defun python-shell-get-process-name (dedicated) 2088(defun python-shell-get-process-name (dedicated)
2089 "Calculate the appropriate process name for inferior Python process. 2089 "Calculate the appropriate process name for inferior Python process.
2090If DEDICATED is t and the variable `buffer-file-name' is non-nil 2090If DEDICATED is t returns a string with the form
2091returns a string with the form 2091`python-shell-buffer-name'[`buffer-name'] else returns the value
2092`python-shell-buffer-name'[variable `buffer-file-name'] else 2092of `python-shell-buffer-name'."
2093returns the value of `python-shell-buffer-name'." 2093 (if dedicated
2094 (let ((process-name 2094 (format "%s[%s]" python-shell-buffer-name (buffer-name))
2095 (if (and dedicated 2095 python-shell-buffer-name))
2096 buffer-file-name)
2097 (format "%s[%s]" python-shell-buffer-name buffer-file-name)
2098 (format "%s" python-shell-buffer-name))))
2099 process-name))
2100 2096
2101(defun python-shell-internal-get-process-name () 2097(defun python-shell-internal-get-process-name ()
2102 "Calculate the appropriate process name for Internal Python process. 2098 "Calculate the appropriate process name for Internal Python process.
2103The name is calculated from `python-shell-global-buffer-name' and 2099The name is calculated from `python-shell-global-buffer-name' and
2104a hash of all relevant global shell settings in order to ensure 2100the `buffer-name'."
2105uniqueness for different types of configurations." 2101 (format "%s[%s]" python-shell-internal-buffer-name (buffer-name)))
2106 (format "%s [%s]"
2107 python-shell-internal-buffer-name
2108 (md5
2109 (concat
2110 python-shell-interpreter
2111 python-shell-interpreter-args
2112 python-shell--prompt-calculated-input-regexp
2113 python-shell--prompt-calculated-output-regexp
2114 (mapconcat #'symbol-value python-shell-setup-codes "")
2115 (mapconcat #'identity python-shell-process-environment "")
2116 (mapconcat #'identity python-shell-extra-pythonpaths "")
2117 (mapconcat #'identity python-shell-exec-path "")
2118 (or python-shell-virtualenv-root "")
2119 (mapconcat #'identity python-shell-exec-path "")))))
2120 2102
2121(defun python-shell-calculate-command () 2103(defun python-shell-calculate-command ()
2122 "Calculate the string used to execute the inferior Python process." 2104 "Calculate the string used to execute the inferior Python process."
@@ -2606,12 +2588,10 @@ there for compatibility with CEDET.")
2606 2588
2607(defun python-shell-internal-get-or-create-process () 2589(defun python-shell-internal-get-or-create-process ()
2608 "Get or create an inferior Internal Python process." 2590 "Get or create an inferior Internal Python process."
2609 (let* ((proc-name (python-shell-internal-get-process-name)) 2591 (let ((proc-name (python-shell-internal-get-process-name)))
2610 (proc-buffer-name (format " *%s*" proc-name))) 2592 (if (process-live-p proc-name)
2611 (when (not (process-live-p proc-name)) 2593 (get-process proc-name)
2612 (run-python-internal) 2594 (run-python-internal))))
2613 (setq python-shell-internal-buffer proc-buffer-name))
2614 (get-buffer-process proc-buffer-name)))
2615 2595
2616(define-obsolete-function-alias 2596(define-obsolete-function-alias
2617 'python-proc 'python-shell-internal-get-or-create-process "24.3") 2597 'python-proc 'python-shell-internal-get-or-create-process "24.3")
diff --git a/test/ChangeLog b/test/ChangeLog
index 7d33014f75c..fda30d9237c 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,16 @@
12014-12-26 Fabián Ezequiel Gallina <fgallina@gnu.org>
2
3 * automated/python-tests.el (python-shell-get-process-name-1)
4 (python-shell-internal-get-process-name-1): Cleanup.
5 (python-shell-get-process-name-2)
6 (python-shell-internal-get-process-name-2): New tests.
7 (python-shell-calculate-command-1)
8 (python-shell-calculate-process-environment-3)
9 (python-shell-calculate-exec-path-2, python-shell-make-comint-1)
10 (python-shell-make-comint-2, python-shell-make-comint-4)
11 (python-shell-get-process-1, python-util-clone-local-variables-1):
12 Replace obsolete function and variable references with current.
13
12014-12-19 Artur Malabarba <bruce.connor.am@gmail.com> 142014-12-19 Artur Malabarba <bruce.connor.am@gmail.com>
2 15
3 * automated/let-alist.el: require `cl-lib' 16 * automated/let-alist.el: require `cl-lib'
diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el
index de20a80ea52..fd427941bf1 100644
--- a/test/automated/python-tests.el
+++ b/test/automated/python-tests.el
@@ -1775,52 +1775,41 @@ def f():
1775(defvar python-tests-shell-interpreter "python") 1775(defvar python-tests-shell-interpreter "python")
1776 1776
1777(ert-deftest python-shell-get-process-name-1 () 1777(ert-deftest python-shell-get-process-name-1 ()
1778 "Check process name calculation on different scenarios." 1778 "Check process name calculation sans `buffer-file-name'."
1779 (python-tests-with-temp-buffer 1779 (python-tests-with-temp-buffer
1780 "" 1780 ""
1781 (should (string= (python-shell-get-process-name nil) 1781 (should (string= (python-shell-get-process-name nil)
1782 python-shell-buffer-name)) 1782 python-shell-buffer-name))
1783 ;; When the `current-buffer' doesn't have `buffer-file-name', even 1783 (should (string= (python-shell-get-process-name t)
1784 ;; if dedicated flag is non-nil should not include its name. 1784 (format "%s[%s]" python-shell-buffer-name (buffer-name))))))
1785 (should (string= (python-shell-get-process-name t) 1785
1786 python-shell-buffer-name))) 1786(ert-deftest python-shell-get-process-name-2 ()
1787 "Check process name calculation with `buffer-file-name'."
1787 (python-tests-with-temp-file 1788 (python-tests-with-temp-file
1788 "" 1789 ""
1789 ;; `buffer-file-name' is non-nil but the dedicated flag is nil and 1790 ;; `buffer-file-name' is non-nil but the dedicated flag is nil and
1790 ;; should be respected. 1791 ;; should be respected.
1791 (should (string= (python-shell-get-process-name nil) 1792 (should (string= (python-shell-get-process-name nil)
1792 python-shell-buffer-name)) 1793 python-shell-buffer-name))
1793 (should (string= 1794 (should (string=
1794 (python-shell-get-process-name t) 1795 (python-shell-get-process-name t)
1795 (format "%s[%s]" python-shell-buffer-name buffer-file-name))))) 1796 (format "%s[%s]" python-shell-buffer-name (buffer-name))))))
1796 1797
1797(ert-deftest python-shell-internal-get-process-name-1 () 1798(ert-deftest python-shell-internal-get-process-name-1 ()
1798 "Check the internal process name is config-unique." 1799 "Check the internal process name is buffer-unique sans `buffer-file-name'."
1799 (let* ((python-shell-interpreter python-tests-shell-interpreter) 1800 (python-tests-with-temp-buffer
1800 (python-shell-interpreter-args "") 1801 ""
1801 (python-shell-prompt-regexp ">>> ") 1802 (should (string= (python-shell-internal-get-process-name)
1802 (python-shell-prompt-block-regexp "[.][.][.] ") 1803 (format "%s[%s]" python-shell-internal-buffer-name (buffer-name))))))
1803 (python-shell-setup-codes "") 1804
1804 (python-shell-process-environment "") 1805(ert-deftest python-shell-internal-get-process-name-2 ()
1805 (python-shell-extra-pythonpaths "") 1806 "Check the internal process name is buffer-unique with `buffer-file-name'."
1806 (python-shell-exec-path "") 1807 (python-tests-with-temp-file
1807 (python-shell-virtualenv-path "") 1808 ""
1808 (expected (python-tests-with-temp-buffer 1809 (should (string= (python-shell-internal-get-process-name)
1809 "" (python-shell-internal-get-process-name)))) 1810 (format "%s[%s]" python-shell-internal-buffer-name (buffer-name))))))
1810 ;; Same configurations should match. 1811
1811 (should 1812(ert-deftest python-shell-calculate-command-1 ()
1812 (string= expected
1813 (python-tests-with-temp-buffer
1814 "" (python-shell-internal-get-process-name))))
1815 (let ((python-shell-interpreter-args "-B"))
1816 ;; A minimal change should generate different names.
1817 (should
1818 (not (string=
1819 expected
1820 (python-tests-with-temp-buffer
1821 "" (python-shell-internal-get-process-name))))))))
1822
1823(ert-deftest python-shell-parse-command-1 ()
1824 "Check the command to execute is calculated correctly. 1813 "Check the command to execute is calculated correctly.
1825Using `python-shell-interpreter' and 1814Using `python-shell-interpreter' and
1826`python-shell-interpreter-args'." 1815`python-shell-interpreter-args'."
@@ -1832,7 +1821,7 @@ Using `python-shell-interpreter' and
1832 (format "%s %s" 1821 (format "%s %s"
1833 python-shell-interpreter 1822 python-shell-interpreter
1834 python-shell-interpreter-args) 1823 python-shell-interpreter-args)
1835 (python-shell-parse-command))))) 1824 (python-shell-calculate-command)))))
1836 1825
1837(ert-deftest python-shell-calculate-process-environment-1 () 1826(ert-deftest python-shell-calculate-process-environment-1 ()
1838 "Test `python-shell-process-environment' modification." 1827 "Test `python-shell-process-environment' modification."
@@ -1857,17 +1846,17 @@ Using `python-shell-interpreter' and
1857 path-separator original-pythonpath))))) 1846 path-separator original-pythonpath)))))
1858 1847
1859(ert-deftest python-shell-calculate-process-environment-3 () 1848(ert-deftest python-shell-calculate-process-environment-3 ()
1860 "Test `python-shell-virtualenv-path' modification." 1849 "Test `python-shell-virtualenv-root' modification."
1861 (let* ((original-path (or (getenv "PATH") "")) 1850 (let* ((original-path (or (getenv "PATH") ""))
1862 (python-shell-virtualenv-path 1851 (python-shell-virtualenv-root
1863 (directory-file-name user-emacs-directory)) 1852 (directory-file-name user-emacs-directory))
1864 (process-environment 1853 (process-environment
1865 (python-shell-calculate-process-environment))) 1854 (python-shell-calculate-process-environment)))
1866 (should (not (getenv "PYTHONHOME"))) 1855 (should (not (getenv "PYTHONHOME")))
1867 (should (string= (getenv "VIRTUAL_ENV") python-shell-virtualenv-path)) 1856 (should (string= (getenv "VIRTUAL_ENV") python-shell-virtualenv-root))
1868 (should (equal (getenv "PATH") 1857 (should (equal (getenv "PATH")
1869 (format "%s/bin%s%s" 1858 (format "%s/bin%s%s"
1870 python-shell-virtualenv-path 1859 python-shell-virtualenv-root
1871 path-separator original-path))))) 1860 path-separator original-path)))))
1872 1861
1873(ert-deftest python-shell-calculate-process-environment-4 () 1862(ert-deftest python-shell-calculate-process-environment-4 ()
@@ -1900,13 +1889,13 @@ Using `python-shell-interpreter' and
1900(ert-deftest python-shell-calculate-exec-path-2 () 1889(ert-deftest python-shell-calculate-exec-path-2 ()
1901 "Test `python-shell-exec-path' modification." 1890 "Test `python-shell-exec-path' modification."
1902 (let* ((original-exec-path exec-path) 1891 (let* ((original-exec-path exec-path)
1903 (python-shell-virtualenv-path 1892 (python-shell-virtualenv-root
1904 (directory-file-name (expand-file-name user-emacs-directory))) 1893 (directory-file-name (expand-file-name user-emacs-directory)))
1905 (exec-path (python-shell-calculate-exec-path))) 1894 (exec-path (python-shell-calculate-exec-path)))
1906 (should (equal 1895 (should (equal
1907 exec-path 1896 exec-path
1908 (append (cons 1897 (append (cons
1909 (format "%s/bin" python-shell-virtualenv-path) 1898 (format "%s/bin" python-shell-virtualenv-root)
1910 original-exec-path)))))) 1899 original-exec-path))))))
1911 1900
1912(ert-deftest python-shell-make-comint-1 () 1901(ert-deftest python-shell-make-comint-1 ()
@@ -1922,7 +1911,7 @@ Using `python-shell-interpreter' and
1922 (shell-buffer 1911 (shell-buffer
1923 (python-tests-with-temp-buffer 1912 (python-tests-with-temp-buffer
1924 "" (python-shell-make-comint 1913 "" (python-shell-make-comint
1925 (python-shell-parse-command) proc-name))) 1914 (python-shell-calculate-command) proc-name)))
1926 (process (get-buffer-process shell-buffer))) 1915 (process (get-buffer-process shell-buffer)))
1927 (unwind-protect 1916 (unwind-protect
1928 (progn 1917 (progn
@@ -1943,7 +1932,7 @@ Using `python-shell-interpreter' and
1943 (shell-buffer 1932 (shell-buffer
1944 (python-tests-with-temp-buffer 1933 (python-tests-with-temp-buffer
1945 "" (python-shell-make-comint 1934 "" (python-shell-make-comint
1946 (python-shell-parse-command) proc-name nil t))) 1935 (python-shell-calculate-command) proc-name nil t)))
1947 (process (get-buffer-process shell-buffer))) 1936 (process (get-buffer-process shell-buffer)))
1948 (unwind-protect 1937 (unwind-protect
1949 (progn 1938 (progn
@@ -2010,7 +1999,7 @@ and `python-shell-interpreter-args' in the new shell buffer."
2010 (setenv "PYTHONSTARTUP" startup-file) 1999 (setenv "PYTHONSTARTUP" startup-file)
2011 (python-tests-with-temp-buffer 2000 (python-tests-with-temp-buffer
2012 "" (python-shell-make-comint 2001 "" (python-shell-make-comint
2013 (python-shell-parse-command) proc-name nil)))) 2002 (python-shell-calculate-command) proc-name nil))))
2014 (process (get-buffer-process shell-buffer))) 2003 (process (get-buffer-process shell-buffer)))
2015 (unwind-protect 2004 (unwind-protect
2016 (progn 2005 (progn
@@ -2040,10 +2029,10 @@ and `python-shell-interpreter-args' in the new shell buffer."
2040 (dedicated-proc-name (python-shell-get-process-name t)) 2029 (dedicated-proc-name (python-shell-get-process-name t))
2041 (global-shell-buffer 2030 (global-shell-buffer
2042 (python-shell-make-comint 2031 (python-shell-make-comint
2043 (python-shell-parse-command) global-proc-name)) 2032 (python-shell-calculate-command) global-proc-name))
2044 (dedicated-shell-buffer 2033 (dedicated-shell-buffer
2045 (python-shell-make-comint 2034 (python-shell-make-comint
2046 (python-shell-parse-command) dedicated-proc-name)) 2035 (python-shell-calculate-command) dedicated-proc-name))
2047 (global-process (get-buffer-process global-shell-buffer)) 2036 (global-process (get-buffer-process global-shell-buffer))
2048 (dedicated-process (get-buffer-process dedicated-shell-buffer))) 2037 (dedicated-process (get-buffer-process dedicated-shell-buffer)))
2049 (unwind-protect 2038 (unwind-protect
@@ -3767,7 +3756,7 @@ def foo(a, b, c):
3767 . "from IPython.core.completerlib import module_completion") 3756 . "from IPython.core.completerlib import module_completion")
3768 (python-shell-completion-string-code 3757 (python-shell-completion-string-code
3769 . "';'.join(get_ipython().Completer.all_completions('''%s'''))\n") 3758 . "';'.join(get_ipython().Completer.all_completions('''%s'''))\n")
3770 (python-shell-virtualenv-path 3759 (python-shell-virtualenv-root
3771 . "/home/user/.virtualenvs/project")))) 3760 . "/home/user/.virtualenvs/project"))))
3772 (with-current-buffer buffer 3761 (with-current-buffer buffer
3773 (kill-all-local-variables) 3762 (kill-all-local-variables)