diff -Nru elpy-1.33.0/.bumpversion.cfg elpy-1.34.0/.bumpversion.cfg --- elpy-1.33.0/.bumpversion.cfg 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/.bumpversion.cfg 2020-05-27 14:48:48.000000000 +0000 @@ -1,7 +1,6 @@ [bumpversion] -current_version = 1.33.0 +current_version = 1.34.0 files = elpy.el elpy/__init__.py Cask elpy-pkg.el docs/conf.py commit = True tag = True tag_name = {new_version} - diff -Nru elpy-1.33.0/Cask elpy-1.34.0/Cask --- elpy-1.33.0/Cask 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/Cask 2020-05-27 14:48:48.000000000 +0000 @@ -1,7 +1,7 @@ (source gnu) (source melpa) -(package "elpy" "1.33.0" "Emacs Python Development Environment") +(package "elpy" "1.34.0" "Emacs Python Development Environment") (depends-on "company" "0.9.10") (depends-on "highlight-indentation" "0.7.0") diff -Nru elpy-1.33.0/debian/changelog elpy-1.34.0/debian/changelog --- elpy-1.33.0/debian/changelog 2020-04-28 23:42:51.000000000 +0000 +++ elpy-1.34.0/debian/changelog 2020-05-28 21:26:03.000000000 +0000 @@ -1,3 +1,12 @@ +elpy (1.34.0-1) unstable; urgency=medium + + * New upstream release. + * Rebase quilt series onto this release. + * Drop 0006-Fix-a-fatal-typo-in-elpy-format-code.patch (merged upstream). + * Switch to debhelper-compat 13. + + -- Nicholas D Steeves Thu, 28 May 2020 17:26:03 -0400 + elpy (1.33.0-2) unstable; urgency=medium * Add 0006-Fix-a-fatal-typo-in-elpy-format-code.patch, a commit cherry diff -Nru elpy-1.33.0/debian/control elpy-1.34.0/debian/control --- elpy-1.33.0/debian/control 2020-04-28 23:42:51.000000000 +0000 +++ elpy-1.34.0/debian/control 2020-05-28 21:26:03.000000000 +0000 @@ -3,7 +3,7 @@ Priority: optional Maintainer: Debian Emacsen team Uploaders: Nicholas D Steeves -Build-Depends: debhelper-compat (= 12) +Build-Depends: debhelper-compat (= 13) , dh-elpa , dh-python , elpa-company diff -Nru elpy-1.33.0/debian/patches/0003-Double-max-wait-in-elpy-wait-for-output-self-test.patch elpy-1.34.0/debian/patches/0003-Double-max-wait-in-elpy-wait-for-output-self-test.patch --- elpy-1.33.0/debian/patches/0003-Double-max-wait-in-elpy-wait-for-output-self-test.patch 2020-04-28 23:42:51.000000000 +0000 +++ elpy-1.34.0/debian/patches/0003-Double-max-wait-in-elpy-wait-for-output-self-test.patch 2020-05-28 21:26:03.000000000 +0000 @@ -8,7 +8,7 @@ 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test-helper.el b/test/test-helper.el -index e9f6810..6d6dbe2 100644 +index 82aa162..a1a2367 100644 --- a/test/test-helper.el +++ b/test/test-helper.el @@ -37,7 +37,7 @@ diff -Nru elpy-1.33.0/debian/patches/0004-docs-conf.py-build-the-documentation-using-sphinx_rt.patch elpy-1.34.0/debian/patches/0004-docs-conf.py-build-the-documentation-using-sphinx_rt.patch --- elpy-1.33.0/debian/patches/0004-docs-conf.py-build-the-documentation-using-sphinx_rt.patch 2020-04-28 23:42:51.000000000 +0000 +++ elpy-1.34.0/debian/patches/0004-docs-conf.py-build-the-documentation-using-sphinx_rt.patch 2020-05-28 21:26:03.000000000 +0000 @@ -7,7 +7,7 @@ 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py -index fad66cf..61885cc 100644 +index 8ece42a..9c28522 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -98,7 +98,7 @@ pygments_style = 'sphinx' diff -Nru elpy-1.33.0/debian/patches/0005-test-helper.el-uniquivocally-set-elpy-test-dont-use-.patch elpy-1.34.0/debian/patches/0005-test-helper.el-uniquivocally-set-elpy-test-dont-use-.patch --- elpy-1.33.0/debian/patches/0005-test-helper.el-uniquivocally-set-elpy-test-dont-use-.patch 2020-04-28 23:42:51.000000000 +0000 +++ elpy-1.34.0/debian/patches/0005-test-helper.el-uniquivocally-set-elpy-test-dont-use-.patch 2020-05-28 21:26:03.000000000 +0000 @@ -7,7 +7,7 @@ 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test-helper.el b/test/test-helper.el -index 6d6dbe2..981c43d 100644 +index a1a2367..1bc54a0 100644 --- a/test/test-helper.el +++ b/test/test-helper.el @@ -52,7 +52,7 @@ diff -Nru elpy-1.33.0/debian/patches/0006-Fix-a-fatal-typo-in-elpy-format-code.patch elpy-1.34.0/debian/patches/0006-Fix-a-fatal-typo-in-elpy-format-code.patch --- elpy-1.33.0/debian/patches/0006-Fix-a-fatal-typo-in-elpy-format-code.patch 2020-04-28 23:42:51.000000000 +0000 +++ elpy-1.34.0/debian/patches/0006-Fix-a-fatal-typo-in-elpy-format-code.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,25 +0,0 @@ -From: Romain Leroux -Date: Tue, 24 Mar 2020 03:22:14 +0100 -Subject: Fix a fatal typo in elpy-format-code - ---- - elpy.el | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/elpy.el b/elpy.el -index f2631f5..dc8aa1f 100644 ---- a/elpy.el -+++ b/elpy.el -@@ -2279,10 +2279,10 @@ prefix argument is given, prompt for a symbol from the user." - (when (interactive-p) (message "Autoformatting code with yapf.")) - (elpy-yapf-fix-code)) - ((elpy-config--package-available-p "autopep8") -- ((when (interactive-p) message "Autoformatting code with autopep8.")) -+ (when (interactive-p) (message "Autoformatting code with autopep8.")) - (elpy-autopep8-fix-code)) - ((elpy-config--package-available-p "black") -- ((when (interactive-p) message "Autoformatting code with black.")) -+ (when (interactive-p) (message "Autoformatting code with black.")) - (elpy-black-fix-code)) - (t - (message "Install yapf/autopep8 to format code.")))) diff -Nru elpy-1.33.0/debian/patches/series elpy-1.34.0/debian/patches/series --- elpy-1.33.0/debian/patches/series 2020-04-28 23:42:51.000000000 +0000 +++ elpy-1.34.0/debian/patches/series 2020-05-28 21:26:03.000000000 +0000 @@ -2,4 +2,3 @@ 0003-Double-max-wait-in-elpy-wait-for-output-self-test.patch 0004-docs-conf.py-build-the-documentation-using-sphinx_rt.patch 0005-test-helper.el-uniquivocally-set-elpy-test-dont-use-.patch -0006-Fix-a-fatal-typo-in-elpy-format-code.patch diff -Nru elpy-1.33.0/docs/conf.py elpy-1.34.0/docs/conf.py --- elpy-1.33.0/docs/conf.py 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/docs/conf.py 2020-05-27 14:48:48.000000000 +0000 @@ -51,9 +51,9 @@ # built documents. # # The short X.Y version. -version = '1.33.0' +version = '1.34.0' # The full version, including alpha/beta/rc tags. -release = '1.33.0' +release = '1.34.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff -Nru elpy-1.33.0/docs/customization_tips.rst elpy-1.34.0/docs/customization_tips.rst --- elpy-1.33.0/docs/customization_tips.rst 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/docs/customization_tips.rst 2020-05-27 14:48:48.000000000 +0000 @@ -55,8 +55,11 @@ -An alternative to ``elpy-goto-definition`` -========================================== +Alternatives to ``elpy-goto-definition`` +======================================== + +Fallback to rgrep +----------------- You may sometimes find when you try to navigate to a function/class definition with elpy-goto-definition_ (``M-.``), that instead of jumping to the definition, you get the message "No definition found". If you see this error often (because of the nature of the code you work on), you can use the following function instead of/in addition to ``elpy-goto-definition``: @@ -80,6 +83,21 @@ .. _elpy-rgrep-symbol: http://elpy.readthedocs.org/en/latest/ide.html#command-elpy-rgrep-symbol +Jumping to assignment +--------------------- + +As an alternative to `elpy-goto-definition`, Elpy also provides the function elpy-goto-assignment_ that jumps to the line where the symbol at point has been assigned. +For functions and classes, it behaves roughly like `elpy-goto-definition` but has some advantages in certain situations (like if you want to jump to a decorated function). +You can try this alternative with the following code: + + +.. code-block:: elisp + + (define-key map (kbd "M-.") 'elpy-goto-assignment + (define-key map (kbd "C-x 4 M-.") 'elpy-goto-assignment-other-window) + +.. _elpy-goto-assignment: http://elpy.readthedocs.org/en/latest/ide.html#command-elpy-goto-assignment + Enable full font locking of inputs in the python shell ====================================================== diff -Nru elpy-1.33.0/docs/ide.rst elpy-1.34.0/docs/ide.rst --- elpy-1.33.0/docs/ide.rst 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/docs/ide.rst 2020-05-27 14:48:48.000000000 +0000 @@ -147,6 +147,13 @@ Search the buffer for a list of definitions of classes and functions. +.. command:: elpy-goto-assignment + + Go to the location where the identifier at point is assigned. + It is not bound by default, so you will have to bind it manually. + You can also use it as a replacement to ``elpy-goto-definition`` (see `Jumping to assignment`_). + +.. _Jumping to assignment: http://elpy.readthedocs.org/en/latest/customization_tips.html#jumping-to-assignment If you use an Emacs version superior to 25, Elpy will define the necessary backends for the `xref`_ package. diff -Nru elpy-1.33.0/elpy/__init__.py elpy-1.34.0/elpy/__init__.py --- elpy-1.33.0/elpy/__init__.py 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/elpy/__init__.py 2020-05-27 14:48:48.000000000 +0000 @@ -37,5 +37,5 @@ """ __author__ = "Jorgen Schaefer" -__version__ = "1.33.0" +__version__ = "1.34.0" __license__ = "GPL" diff -Nru elpy-1.33.0/elpy/jedibackend.py elpy-1.34.0/elpy/jedibackend.py --- elpy-1.33.0/elpy/jedibackend.py 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/elpy/jedibackend.py 2020-05-27 14:48:48.000000000 +0000 @@ -70,7 +70,13 @@ source=source, line=line, column=column, path=filename, encoding='utf-8', environment=self.environment) - if locations and locations[-1].docstring(): + if not locations: + return None + # Filter uninteresting things + if locations[-1].name in ["str", "int", "float", "bool", "tuple", + "list", "dict"]: + return None + if locations[-1].docstring(): return ('Documentation for {0}:\n\n'.format( locations[-1].full_name) + locations[-1].docstring()) else: @@ -165,6 +171,33 @@ "index": call.index, "params": params} + def rpc_get_calltip_or_oneline_docstring(self, filename, source, offset): + """ + Return the current function calltip or its oneline docstring. + + Meant to be used with eldoc. + """ + # Try to get a oneline docstring then + docs = self.rpc_get_oneline_docstring(filename=filename, + source=source, + offset=offset) + if docs is not None: + if docs['doc'] != "No documentation": + docs['kind'] = 'oneline_doc' + return docs + # Try to get a calltip + calltip = self.rpc_get_calltip(filename=filename, source=source, + offset=offset) + if calltip is not None: + calltip['kind'] = 'calltip' + return calltip + # Ok, no calltip, just display the function name + if docs is not None: + docs['kind'] = 'oneline_doc' + return docs + # Giving up... + return None + def rpc_get_oneline_docstring(self, filename, source, offset): """Return a oneline docstring for the symbol at offset""" line, column = pos_to_linecol(source, offset) @@ -172,6 +205,13 @@ source=source, line=line, column=column, path=filename, encoding='utf-8', environment=self.environment) + # avoid unintersting stuff + try: + if definitions[0].name in ["str", "int", "float", "bool", "tuple", + "list", "dict"]: + return None + except: + pass assignments = run_with_debug(jedi, 'goto_assignments', source=source, line=line, column=column, path=filename, encoding='utf-8', diff -Nru elpy-1.33.0/elpy/server.py elpy-1.34.0/elpy/server.py --- elpy-1.33.0/elpy/server.py 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/elpy/server.py 2020-05-27 14:48:48.000000000 +0000 @@ -79,6 +79,14 @@ return self._call_backend("rpc_get_oneline_docstring", None, filename, get_source(source), offset) + def rpc_get_calltip_or_oneline_docstring(self, filename, source, offset): + """Get a calltip or a oneline docstring for the symbol at the offset. + + """ + return self._call_backend("rpc_get_calltip_or_oneline_docstring", + None, filename, + get_source(source), offset) + def rpc_get_completions(self, filename, source, offset): """Get a list of completion candidates for the symbol at offset. diff -Nru elpy-1.33.0/elpy/tests/support.py elpy-1.34.0/elpy/tests/support.py --- elpy-1.33.0/elpy/tests/support.py 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/elpy/tests/support.py 2020-05-27 14:48:48.000000000 +0000 @@ -698,38 +698,46 @@ METHOD = "rpc_get_calltip" def test_should_get_calltip(self): + expected = self.THREAD_CALLTIP source, offset = source_and_offset( "import threading\nthreading.Thread(_|_") filename = self.project_file("test.py", source) calltip = self.backend.rpc_get_calltip(filename, source, offset) - - expected = self.THREAD_CALLTIP - + self.assertEqual(calltip, expected) + calltip = self.backend.rpc_get_calltip_or_oneline_docstring(filename, + source, + offset) + calltip.pop('kind') self.assertEqual(calltip, expected) def test_should_get_calltip_even_after_parens(self): source, offset = source_and_offset( "import threading\nthreading.Thread(foo()_|_") filename = self.project_file("test.py", source) - actual = self.backend.rpc_get_calltip(filename, source, offset) - + self.assertEqual(self.THREAD_CALLTIP, actual) + actual = self.backend.rpc_get_calltip_or_oneline_docstring(filename, + source, + offset) + actual.pop('kind') self.assertEqual(self.THREAD_CALLTIP, actual) def test_should_get_calltip_at_closing_paren(self): source, offset = source_and_offset( "import threading\nthreading.Thread(_|_)") filename = self.project_file("test.py", source) - actual = self.backend.rpc_get_calltip(filename, source, offset) - self.assertEqual(self.THREAD_CALLTIP, actual) + actual = self.backend.rpc_get_calltip_or_oneline_docstring(filename, + source, + offset) + self.assertEqual(actual['kind'], "oneline_doc") def test_should_not_missing_attribute_get_definition(self): # Bug #627 / jedi#573 @@ -747,6 +755,10 @@ source, offset) self.assertIsNone(calltip) + calltip = self.backend.rpc_get_calltip_or_oneline_docstring(filename, + source, + offset) + self.assertIsNone(calltip) def test_should_remove_self_argument(self): source, offset = source_and_offset( @@ -757,7 +769,11 @@ actual = self.backend.rpc_get_calltip(filename, source, offset) - + self.assertEqual(self.KEYS_CALLTIP, actual) + actual = self.backend.rpc_get_calltip_or_oneline_docstring(filename, + source, + offset) + actual.pop('kind') self.assertEqual(self.KEYS_CALLTIP, actual) def test_should_remove_package_prefix(self): @@ -770,7 +786,11 @@ actual = self.backend.rpc_get_calltip(filename, source, offset) - + self.assertEqual(self.RADIX_CALLTIP, actual) + actual = self.backend.rpc_get_calltip_or_oneline_docstring(filename, + source, + offset) + actual.pop('kind') self.assertEqual(self.RADIX_CALLTIP, actual) def test_should_return_none_outside_of_all(self): @@ -779,6 +799,10 @@ calltip = self.backend.rpc_get_calltip(filename, source, offset) self.assertIsNone(calltip) + calltip = self.backend.rpc_get_calltip_or_oneline_docstring(filename, + source, + offset) + self.assertIsNotNone(calltip) def test_should_find_calltip_different_package(self): # See issue #74 @@ -798,7 +822,11 @@ actual = self.backend.rpc_get_calltip(file2, source2, offset) - + self.assertEqual(self.ADD_CALLTIP, actual) + actual = self.backend.rpc_get_calltip_or_oneline_docstring(file2, + source2, + offset) + actual.pop('kind') self.assertEqual(self.ADD_CALLTIP, actual) @@ -853,6 +881,11 @@ source, offset) self.check_docstring(docstring) + docstring = self.backend.rpc_get_calltip_or_oneline_docstring(filename, + source, + offset) + docstring.pop('kind') + self.check_docstring(docstring) def test_should_get_oneline_docstring_for_modules(self): source, offset = source_and_offset( @@ -862,6 +895,11 @@ source, offset) self.check_module_docstring(docstring) + docstring = self.backend.rpc_get_calltip_or_oneline_docstring(filename, + source, + offset) + docstring.pop('kind') + self.check_module_docstring(docstring) def test_should_return_none_for_bad_identifier(self): source, offset = source_and_offset( @@ -871,6 +909,10 @@ source, offset) self.assertIsNone(docstring) + docstring = self.backend.rpc_get_calltip_or_oneline_docstring(filename, + source, + offset) + self.assertIsNone(docstring) class RPCGetNamesTests(GenericRPCTests): diff -Nru elpy-1.33.0/elpy/tests/test_server.py elpy-1.34.0/elpy/tests/test_server.py --- elpy-1.33.0/elpy/tests/test_server.py 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/elpy/tests/test_server.py 2020-05-27 14:48:48.000000000 +0000 @@ -211,6 +211,18 @@ "offset")) +class TestRPCGetCalltipOrOnelineDocstring(BackendCallTestCase): + def test_should_call_backend(self): + self.assert_calls_backend("rpc_get_calltip_or_oneline_docstring") + + def test_should_handle_no_backend(self): + self.srv.backend = None + self.assertIsNone( + self.srv.rpc_get_calltip_or_oneline_docstring("filname", + "source", + "offset")) + + class TestRPCGetPydocCompletions(ServerTestCase): @mock.patch.object(server, 'get_pydoc_completions') def test_should_call_pydoc_completions(self, get_pydoc_completions): diff -Nru elpy-1.33.0/elpy.el elpy-1.34.0/elpy.el --- elpy-1.33.0/elpy.el 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/elpy.el 2020-05-27 14:48:48.000000000 +0000 @@ -4,7 +4,7 @@ ;; Author: Jorgen Schaefer , Gaby Launay ;; URL: https://github.com/jorgenschaefer/elpy -;; Version: 1.33.0 +;; Version: 1.34.0 ;; Keywords: Python, IDE, Languages, Tools ;; Package-Requires: ((company "0.9.10") (emacs "24.4") (highlight-indentation "0.7.0") (pyvenv "1.20") (yasnippet "0.13.0") (s "1.12.0")) @@ -53,7 +53,7 @@ (require 'elpy-rpc) (require 'pyvenv) -(defconst elpy-version "1.33.0" +(defconst elpy-version "1.34.0" "The version of the Elpy Lisp code.") ;;;;;;;;;;;;;;;;;;;;;; @@ -535,12 +535,13 @@ (add-hook 'inferior-python-mode-hook 'elpy-shell--enable-output-filter) (add-hook 'python-shell-first-prompt-hook 'elpy-shell--send-setup-code t) ;; Enable Elpy-mode in the opened python buffer + (setq elpy-enabled-p t) (dolist (buffer (buffer-list)) (and (not (string-match "^ ?\\*" (buffer-name buffer))) (with-current-buffer buffer (when (string= major-mode 'python-mode) (elpy-mode t))))) - (setq elpy-enabled-p t))) + )) (defun elpy-disable () "Disable Elpy in all future Python buffers." @@ -567,6 +568,8 @@ :lighter " Elpy" (unless (derived-mode-p 'python-mode) (error "Elpy only works with `python-mode'")) + (unless elpy-enabled-p + (error "Please enable Elpy with `(elpy-enable)` before using it")) (when (boundp 'xref-backend-functions) (add-hook 'xref-backend-functions #'elpy--xref-backend nil t)) (cond @@ -884,16 +887,21 @@ (insert "\n\n")) ;; Pip not available in the rpc virtualenv - (when (and (elpy-rpc--pip-missing) - (not (gethash "jedi_version" config))) - (elpy-insert--para - "Pip doesn't seem to be installed in the dedicated virtualenv " - "created by Elpy (" (elpy-rpc-get-virtualenv-path) "). " - "This will prevent some features from working properly" - " (completion, documentation, reformatting, ...). " - "You can try reinstalling the virtualenv with `elpy-rpc-reinstall-virtualenv'. " - "If the problem persists, please report on Elpy's github page." - "\n\n")) + (when (and + (equal elpy-rpc-virtualenv-path 'default) + (elpy-rpc--pip-missing)) + (elpy-insert--para + "Pip doesn't seem to be installed in the dedicated virtualenv " + "created by Elpy (" (elpy-rpc-get-virtualenv-path) "). " + "This may prevent some features from working properly" + " (completion, documentation, reformatting, ...). " + "You can try reinstalling the virtualenv. " + "If the problem persists, please report on Elpy's github page." + "\n\n") + (widget-create 'elpy-insert--generic-button + :button-name "[Reinstall RPC virtualenv]" + :function (lambda () (elpy-rpc-reinstall-virtualenv))) + (insert "\n\n")) ;; Requested backend unavailable (when (and (gethash "rpc_python_executable" config) @@ -2279,10 +2287,10 @@ (when (interactive-p) (message "Autoformatting code with yapf.")) (elpy-yapf-fix-code)) ((elpy-config--package-available-p "autopep8") - ((when (interactive-p) message "Autoformatting code with autopep8.")) + (when (interactive-p) (message "Autoformatting code with autopep8.")) (elpy-autopep8-fix-code)) ((elpy-config--package-available-p "black") - ((when (interactive-p) message "Autoformatting code with black.")) + (when (interactive-p) (message "Autoformatting code with black.")) (elpy-black-fix-code)) (t (message "Install yapf/autopep8 to format code.")))) @@ -3090,7 +3098,7 @@ (pcase command (`global-init (require 'eldoc) - (setq eldoc-minor-mode-string nil)) + (elpy-modules-remove-modeline-lighter 'eldoc-minor-mode)) (`buffer-init ;; avoid eldoc message flickering when using eldoc and company modules jointly (eldoc-add-command-completions "company-") @@ -3115,16 +3123,17 @@ (let ((flymake-error (elpy-flymake-error-at-point))) (if flymake-error flymake-error - ;; Try getting calltip - (elpy-rpc-get-calltip - (lambda (calltip) + (elpy-rpc-get-calltip-or-oneline-docstring + (lambda (info) (cond - ((stringp calltip) - (eldoc-message calltip)) - (calltip - (let ((name (cdr (assq 'name calltip))) - (index (cdr (assq 'index calltip))) - (params (cdr (assq 'params calltip)))) + ;; INFO is a string, just display it + ((stringp info) + (eldoc-message info)) + ;; INFO is a calltip + ((string= (cdr (assq 'kind info)) "calltip") + (let ((name (cdr (assq 'name info))) + (index (cdr (assq 'index info))) + (params (cdr (assq 'params info)))) (when index (setf (nth index params) (propertize (nth index params) @@ -3137,28 +3146,29 @@ (if (version<= emacs-version "25") (format "%s%s" prefix args) (eldoc-docstring-format-sym-doc prefix args nil)))))) + ;; INFO is a oneline docstring + ((string= (cdr (assq 'kind info)) "oneline_doc") + (let ((name (cdr (assq 'name info))) + (docs (cdr (assq 'doc info)))) + (let ((prefix (propertize (format "%s: " name) + 'face + 'font-lock-function-name-face))) + (eldoc-message + (if (version<= emacs-version "25") + (format "%s%s" prefix docs) + (let ((eldoc-echo-area-use-multiline-p nil)) + (eldoc-docstring-format-sym-doc prefix docs nil))))))) + ;; INFO is nil, maybe display the current function (t - ;; Try getting oneline docstring - (elpy-rpc-get-oneline-docstring - (lambda (doc) - (cond - (doc - (let ((name (cdr (assq 'name doc))) - (doc (cdr (assq 'doc doc)))) - (let ((prefix (propertize (format "%s: " name) - 'face - 'font-lock-function-name-face))) - (eldoc-message - (if (version<= emacs-version "25") - (format "%s%s" prefix doc) - (let ((eldoc-echo-area-use-multiline-p nil)) - (eldoc-docstring-format-sym-doc prefix doc nil))))))) - ;; Give the current definition - (elpy-eldoc-show-current-function - (let ((current-defun (python-info-current-defun))) - (when current-defun - (eldoc-message - (format "In: %s()" current-defun)))))))))))) + (if elpy-eldoc-show-current-function + (let ((current-defun (python-info-current-defun))) + (when current-defun + (eldoc-message + (concat "In: " + (propertize + (format "%s()" current-defun) + 'face 'font-lock-function-name-face))))) + (eldoc-message "")))))) ;; Return the last message until we're done eldoc-last-message))) @@ -3253,15 +3263,6 @@ "^\\s-*[uU]?[rR]?\"\"\"\n?\\s-*" "Version of `hs-block-start-regexp' for docstrings.") -;; Herlpers -(defun elpy-info-docstring-p (&optional syntax-ppss) - "Return non-nil if point is in a docstring." - (save-excursion - (and (progn (python-nav-beginning-of-statement) - (looking-at "\\(\"\\|'\\)")) - (progn (forward-line -1) - (beginning-of-line) - (python-info-looking-at-beginning-of-defun))))) ;; Indicators (defun elpy-folding--display-code-line-counts (ov) "Display a folded region indicator with the number of folded lines. @@ -3408,11 +3409,11 @@ "Hide the docstring at point." (hs-life-goes-on (let ((hs-block-start-regexp elpy-docstring-block-start-regexp)) - (when (and (elpy-info-docstring-p) (not (hs-already-hidden-p))) + (when (and (python-info-docstring-p) (not (hs-already-hidden-p))) (let (beg end line-beg line-end) ;; Get first doc line (if (not (save-excursion (forward-line -1) - (elpy-info-docstring-p))) + (python-info-docstring-p))) (setq beg (line-beginning-position)) (forward-line -1) (end-of-line) @@ -3425,7 +3426,7 @@ (setq line-beg (line-number-at-pos)) ;; Get last line (if (not (save-excursion (forward-line 1) - (elpy-info-docstring-p))) + (python-info-docstring-p))) (progn (setq end (line-end-position)) (setq line-end (line-number-at-pos))) @@ -3440,7 +3441,7 @@ "Show docstring at point." (hs-life-goes-on (let ((hs-block-start-regexp elpy-docstring-block-start-regexp)) - (when (elpy-info-docstring-p) + (when (python-info-docstring-p) (hs-show-block))))) (defvar-local elpy-folding-docstrings-hidden nil @@ -3457,7 +3458,7 @@ (while (python-nav-forward-defun) (search-forward-regexp ")\\s-*:" nil t) (forward-line) - (when (and (elpy-info-docstring-p) + (when (and (python-info-docstring-p) (progn (beginning-of-line) (search-forward-regexp elpy-folding-docstring-regex @@ -3570,14 +3571,14 @@ (elpy-folding--hide-region (region-beginning) (region-end)) ;; Adapt starting regexp if on a docstring (let ((hs-block-start-regexp - (if (elpy-info-docstring-p) + (if (python-info-docstring-p) elpy-docstring-block-start-regexp hs-block-start-regexp))) ;; Hide or fold (cond ((hs-already-hidden-p) (hs-show-block)) - ((elpy-info-docstring-p) + ((python-info-docstring-p) (elpy-folding--hide-docstring-at-point)) (t (hs-hide-block)))))))) @@ -4022,5 +4023,15 @@ (rx eos)) output))) +(unless (fboundp 'python-info-docstring-p) + (defun python-info-docstring-p (&optional syntax-ppss) + "Return non-nil if point is in a docstring." + (save-excursion + (and (progn (python-nav-beginning-of-statement) + (looking-at "\\(\"\\|'\\)")) + (progn (forward-line -1) + (beginning-of-line) + (python-info-looking-at-beginning-of-defun)))))) + (provide 'elpy) ;;; elpy.el ends here diff -Nru elpy-1.33.0/elpy-pkg.el elpy-1.34.0/elpy-pkg.el --- elpy-1.33.0/elpy-pkg.el 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/elpy-pkg.el 2020-05-27 14:48:48.000000000 +0000 @@ -1,4 +1,4 @@ -(define-package "elpy" "1.33.0" +(define-package "elpy" "1.34.0" "Emacs Python Development Environment" '((company "0.9.2") (emacs "24.4") diff -Nru elpy-1.33.0/elpy-rpc.el elpy-1.34.0/elpy-rpc.el --- elpy-1.33.0/elpy-rpc.el 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/elpy-rpc.el 2020-05-27 14:48:48.000000000 +0000 @@ -1051,6 +1051,19 @@ success error))) +(defun elpy-rpc-get-calltip-or-oneline-docstring (&optional success error) + "Call the get_calltip_or_oneline_doc API function. + +Returns a calltip string or a oneline docstring for the function call at point." + (when (< (buffer-size) elpy-rpc-ignored-buffer-size) + (elpy-rpc "get_calltip_or_oneline_docstring" + (list buffer-file-name + (elpy-rpc--buffer-contents) + (- (point) + (point-min))) + success error))) + + (defun elpy-rpc-get-oneline-docstring (&optional success error) "Call the get_oneline_docstring API function. diff -Nru elpy-1.33.0/README.rst elpy-1.34.0/README.rst --- elpy-1.33.0/README.rst 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/README.rst 2020-05-27 14:48:48.000000000 +0000 @@ -84,6 +84,16 @@ .. _Readthedocs: https://elpy.readthedocs.io/en/latest/index.html +External resources +=================== + +- `Emacs: The Best Python Editor?`_ by Jon Fincher +- `Managing a Python development environment in Emacs`_ by Diego Fernández Giraldo +- `Configuring GNU emacs with elpy on MacOS`_ by Kenneth H. East + +.. _Managing a Python development environment in Emacs: https://medium.com/analytics-vidhya/managing-a-python-development-environment-in-emacs-43897fd48c6a +.. _Emacs\: The Best Python Editor?: https://realpython.com/emacs-the-best-python-editor +.. _Configuring GNU emacs with elpy on MacOS: https://east.fm/posts/configuring-gnu-emacs-with-elpy-on-macos/index.html# Contact ======= diff -Nru elpy-1.33.0/test/elpy-doc-test.el elpy-1.34.0/test/elpy-doc-test.el --- elpy-1.33.0/test/elpy-doc-test.el 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/test/elpy-doc-test.el 2020-05-27 14:48:48.000000000 +0000 @@ -11,29 +11,30 @@ (should (re-search-forward "This module provides access"))))) ;; Does not work with jedi 16.0. Jedi sometimes consider parenthesis as strings -;; (ert-deftest elpy-doc-should-find-documentation-from-inside-arguments () -;; (elpy-testcase () -;; (elpy-enable) -;; (python-mode) -;; (insert "import socket\n" -;; "socket.getaddrinfo(socket.gethostname(") -;; (save-excursion -;; (insert "))\n")) +(ert-deftest elpy-doc-should-find-documentation-from-inside-arguments () + (elpy-testcase () + (elpy-enable) + (python-mode) + (insert "import socket\n" + "socket.getaddrinfo(socket.gethostname(") + (save-excursion + (insert "))\n")) -;; (elpy-doc) + (elpy-doc) -;; (with-current-buffer "*Python Doc*" -;; (should (re-search-forward "gethostname"))) + (with-current-buffer "*Python Doc*" + (message "(buffer-string): %s" (buffer-string)) + (should (re-search-forward "gethostname"))) -;; (erase-buffer) + (erase-buffer) -;; (insert "import socket\n" -;; "socket.getaddrinfo(socket.gethostname(), ") -;; (save-excursion -;; (insert ")\n")) + (insert "import socket\n" + "socket.getaddrinfo(socket.gethostname(), ") + (save-excursion + (insert ")\n")) -;; (elpy-doc) + (elpy-doc) -;; (with-current-buffer "*Python Doc*" -;; (should (re-search-forward "getaddrinfo"))))) + (with-current-buffer "*Python Doc*" + (should (re-search-forward "getaddrinfo"))))) diff -Nru elpy-1.33.0/test/elpy-eldoc-documentation-test.el elpy-1.34.0/test/elpy-eldoc-documentation-test.el --- elpy-1.33.0/test/elpy-eldoc-documentation-test.el 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/test/elpy-eldoc-documentation-test.el 2020-05-27 14:48:48.000000000 +0000 @@ -9,7 +9,7 @@ ;; Calltip available: display that (ert-deftest elpy-eldoc-documentation-should-show-string-calltip () (elpy-testcase () - (mletf* ((elpy-rpc-get-calltip + (mletf* ((elpy-rpc-get-calltip-or-oneline-docstring (callback) (funcall callback "Queue.cancel_join_thread()")) (calltip nil) @@ -21,10 +21,11 @@ (ert-deftest elpy-eldoc-documentation-should-show-object-calltip () (elpy-testcase () - (mletf* ((elpy-rpc-get-calltip + (mletf* ((elpy-rpc-get-calltip-or-oneline-docstring (callback) (funcall callback '((name . "cancel_join_thread") (index . 0) + (kind . "calltip") (params "foo" "bar")))) (calltip nil) (eldoc-message (tip) (setq calltip tip))) @@ -40,10 +41,11 @@ (ert-deftest elpy-eldoc-documentation-should-not-fail-for-index-nil () (elpy-testcase () - (mletf* ((elpy-rpc-get-calltip + (mletf* ((elpy-rpc-get-calltip-or-oneline-docstring (callback) (funcall callback '((name . "cancel_join_thread") (index . nil) + (kind . "calltip") (params . nil)))) (calltip nil) ;; without UI, the minibuffer width is only 9, @@ -59,12 +61,10 @@ ;; No calltip: display function oneline docstring (ert-deftest elpy-eldoc-documentation-should-show-object-onelinedoc () (elpy-testcase () - (mletf* ((elpy-rpc-get-calltip - (callback) - (funcall callback nil)) - (elpy-rpc-get-oneline-docstring + (mletf* ((elpy-rpc-get-calltip-or-oneline-docstring (callback) (funcall callback '((name . "cancel_join_thread()") + (kind . "oneline_doc") (doc . "This function does things.")))) (doc nil) (window-width (buff) 100000000) @@ -84,8 +84,8 @@ ;; No calltip and docstring: display current edited function (ert-deftest elpy-eldoc-documentation-should-use-current-defun-if-nothing-else () (elpy-testcase () - (mletf* ((elpy-rpc-get-calltip (callback) (funcall callback nil)) - (elpy-rpc-get-oneline-docstring (callback) (funcall callback nil)) + (mletf* ((elpy-rpc-get-calltip-or-oneline-docstring (callback) + (funcall callback nil)) (calltip nil) (eldoc-message (tip) (setq calltip tip)) (python-info-current-defun () "FooClass.method")) @@ -97,8 +97,8 @@ ;; No calltip, docstring or current function: display nothing (ert-deftest elpy-eldoc-documentation-should-return-nil-without-defun () (elpy-testcase () - (mletf* ((elpy-rpc-get-calltip (callback) (funcall callback nil)) - (elpy-rpc-get-oneline-docstring (callback) (funcall callback nil)) + (mletf* ((elpy-rpc-get-calltip-or-oneline-docstring (callback) + (funcall callback nil)) (calltip nil) (eldoc-message (tip) (setq calltip tip)) (python-info-current-defun () nil)) diff -Nru elpy-1.33.0/test/elpy-folding-fold-all-comments-test.el elpy-1.34.0/test/elpy-folding-fold-all-comments-test.el --- elpy-1.33.0/test/elpy-folding-fold-all-comments-test.el 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/test/elpy-folding-fold-all-comments-test.el 2020-05-27 14:48:48.000000000 +0000 @@ -20,25 +20,27 @@ "# Another comment on" "# two lines !" "var2 = foo(var1, 4)") + (elpy-enable) (python-mode) - (elpy-mode) ;; Fold all comments (elpy-folding-toggle-comments) (let* ((overlays (overlays-in (point-min) (point-max))) overlay) - (should (= 6 (length overlays))) ;; first two lines comment - (setq overlay (nth 5 overlays)) + (setq overlay (elpy-get-overlay-at 49 'comment)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'comment)) (should (= (overlay-start overlay) 49)) (should (= (overlay-end overlay) 83)) ;; second three lines comment - (setq overlay (nth 2 overlays)) + (setq overlay (elpy-get-overlay-at 184 'comment)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'comment)) (should (= (overlay-start overlay) 184)) (should (= (overlay-end overlay) 229)) ;; third two lines comment - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 340 'comment)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'comment)) (should (= (overlay-start overlay) 340)) (should (= (overlay-end overlay) 354))) @@ -46,8 +48,5 @@ (should (= (point) 177)) ;; Unfold all comments (elpy-folding-toggle-comments) - (let* ((overlays (overlays-in (point-min) (point-max))) - overlay) - (should (= 3 (length overlays)))) ;; Position (should (= (point) 177)))) diff -Nru elpy-1.33.0/test/elpy-folding-fold-all-docstrings-test.el elpy-1.34.0/test/elpy-folding-fold-all-docstrings-test.el --- elpy-1.33.0/test/elpy-folding-fold-all-docstrings-test.el 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/test/elpy-folding-fold-all-docstrings-test.el 2020-05-27 14:48:48.000000000 +0000 @@ -29,19 +29,21 @@ " print(mess)" "" "var2 = foo(var1, 4)") + (elpy-enable) (python-mode) - (elpy-mode) (elpy-folding-toggle-docstrings) (let* ((overlays (overlays-in (point-min) (point-max))) overlay) (should (= 6 (length overlays))) ;; First docstring - (setq overlay (nth 3 overlays)) + (setq overlay (elpy-get-overlay-at 97 'docstring)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'docstring)) (should (= (overlay-start overlay) 97)) (should (= (overlay-end overlay) 124)) ;; Second docstring - (setq overlay (nth 1 overlays)) + (setq overlay (elpy-get-overlay-at 206 'docstring)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'docstring)) (should (= (overlay-start overlay) 206)) (should (= (overlay-end overlay) 280))) diff -Nru elpy-1.33.0/test/elpy-folding-fold-blocks-test.el elpy-1.34.0/test/elpy-folding-fold-blocks-test.el --- elpy-1.33.0/test/elpy-folding-fold-blocks-test.el 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/test/elpy-folding-fold-blocks-test.el 2020-05-27 14:48:48.000000000 +0000 @@ -6,13 +6,13 @@ "def foo(_|_a, b):" " c = a + b" "var2 = foo(var1, 4)") + (elpy-enable) (python-mode) - (elpy-mode) (elpy-folding-toggle-at-point) (let* ((overlays (apply 'nconc (overlay-lists))) overlay) - (should (= 2 (length overlays))) - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 25 'code)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) (should (= (overlay-start overlay) 25)) (should (or (= (overlay-end overlay) 37) @@ -20,9 +20,6 @@ (should (= (point) 14)) ;; Unfold (elpy-folding-toggle-at-point) - (let* ((overlays (apply 'nconc (overlay-lists))) - overlay) - (should (= 1 (length overlays)))) ;; Position (should (= (point) 14)))) @@ -34,13 +31,13 @@ "def foo(a, b):" " c = _|_a + b" "var2 = foo(var1, 4)") + (elpy-enable) (python-mode) - (elpy-mode) (elpy-folding-toggle-at-point) (let* ((overlays (apply 'nconc (overlay-lists))) overlay) - (should (= 2 (length overlays))) - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 25 'code)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) (should (= (overlay-start overlay) 25)) (should (or (= (overlay-end overlay) 37) @@ -48,9 +45,6 @@ (should (= (point) 14)) ;; Unfold (elpy-folding-toggle-at-point) - (let* ((overlays (apply 'nconc (overlay-lists))) - overlay) - (should (= 1 (length overlays)))) ;; Position (should (= (point) 14)))) @@ -64,11 +58,9 @@ " return c" "_|_" "var2 = foo(var1, 4)") + (elpy-enable) (python-mode) - (elpy-mode) (elpy-folding-toggle-at-point) - (let ((overlays (apply 'nconc (overlay-lists)))) - (should (= 1 (length overlays)))) ;; Position (should (= (point) 49)))) @@ -84,13 +76,13 @@ " print(mess)" " return _|_mess" "var2 = foo(var1, 4)") + (elpy-enable) (python-mode) - (elpy-mode) (elpy-folding-toggle-at-point) (let* ((overlays (apply 'nconc (overlay-lists))) overlay) - (should (= 3 (length overlays))) - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 54 'code)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) (should (= (overlay-start overlay) 54)) (should (or (= (overlay-end overlay) 100) @@ -98,9 +90,6 @@ (should (= (point) 43)) ;; Unfold (elpy-folding-toggle-at-point) - (let* ((overlays (apply 'nconc (overlay-lists))) - overlay) - (should (= 2 (length overlays)))) ;; Position (should (= (point) 43)))) @@ -118,13 +107,13 @@ " print(mess)" " return _|_mess" "var2 = foo(var1, 4)") + (elpy-enable) (python-mode) - (elpy-mode) (elpy-folding-toggle-at-point) (let* ((overlays (apply 'nconc (overlay-lists))) overlay) - (should (= 4 (length overlays))) - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 104 'code)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) (should (= (overlay-start overlay) 104)) (should (or (= (overlay-end overlay) 150) @@ -132,9 +121,6 @@ (should (= (point) 93)) ;; Unfold (elpy-folding-toggle-at-point) - (let* ((overlays (apply 'nconc (overlay-lists))) - overlay) - (should (= 3 (length overlays)))) ;; Position (should (= (point) 93)))) @@ -152,13 +138,13 @@ " print(mess)" " return mess" "var2 = foo(var1, 4)") + (elpy-enable) (python-mode) - (elpy-mode) (elpy-folding-toggle-at-point) (let* ((overlays (apply 'nconc (overlay-lists))) overlay) - (should (= 4 (length overlays))) - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 29 'code)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) (should (= (overlay-start overlay) 29)) (should (or (= (overlay-end overlay) 150) @@ -166,8 +152,5 @@ (should (= (point) 16)) ;; Unfold (elpy-folding-toggle-at-point) - (let* ((overlays (apply 'nconc (overlay-lists))) - overlay) - (should (= 3 (length overlays)))) ;; Position (should (= (point) 16)))) diff -Nru elpy-1.33.0/test/elpy-folding-fold-comments-test.el elpy-1.34.0/test/elpy-folding-fold-comments-test.el --- elpy-1.33.0/test/elpy-folding-fold-comments-test.el 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/test/elpy-folding-fold-comments-test.el 2020-05-27 14:48:48.000000000 +0000 @@ -15,22 +15,19 @@ " print(mess)" " return mess" "var2 = foo(var1, 4)") + (elpy-enable) (python-mode) - (elpy-mode) (elpy-folding-toggle-at-point) (let* ((overlays (overlays-in (point-min) (point-max))) overlay) - (should (= 4 (length overlays))) - (setq overlay (nth 1 overlays)) + (setq overlay (elpy-get-overlay-at 111 'comment)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'comment)) (should (= (overlay-start overlay) 111)) (should (= (overlay-end overlay) 156))) (should (= (point) 92)) ;; Unfold (elpy-folding-toggle-at-point) - (let* ((overlays (overlays-in (point-min) (point-max))) - overlay) - (should (= 3 (length overlays)))) ;; Position (should (= (point) 92)))) @@ -49,10 +46,7 @@ " print(mess)" " return mess" "var2 = foo(var1, 4)") + (elpy-enable) (python-mode) - (elpy-mode) (elpy-folding-toggle-at-point) - (let* ((overlays (overlays-in (point-min) (point-max))) - overlay) - (should (= 3 (length overlays)))) (should (= (point) 112)))) diff -Nru elpy-1.33.0/test/elpy-folding-fold-docstrings-test.el elpy-1.34.0/test/elpy-folding-fold-docstrings-test.el --- elpy-1.33.0/test/elpy-folding-fold-docstrings-test.el 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/test/elpy-folding-fold-docstrings-test.el 2020-05-27 14:48:48.000000000 +0000 @@ -18,28 +18,19 @@ " print(mess)" " return mess" "var2 = foo(var1, 4)") + (elpy-enable) (python-mode) - (elpy-mode) (elpy-folding-toggle-at-point) (let* ((overlays (overlays-in (point-min) (point-max))) overlay) - ;; (dolist (overlay overlays) - ;; (message "overlay from %s to %s on: %s" - ;; (overlay-start overlay) - ;; (overlay-end overlay) - ;; (buffer-substring (overlay-start overlay) - ;; (overlay-end overlay)))) - (should (= 4 (length overlays))) - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 138 'docstring)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'docstring)) (should (= (overlay-start overlay) 138)) (should (= (overlay-end overlay) 212))) (should (= (point) 109)) ;; Unfold (elpy-folding-toggle-at-point) - (let* ((overlays (overlays-in (point-min) (point-max))) - overlay) - (should (= 3 (length overlays)))) ;; Position (should (= (point) 109)))) @@ -64,22 +55,19 @@ " print(mess)" " return mess" "var2 = foo(var1, 4)") + (elpy-enable) (python-mode) - (elpy-mode) (elpy-folding-toggle-at-point) (let* ((overlays (overlays-in (point-min) (point-max))) overlay) - (should (= 4 (length overlays))) - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 142 'docstring)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'docstring)) (should (= (overlay-start overlay) 142)) (should (= (overlay-end overlay) 216))) (should (= (point) 117)) ;; Unfold (elpy-folding-toggle-at-point) - (let* ((overlays (overlays-in (point-min) (point-max))) - overlay) - (should (= 3 (length overlays)))) ;; Position (should (= (point) 117)))) @@ -98,15 +86,16 @@ " print(mess)" " return mess" "var2 = foo(var1, 4)") + (elpy-enable) (python-mode) - (elpy-mode) (elpy-folding-toggle-at-point) - (let* ((overlays (overlays-in (point-min) (point-max))) - overlay) - (should (= 3 (length overlays)))))) + (let* ((overlays (overlays-in (point-min) (point-max)))) + (dolist (overlay overlays) + (should-not (overlay-get overlay 'hs)))))) (ert-deftest elpy-fold-at-point-should-NOT-fold-strings () (elpy-testcase () + (add-to-list 'elpy-modules 'elpy-module-folding) (set-buffer-string-with-point "var1 = 45" "class foo(object):" @@ -114,17 +103,19 @@ " self.a = a" " self.b = b" " def bar(mess):" - " \" This is just _|_a string\"" " mess *= 2" + " \" This is just _|_a string\"" " print(mess)" " return mess" "var2 = foo(var1, 4)") + (elpy-enable) (python-mode) - (elpy-mode) - (elpy-folding-toggle-at-point) - (let* ((overlays (overlays-in (point-min) (point-max))) - overlay) - (should (= 3 (length overlays)))))) + (let ((nmb-overlays (length (overlays-in (point-min) (point-max))))) + (elpy-folding-toggle-at-point) + (let* ((overlays (overlays-in (point-min) (point-max))) + overlay) + (dolist (overlay overlays) + (should-not (eq (overlay-get overlay 'hs) 'docstring))))))) (ert-deftest elpy-fold-at-point-should-NOT-fold-strings-2 () (elpy-testcase () @@ -137,18 +128,18 @@ " self.b = b" " def bar(mess):" " mess *= 2" - " \" This is just _|_a string\"" + " \"\"\" This is just _|_a string\"\"\"" " print(mess)" " return mess" "var2 = foo(var1, 4)") + (elpy-enable) (python-mode) - (elpy-mode) - (elpy-folding-toggle-at-point) - (let* ((overlays (overlays-in (point-min) (point-max))) - overlay) - (should (= 4 (length overlays))) - (dolist (overlay overlays) - (should-not (eq (overlay-get overlay 'hs) 'docstring)))))) + (let ((nmb-overlays (length (overlays-in (point-min) (point-max))))) + (elpy-folding-toggle-at-point) + (let* ((overlays (overlays-in (point-min) (point-max))) + overlay) + (dolist (overlay overlays) + (should-not (eq (overlay-get overlay 'hs) 'docstring))))))) (ert-deftest elpy-fold-at-point-should-NOT-fold-strings-3 () (elpy-testcase () @@ -165,13 +156,13 @@ " print(mess)" " return mess" "var2 = foo(var1, 4)") + (elpy-enable) (python-mode) - (elpy-mode) (elpy-folding-toggle-at-point) (let* ((overlays (overlays-in (point-min) (point-max))) overlay) - (should (= 4 (length overlays))) - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 104 'code)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) (should (= (overlay-start overlay) 104)) (should (or (= (overlay-end overlay) 190) @@ -197,13 +188,13 @@ " print(mess)" " return mess" "var2 = foo(var1, 4)") + (elpy-enable) (python-mode) - (elpy-mode) (elpy-folding-toggle-at-point) (let* ((overlays (overlays-in (point-min) (point-max))) overlay) - (should (= 4 (length overlays))) - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 104 'code)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) (should (= (overlay-start overlay) 104)) (should (or (= (overlay-end overlay) 229) diff -Nru elpy-1.33.0/test/elpy-folding-fold-leafs-test.el elpy-1.34.0/test/elpy-folding-fold-leafs-test.el --- elpy-1.33.0/test/elpy-folding-fold-leafs-test.el 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/test/elpy-folding-fold-leafs-test.el 2020-05-27 14:48:48.000000000 +0000 @@ -14,18 +14,20 @@ " print(_|_mess)" " return mess" "var2 = foo(var1, 4)") + (elpy-enable) (python-mode) - (elpy-mode) (elpy-folding-hide-leafs) (let* ((overlays (overlays-in (point-min) (point-max))) overlay) - (should (= 6 (length overlays))) - (setq overlay (nth 3 overlays)) + + (setq overlay (elpy-get-overlay-at 57 'code)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) (should (= (overlay-start overlay) 57)) (should (or (= (overlay-end overlay) 87) (= (overlay-end overlay) 88))) - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 138 'code)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) (should (= (overlay-start overlay) 138)) (should (or (= (overlay-end overlay) 156) @@ -34,8 +36,5 @@ (should (= (point) 151)) ;; Unfold (hs-show-all) - (let* ((overlays (overlays-in (point-min) (point-max))) - overlay) - (should (= 4 (length overlays)))) ;; Position (should (= (point) 151)))) diff -Nru elpy-1.33.0/test/elpy-folding-fold-on-click-test.el elpy-1.34.0/test/elpy-folding-fold-on-click-test.el --- elpy-1.33.0/test/elpy-folding-fold-on-click-test.el 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/test/elpy-folding-fold-on-click-test.el 2020-05-27 14:48:48.000000000 +0000 @@ -6,14 +6,14 @@ "def foo(_|_a, b):" " c = a + b" "var2 = foo(var1, 4)") + (elpy-enable) (python-mode) - (elpy-mode) (mletf* ((mouse-set-point (event) (goto-char (point)))) (elpy-folding--click-fringe nil)) (let* ((overlays (apply 'nconc (overlay-lists))) overlay) - (should (= 2 (length overlays))) - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 25 'code)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) (should (= (overlay-start overlay) 25)) (should (or (= (overlay-end overlay) 37) @@ -22,9 +22,6 @@ ;; Unfold (mletf* ((mouse-set-point (event) (goto-char (point)))) (elpy-folding--click-fringe nil)) - (let* ((overlays (apply 'nconc (overlay-lists))) - overlay) - (should (= 1 (length overlays)))) ;; Position (should (= (point) 14)))) @@ -36,14 +33,14 @@ "def foo(_|_a, b):" " c = a + b" "var2 = foo(var1, 4)") + (elpy-enable) (python-mode) - (elpy-mode) (mletf* ((mouse-set-point (event) (goto-char (point)))) (elpy-folding--click-fringe nil)) (let* ((overlays (apply 'nconc (overlay-lists))) overlay) - (should (= 2 (length overlays))) - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 25 'code)) + (should overlay) (should (eq (overlay-get overlay 'hs) 'code)) (should (= (overlay-start overlay) 25)) (should (or (= (overlay-end overlay) 37) @@ -55,8 +52,5 @@ (posn-point (position) (point)) (window-buffer (window) (current-buffer))) (elpy-folding--click-text nil)) - (let* ((overlays (apply 'nconc (overlay-lists))) - overlay) - (should (= 1 (length overlays)))) ;; Position (should (= (point) 25)))) diff -Nru elpy-1.33.0/test/elpy-folding-should-mark-foldable-lines-test.el elpy-1.34.0/test/elpy-folding-should-mark-foldable-lines-test.el --- elpy-1.33.0/test/elpy-folding-should-mark-foldable-lines-test.el 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/test/elpy-folding-should-mark-foldable-lines-test.el 2020-05-27 14:48:48.000000000 +0000 @@ -18,23 +18,26 @@ " print(mess)" " return mess" "var2 = foo(var1, 4)") + (elpy-enable) (python-mode) - (elpy-mode) (let* ((overlays (overlays-in (point-min) (point-max))) overlay) (should (= 3 (length overlays))) ;; Second mark - (setq overlay (nth 2 overlays)) + (setq overlay (elpy-get-overlay-at 11 nil)) + (should overlay) (should (eq (overlay-get overlay 'hs) nil)) (should (= (overlay-start overlay) 11)) (should (= (overlay-end overlay) 29)) ;; Second mark - (setq overlay (nth 1 overlays)) + (setq overlay (elpy-get-overlay-at 30 nil)) + (should overlay) (should (eq (overlay-get overlay 'hs) nil)) (should (= (overlay-start overlay) 30)) (should (= (overlay-end overlay) 57)) ;; Third mark - (setq overlay (nth 0 overlays)) + (setq overlay (elpy-get-overlay-at 88 nil)) + (should overlay) (should (eq (overlay-get overlay 'hs) nil)) (should (= (overlay-start overlay) 88)) (should (= (overlay-end overlay) 104))))) diff -Nru elpy-1.33.0/test/elpy-mode-test.el elpy-1.34.0/test/elpy-mode-test.el --- elpy-1.33.0/test/elpy-mode-test.el 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/test/elpy-mode-test.el 2020-05-27 14:48:48.000000000 +0000 @@ -3,10 +3,16 @@ (let ((major-mode 'not-python-mode)) (should-error (elpy-mode))))) +(ert-deftest elpy-mode-should-fail-when-elpy-not-activated () + (elpy-testcase () + (python-mode) + (should-error (elpy-mode)))) + (ert-deftest elpy-mode-should-run-buffer-init-on-start () (elpy-testcase () (python-mode) (mletf* ((buffer-init-called nil) + (elpy-enabled-p t) (elpy-modules-buffer-init () (setq buffer-init-called t))) @@ -17,6 +23,7 @@ (ert-deftest elpy-mode-should-run-buffer-stop-on-stop () (elpy-testcase () + (elpy-enable) (python-mode) (mletf* ((buffer-stop-called nil) (elpy-modules-buffer-stop diff -Nru elpy-1.33.0/test/elpy-open-and-indent-line-above-test.el elpy-1.34.0/test/elpy-open-and-indent-line-above-test.el --- elpy-1.33.0/test/elpy-open-and-indent-line-above-test.el 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/test/elpy-open-and-indent-line-above-test.el 2020-05-27 14:48:48.000000000 +0000 @@ -3,8 +3,8 @@ ;; (ert-deftest elpy-open-and-indent-line-below () ;; (elpy-testcase () +;; (elpy-enable) ;; (python-mode) -;; (elpy-mode 1) ;; (insert-source ;; "def foo():" ;; " x = 5") diff -Nru elpy-1.33.0/test/elpy-open-and-indent-line-below-test.el elpy-1.34.0/test/elpy-open-and-indent-line-below-test.el --- elpy-1.33.0/test/elpy-open-and-indent-line-below-test.el 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/test/elpy-open-and-indent-line-below-test.el 2020-05-27 14:48:48.000000000 +0000 @@ -3,8 +3,8 @@ ;; (ert-deftest elpy-open-and-indent-line-below () ;; (elpy-testcase () +;; (elpy-enable) ;; (python-mode) -;; (elpy-mode 1) ;; (insert "def foo():\n") ;; (goto-char 2) ;; (elpy-open-and-indent-line-below) diff -Nru elpy-1.33.0/test/test-helper.el elpy-1.34.0/test/test-helper.el --- elpy-1.33.0/test/test-helper.el 2020-03-23 16:47:48.000000000 +0000 +++ elpy-1.34.0/test/test-helper.el 2020-05-27 14:48:48.000000000 +0000 @@ -223,5 +223,11 @@ ,(buffer-string-with-point))) (put 'buffer-be 'ert-explainer 'buffer-be-explainer) +(defun elpy-get-overlay-at (start kind) + (dolist (tmp-overlay overlays overlay) + (when (and (= (overlay-start tmp-overlay) start) + (eq (overlay-get tmp-overlay 'hs) kind)) + (setq overlay tmp-overlay)))) + (setq yas-verbosity 0) (setq yas-snippet-dirs ())