├── CONTRIBUTING.md ├── CREDITS ├── INSTALL ├── INSTALL-INFO-FILES ├── IPYTHON ├── LICENSE ├── MANIFEST.in ├── NEWS ├── PROBLEMS.org ├── README-PYMACS.org ├── README.md ├── README_AUTOPAIR.org ├── README_DEVEL.org ├── ToDo.org ├── byte-compile-directory.sh ├── completion ├── auto-complete-pycomplete.el ├── company-pycomplete.el ├── pycomplete.el ├── pycomplete.py └── test_pycomplete.py ├── devel ├── README ├── fundocu2infoformats.el ├── fundocu2infoformats.sh ├── py-report-comint-variable-setting.el ├── python-components-create-menu.el ├── python-mode-create-menu.el ├── python-mode-utils.el ├── python-mode-vars.el ├── python-mode-write-menu.el ├── python-mode-write-tests.el └── python-shell-install-example-buffer.el ├── doc ├── commands-auto-complete-pycomplete.org ├── commands-auto-complete-pycomplete.rst ├── commands-autopair.org ├── commands-autopair.rst ├── commands-company-pycomplete.org ├── commands-company-pycomplete.rst ├── commands-py-smart-operator.org ├── commands-py-smart-operator.rst ├── commands-pycomplete.org ├── commands-pycomplete.rst ├── commands-python-mode.org ├── commands-python-mode.rst ├── commands-smart-operator.org ├── commands-smart-operator.rst ├── variables-python-mode.org └── variables-python-mode.rst ├── extensions └── python-components-skeletons.el ├── py-setup-ert-tests.el ├── pyflakespep8.py ├── python-mode-compile.sh ├── python-mode-pkg.el ├── python-mode.el ├── run-tests.sh ├── setup.py ├── test ├── UnicodeEncodeError-lp-550661-test.py ├── UnicodeEncodeError-python2-lp-550661-test.py ├── UnicodeEncodeError-python3-lp-550661-test.py ├── doctest-mode.el ├── py-completion-tests.el ├── py-ert-always-split-lp-1361531-tests.el ├── py-ert-always-split-tests.el ├── py-ert-beginning-tests.el ├── py-ert-delete-tests.el ├── py-ert-end-tests.el ├── py-ert-execute-block-test.el ├── py-ert-execute-region-test.el ├── py-ert-fill-tests.el ├── py-ert-font-lock-test.el ├── py-ert-forward-tests.el ├── py-ert-function-tests.el ├── py-ert-hide-tests.el ├── py-ert-indent-tests-1.el ├── py-ert-indent-tests.el ├── py-ert-interactive-tests.el ├── py-ert-just-two-split-lp-1361531-tests.el ├── py-ert-misc-tests.el ├── py-ert-navigation-tests.el ├── py-ert-position-functions-test.el ├── py-ert-scope-tests.el ├── py-ert-variablen-tests.el ├── py-executable-python-tests.el ├── py-execute-region-commandp-test.el ├── py-extra-tests.el ├── py-interactive-tests.el ├── py-non-travis-tests.el ├── py-setup-ert-tests.el ├── py-shell-arg-ert-tests.el ├── py-shell-completion-tests.el ├── py-shell-ert-tests.el ├── py-split-window-on-execute-lp-1361531-test.el ├── py-split-window-on-execute-test.el ├── python-extended-executes-test.el ├── python-mode-ert-tests-1.sh ├── python-mode-ert-tests-2.sh ├── python-mode-ert-tests.sh ├── python-mode-syntax-test.el ├── python-mode-test.el ├── python-mode-tests-2.sh ├── python-mode-tests.sh ├── syntax-test.sh └── test-triple-strings.py └── website ├── .cvsignore ├── .rsync-excludes ├── Makefile ├── PMGenerator.py ├── calcroot.py ├── docs ├── .cvsignore ├── Makefile ├── basics.ht ├── customize.ht ├── index.ht ├── links.h └── related.ht ├── index.ht ├── links.h └── make.rules /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Please reporte bugs 2 | 3 | Always report a bug from latest version. Maybe update via M-x list-packages RET. 4 | Or download from here. -------------------------------------------------------------------------------- /CREDITS: -------------------------------------------------------------------------------- 1 | Many people have contributed code in python-mode.el's 2 | history. Many have assisted and inspired development by 3 | proposals, requests and bug-reports. Should you feel 4 | one of them, but don't find your name listed --in 5 | alphabetical order-- below, please write to developers 6 | at python-mode@python.org. 7 | 8 | Aaron Culich 9 | Alexander Boettcher 10 | Andrea Crotti 11 | Andreas Röhler http://launchpad.net/s-x-emacs-werkstatt/ 12 | Andrew Uzilov 13 | Andy Smith 14 | Aurel Wisse 15 | Austin Bingham 16 | Barry A. Warsaw 17 | Benjamin Peterson 18 | Bryce Harrington 19 | Chong Yidong 20 | Chris McDonough 21 | Christoph Conrad 22 | Christoph Scholtes 23 | Conny Kühne 24 | Dan Davison 25 | Dan Nicolaescu 26 | Dave Love http://www.loveshack.ukfsn.org/emacs/ 27 | David Cagle 28 | David Poole 29 | David Reitter 30 | Don Bennett 31 | Drew Adams 32 | Ed Loper 33 | Ed McCardell 34 | Eric Hanchrow 35 | Eric S. Johansson 36 | Erik Allik 37 | Fabián Ezequiel Gallina http://github.com/fgallina/python.el 38 | Felix Geller 39 | François Pinard 40 | Gabriele Lanaro https://github.com/gabrielelanaro 41 | Gennady N. Uraltsev 42 | Georg Brandl 43 | Glenn Linderman 44 | Glenn Morris 45 | Grady Weyenberg 46 | James Jong 47 | James Troup 48 | Jean-Francois Caron 49 | Jeff Dairiki 50 | Jeffrey Spencer 51 | Jesse Legg 52 | Joao Tavora http://autopair.googlecode.com 53 | John Wiegley 54 | Jonathan Waltman 55 | Juan A Rodriquez 56 | Juanma Barranquero 57 | Kao Félix 58 | Keegan Carruthers-Smith http://people.cs.uct.ac.za/~ksmith/2011/better-python-flymake-integration-in-emacs.html 59 | Ken Manheimer 60 | Khaoz 61 | Kim F. Storm 62 | Laimonas Vebra 63 | Lars Bungum 64 | Luis-Dominique Dubeau 65 | Martin Rudalics 66 | Matsui Tetsushi 67 | Matthew Willson 68 | Mike Mazurek 69 | Miles Bader 70 | Nathan R. Yergler 71 | Neilen Marais 72 | Nick Roberts 73 | Nikolaj Schumacher http://nschum.de/src/emacs/company/ 74 | Patrik Jonsson 75 | Paul Pogonyshev 76 | Phil Rufflewind 77 | Pierre Rouleau 78 | Reinout van Rees http://reinout.vanrees.org/weblog/2010/05/11/pep8-pyflakes-emacs.html 79 | Richard Everson 80 | Richard Riley http://www.emacswiki.org/emacs/RichardRiley 81 | Richard Stallman 82 | Richard Stanton 83 | Rick Bielawski 84 | Rocky Bernstein 85 | Rohan Nicholls 86 | Roman Dzvinkovsky 87 | Ryan Kinnear https://gitlab.com/RJTK 88 | Russell Sim 89 | Ryan Kaskel RyanKaskel.com 90 | Ryan Thompson 91 | Seong-Kook Shin 92 | Simon Safar 93 | Skip Montanaro 94 | Stefan Monnier 95 | Stéphane Castelli 96 | Tavis Rudd 97 | Terry Jones 98 | Thomas Caswell 99 | Tim Peters 100 | Titus Barik 101 | Tom Roche 102 | Tom Willemsen 103 | Urs Fleisch 104 | Vinicius Jose Latorre 105 | Wilfred Hughes http://www.wilfred.me.uk 106 | William Xu 107 | Yuri D'Elia 108 | Yuri Goncharov -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | Put the respective lines into your Emacs initialisation file: 2 | 3 | (add-to-list 'load-path "PATH/TO/PYTHON-MODE/") 4 | (setq py-install-directory "PATH/TO/PYTHON-MODE/") 5 | (require 'python-mode) 6 | 7 | To change the Python default shell use 8 | 9 | M-x customize-variable py-shell-name 10 | 11 | or write 12 | 13 | (setq py-shell-name "MY-PYTHON") 14 | resp. 15 | (setq py-shell-name "PATH/TO/MY-PYTHON") 16 | 17 | IPython users for example may insert "ipython" with 18 | M-x customize-variable py-shell-name 19 | 20 | or in init-file 21 | 22 | (setq py-shell-name "ipython") 23 | resp. 24 | (setq py-shell-name "PATH/TO/ipython") 25 | -------------------------------------------------------------------------------- /INSTALL-INFO-FILES: -------------------------------------------------------------------------------- 1 | Wilfred Hughes provides a tool which seems to permit 2 | building info docu for any Python version. 3 | 4 | Source here: 5 | http://github.com/wilfred/python-info 6 | 7 | After unpacking, either follow the recipes in README.md 8 | 9 | or, when aiming for an info of a different Python 10 | version, edit the Makefile in directory build. Replace 11 | the hard-coded Python-version by the one you need: 12 | Worked nicely here with Python 3.3.0 13 | 14 | This will create `build/python.texi`. 15 | 16 | Afterwards run ‘makeinfo’ at the texi-file. 17 | 18 | In order to get them recognised by Emacs info-reader, 19 | maybe copy the info-files into a known info-directory 20 | and edit the "dir" file there - the head of newly 21 | created info-files containes a line, which must appear 22 | in file "dir". 23 | 24 | At Linux that directory which keeps the info-files 25 | should appear in $INFOPATH. 26 | 27 | ###### 28 | 29 | ‘info-lookup-symbol’ needs patched python-info.el available at 30 | http://bitbucket.org/andreas_roehler/pydoc-info 31 | 32 | Thanks Jonathan Waltman providing the original python-info.el: 33 | http://bitbucket.org/jonwaltman/pydoc-info 34 | 35 | -------------------------------------------------------------------------------- /IPYTHON: -------------------------------------------------------------------------------- 1 | Put the respective lines into your Emacs initialisation file: 2 | 3 | (add-to-list 'load-path "PATH/TO/PYTHON-MODE/") 4 | (setq py-install-directory "PATH/TO/PYTHON-MODE/") 5 | (require 'python-mode) 6 | 7 | To change the Python default shell use 8 | 9 | M-x customize-variable py-shell-name ipython 10 | 11 | or in init-file 12 | 13 | (setq py-shell-name "ipython") 14 | resp. 15 | (setq py-shell-name "PATH/TO/ipython") 16 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include INSTALL 2 | include INSTALL-INFO-FILES 3 | include LICENSE 4 | include NEWS 5 | include README 6 | include README-AUTOPAIR.org 7 | include README-ROPEMACS 8 | include README_DEVEL.org 9 | include README_VIRTUALENV 10 | include byte-compile-directory.sh 11 | include completion/auto-complete-pycomplete.el 12 | include completion/company-pycomplete.el 13 | include completion/pycomplete.el 14 | include completion/pycomplete.py 15 | include completion/test_pycomplete.py 16 | include doc/commands-python-mode.org 17 | include doc/commands-python-mode.rst 18 | include doc/variables-python-mode.org 19 | include doc/variables-python-mode.rst 20 | include python-mode.el 21 | include test/doctest-mode.el 22 | include test/py-ert-always-split-lp-1361531-tests.el 23 | include test/py-ert-beginning-tests.el 24 | include test/py-ert-execute-block-test.el 25 | include test/py-ert-execute-region-test.el 26 | include test/py-ert-fill.el 27 | include test/py-ert-forward-tests.el 28 | include test/py-ert-function-tests.el 29 | include test/py-ert-indent-tests-1.el 30 | include test/py-ert-just-two-split-lp-1361531-tests.el 31 | include test/py-ert-misc-tests-1.el 32 | include test/py-ert-navigation-tests-1.el 33 | include test/py-ert-scope-tests-1.el 34 | include test/py-ert-variablen-tests.el 35 | include test/py-execute-region-commandp-test.el 36 | include test/py-shell-arg-ert-tests.el 37 | include test/py-ert-delete-tests-1.el 38 | include test/py-extra-tests.el 39 | -------------------------------------------------------------------------------- /PROBLEMS.org: -------------------------------------------------------------------------------- 1 | * interactive Python shell 2 | 3 | in some cases, with a new Emacs, py-shell seems not to receive 4 | input, while listed by M-x list-processes RET looks okay and no 5 | error elsewhere. Killing the comint-buffer and open that shell 6 | again helps AFAICT. 7 | 8 | If it's about receiving results only, executing via non-interactive 9 | Python (‘py-fast-process-p’) might be preferable. 10 | 11 | * Window-management 12 | From choices offered by ‘py-split-window-on-execute’ no bugs are 13 | known with ‘just-two’ --the behaviour of version 6.1.3-- and ‘nil’, 14 | whilst ‘always’ and ‘t’ have some 15 | 16 | -------------------------------------------------------------------------------- /README-PYMACS.org: -------------------------------------------------------------------------------- 1 | * python-mode comes with a folder "completion" 2 | 3 | If Pymacs based auto-complete shall be used make sure the directory 4 | is in your load-path. In case `Pymacs' was installed via ‘make’ on 5 | your system, do not activate inlined one. Keep ‘py-load-pymacs-p’ 6 | nil. 7 | 8 | Otherwise setting ‘py-load-pymacs-p’ to ‘t’ should enable a 9 | company-based auto-completion - alongside with 10 | ‘py-company-pycomplete-p’. 11 | 12 | * Troubeshooting 13 | On systems which run Python3 as default 14 | setting 15 | export PYMACS_PYTHON=python2 16 | was reported being useful. 17 | Newer Pymacs should not need this. 18 | 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![MELPA](https://melpa.org/packages/python-mode-badge.svg)](https://melpa.org/#/python-mode) 2 | 3 | Send source code to all known Python shells without need to reconfigure default. 4 | Provide fine grained navigation of all known Python constructs. 5 | 6 | * Initialize 7 | 8 | Make sure the directory, where python-mode.el resides, is in load-path 9 | For expample put something like that in your init-file: 10 | 11 | (add-to-list 'load-path "PATH/TO/PYTHON-MODE")\ 12 | (require 'python-mode) 13 | 14 | or probably still better: 15 | 16 | (setq py-install-directory "PATH/TO/PYTHON-MODE/")\ 17 | (add-to-list 'load-path py-install-directory)\ 18 | (require 'python-mode) 19 | 20 | * Selecting a Python shell: 21 | 22 | Customize default Python shell as `py-shell-name' 23 | 24 | ‘py-shell-name’ might be an installed default executable as shell 25 | command `type' would display, but also a PATH/TO/EXECUTABLE 26 | 27 | If different flavours of Python are installed, in order to adress 28 | them customize var ‘py-known-shells’ and reload. python-mode will 29 | create the required commands according to contents of this list. 30 | 31 | Depending from your instell the var py-known-shells might show contents like that: 32 | ("ipython" "ipython2.7" "ipython3" "jython" "python" "python2" "python3" "pypy") 33 | 34 | If needed, customize respective arguments 35 | py-SHELL-command-args, i.e. 36 | 37 | py-python-command-args 38 | py-python3-command-args 39 | py-ipython-command-args 40 | 41 | etc. 42 | 43 | Commands related to a specific shell start with 44 | 45 | M-x SHELL RET 46 | 47 | This calls py-shell with its default arguments 48 | With C-u, shell will get an unique name. 49 | 50 | According to contents of ‘py-known-shells’ commands might be 51 | available like this: 52 | 53 | M-x py-shell RET ==> "*Python*" 54 | M-x python RET ==> "*Python*" 55 | M-x ipython RET ==> "*IPython*" 56 | M-x python3 RET ==> "*Python3*" 57 | 58 | etc. 59 | 60 | A shebang precedes default py-shell-name. 61 | In case you will run code by default-shell, ignoring shebang, set 62 | `py-force-py-shell-name-p' to. This might be done also via menu 63 | Python/.../Switches 64 | 65 | Run a local shell by evaluating 66 | 67 | (defun MY-LOCAL-SHELL () 68 | (interactive) 69 | (py-shell nil DEDICATED PATH-TO-LOCAL-SHELL)) 70 | 71 | * Executing code 72 | 73 | - Python code might be processed by an interactive Python shell (DEFAULT) 74 | 75 | - non-interactive Python (`py-fast-process-p') 76 | 77 | The latter, while design for large output, seems more reliable - see also PROBLEMS.org. 78 | 79 | Both processes might run in 80 | - session, i.e. start from possible previous state (DEFAULT) 81 | - dedicated, (`py-dedicated-process-p') run in separate process 82 | 83 | There is also ‘python-mode-v5-behavior’ 84 | 85 | * Indentation 86 | 87 | See customizable variable ‘py-indent-offset’ for default indent 88 | 89 | Rules according to ‘py-indent-list-style’ 90 | 91 | - ‘line-up-with-first-element’ (default) 92 | 93 | Which would look like\ 94 | packed_entry = (long, sequence, of_items, 95 | that, needs, to_be, wrapped) 96 | 97 | However, if a continuation list or tuple starts at the beginning line, 98 | select ‘one-level-from-opener’ though 99 | 100 | (long, sequence, of_items, 101 | that, needs, to_be, wrapped) = input_list 102 | 103 | - ‘one-level-to-beginning-of-statement’ 104 | - ‘one-level-from-opener’ 105 | 106 | As for the closing line:\ 107 | ‘ py-closing-list-dedents-bos’ 108 | 109 | my_list = [\ 110 | 1, 2, 3,\ 111 | 4, 5, 6 112 | ] 113 | 114 | otherwise 115 | 116 | my_list = [\ 117 | 1, 2, 3,\ 118 | 4, 5, 6\ 119 | ] 120 | 121 | With nested dicts: 122 | 123 | closing, py-closing-list-dedents-bos t\ 124 | asdf = {\ 125 | 'a':{\ 126 | 'b':3,\ 127 | 'c':4\ 128 | }\ 129 | } 130 | 131 | otherwise 132 | 133 | hanging, py-closing-list-dedents-bos nil\ 134 | asdf = {\ 135 | 'a':{\ 136 | 'b':3,\ 137 | 'c':4\ 138 | }\ 139 | } 140 | 141 | With opener at EOL, next line indents acording to ‘py-indent-offset’\ 142 | def long_function_name(\ 143 | var_one, var_two, var_three,\ 144 | var_four):\ 145 | print(var_one) 146 | 147 | ‘one-level-from-first-element’ adds ‘py-indent-offset’ from first element\ 148 | def foo():\ 149 | if (foo &&\ 150 | baz):\ 151 | bar()" 152 | 153 | * Checks 154 | Access is provided to a couple of known checkers like Flake8, pep8, pylint 155 | Need to be installed for example calling "pip install pep8" from a shell command-line 156 | Get flycheck from https://www.flycheck.org 157 | 158 | * Displaying Output 159 | 160 | `py-execute-...'-commands arrive in buffer created by 161 | `py-shell'. It's name is composed WRT to Python 162 | version used, it's path etc. 163 | 164 | Result of commands ending "-fast" 165 | arrives in `py-fast-output-buffer' 166 | 167 | * Window management 168 | Variables in question: 169 | 170 | ** py-keep-windows-configuration 171 | 172 | Default is nil. 173 | When non-nil, it takes precedence over 174 | `py-split-window-on-execute' and `py-switch-buffers-on-execute-p' 175 | settings 176 | 177 | Useful, if a pre-designed set of python-shells/buffers should be 178 | maintained 179 | 180 | ** py-split-window-on-execute 181 | 182 | When non-nil split windows according to value set. 183 | 184 | Default is 'just-two: when code is send to interpreter, split screen 185 | into source-code buffer and current py-shell result. Other buffers 186 | will be hidden that way. 187 | 188 | When set to `t', python-mode tries to reuse existing windows and 189 | will split only if needed. 190 | 191 | With 'always, results will displayed in a new window. 192 | 193 | ** py-switch-buffers-on-execute-p 194 | 195 | Put focus into the output buffer: this will display buffer in any 196 | case 197 | 198 | * Completion 199 | At the end of a word TAB by default calls completion. 200 | 201 | Auto-completion should be available via 202 | 203 | (require 'auto-complete-config) 204 | (ac-config-default) 205 | 206 | or for company: 207 | 208 | (autoload 'company-mode "company" nil t) 209 | 210 | There is also a Pymacs based auto-completion mode 211 | see README-PYMACS.org 212 | 213 | Either use Pymacs and `company-mode' with `pycomplete.el' etc. --load 214 | stuff from folder completion-- 215 | 216 | or switch `py-auto-completion-mode-p' - which relies on 217 | `py-shell-complete', i.e. calls the current Python process. 218 | 219 | Extern tools like jedi-server/mode should work too. 220 | 221 | 222 | * Moving 223 | 224 | Beside common moves like `defun', `statement', block 225 | called via py-end-of-..., py-beginning-... 226 | specific Python-mode edits are delivered: 227 | 228 | `py-expression' and `py-partial-expression'. 229 | 230 | Statement below is considered composed of two `py-expression' 231 | 232 | a = ['spam', 'eggs', 100, 1234] 233 | || |_________________________| 234 | 235 | Assigment operator and all inside comments is ignored. 236 | 237 | `py-partial-expression' would match six sections 238 | 239 | a = ['spam', 'eggs', 100, 1234] 240 | || |_____| |_____| |__| |___| 241 | |_____________________________| 242 | 243 | When traversing code, `py-partial-expression' climbs down and up 244 | all levels encountered, i.e. at opening `[' `py-expression' would return ['spam', 'eggs', 100, 1234], while one char behind at `'' 245 | it yields `'spam',' 246 | 247 | - py-sexp-function, 248 | When set, it's value is called instead of `forward-sexp', `backward-sexp 249 | Choices are py-partial-expression, py-expression, default nil 250 | 251 | 252 | * Filling 253 | Customize boolean `py-set-fill-column-p' 254 | 255 | If `t', enables use Python specific `fill-column' according to 256 | 257 | `py-docstring-fill-column', default is 72 258 | 259 | and `py-comment-fill-column, default is 79 260 | 261 | Comment- and docstring settings might be disabled by 262 | any non-integer value, which means: do not use a 263 | different value of `fill-column' than emacs-wide 264 | 265 | * Prefix conventions 266 | 267 | Most python-mode.el commands start with prefix `py-' 268 | 269 | `M-x py- TAB' 270 | displays a list of them in completion-buffer. 271 | See also commands list delivered in directory doc. 272 | 273 | List virtualenv related `M-x virtualenv- TAB' 274 | resp. Pymacs commands `M-x pymacs-' 275 | 276 | * Python and IPython 277 | 278 | Start IPython shell after loading python-mode via M-x 279 | ipython, not from plain shell. 280 | 281 | Executing code through IPython should work as with 282 | regular Python, also getting completions from. However, 283 | with IPython, it feels a demi-second slower. 284 | 285 | * Session mode 286 | Py-shell runs in session mode by default. Not to run in session 287 | mode, customize ‘py-session-p’ to nil. Or for current session call 288 | ‘py-toggle-session-p’. 289 | 290 | * Troubleshooting 291 | 292 | Start with Emacs -Q from the directory where python-mode.el lives. 293 | Open python-mode.el and evaluate it. 294 | 295 | Open a file with ending ".py". 296 | 297 | M-x python RET 298 | 299 | a regular Python-shell should appear 300 | 301 | M-x IPython RET 302 | 303 | an IPython-shell should be opened 304 | 305 | ** pdb doesn't work at Windows 306 | Richard Stanton commented: 307 | 308 | Running M-x pdb doesn't work on my Windows machine, primarily because 309 | Windows (at least using the default shell) doesn't automatically know 310 | what to do when you give it a .py command at the command line. 311 | 312 | For example, here's the suggested command when I run pdb on a file 313 | c:\projects/run.py: 314 | 315 | c:/python27/Lib/pdb.py run.py 316 | 317 | If I accept this, I get an error "Spawning child process: Invalid 318 | argument" 319 | 320 | A work-around to get it to work is to replace the suggested command 321 | with 322 | 323 | c:\python27\python -i c:/python27/Lib/pdb.py c:/projects/run.py 324 | 325 | (note that I not only have to add the python command, but also fully 326 | qualify the script file, since otherwise it complains it can't find 327 | the file). 328 | 329 | * Testing 330 | 331 | File ‘run-tests.sh’ runs tests in batch-mode locally and remote. 332 | If the shell-variable WERKSTATT is set to 0, local run is assumed. 333 | The script does 334 | WERKSTATT=${WERKSTATT:=1} 335 | i.e. if WERKSTATT is not set, it will be 1, which means "remote" here. 336 | -------------------------------------------------------------------------------- /README_AUTOPAIR.org: -------------------------------------------------------------------------------- 1 | # -*- mode: org -*- 2 | 3 | *Autopair* is an extension to the Emacs text editor that automatically 4 | pairs braces and quotes: 5 | 6 | - Opening braces/quotes are autopaired; 7 | - Closing braces/quotes are autoskipped; 8 | - Backspacing an opening brace/quote autodeletes its pair. 9 | - Newline between newly-opened brace pairs open an extra indented line. 10 | 11 | Autopair works well across all Emacs major-modes, deduces from the 12 | language's syntax table which characters to pair, skip or delete. It 13 | should work even with extensions that redefine such keys. 14 | 15 | * Installation and basic use: 16 | 17 | To try it out, download the [[http://autopair.googlecode.com/git/autopair.el][latest version]] and add to your =.emacs=: 18 | 19 | #+BEGIN_EXAMPLE 20 | (add-to-list 'load-path "/path/to/autopair") ;; comment if autopair.el is in standard load path 21 | (require 'autopair) 22 | (autopair-global-mode) ;; enable autopair in all buffers 23 | #+END_EXAMPLE 24 | 25 | * Rationale 26 | 27 | I developed autopair to work just like [[http://macromates.com/][TextMate]] or better, be 28 | minimally intrusive to my existing hacks and need very little 29 | customization. You might prefer it to the following: 30 | 31 | - http://www.emacswiki.org/emacs/ParEdit 32 | - http://code.google.com/p/emacs-textmate/ 33 | - http://github.com/ramblex/emacs-textmate 34 | - http://svn.ruby-lang.org/repos/ruby/trunk/misc/ruby-electric.el (most of it) 35 | - the options listed in http://www.emacswiki.org/emacs/AutoPairs 36 | 37 | It also works with [[http://github.com/capitaomorte/yasnippet/][YASnippet]], another package I maintain. 38 | 39 | * Neat tricks 40 | 41 | - =autopair-autowrap= tells autopair to automatically wrap the 42 | selection region with the delimiters you're trying to insert. 43 | 44 | - =autopair-blink= makes the cursor quickly blink over matching 45 | braces and quotes just inserted or skipped over. If you find this 46 | behaviour annoying, set this to nil. 47 | 48 | - =autopair-skip-whitespace=, when set to non-nil, tells autopair to 49 | skip over whitespace when attempting to skip over a closing 50 | brace. If you set this to 'chomp, the whitespace is not only 51 | jumped over but also deleted. 52 | 53 | Autopair's idea is to always do-what-you-mean, but since some people 54 | are never satisfied, have a look at the following: 55 | 56 | * Optional tricks 57 | 58 | You shouldn't need this, but to enable autopair in just some types 59 | of buffers, comment out the `autopair-global-mode` and turn on 60 | `autopair-mode` in some major-mode hook, like: 61 | 62 | #+BEGIN_EXAMPLE 63 | ;; use autopair just in c buffers 64 | 65 | (add-hook 'c-mode-common-hook 66 | #'(lambda () (autopair-mode))) 67 | #+END_EXAMPLE 68 | 69 | Alternatively, do use =autopair-global-mode= and create _exceptions_ 70 | using the major mode hooks (watch out for the change in behaviour 71 | emacs 24). 72 | 73 | #+BEGIN_EXAMPLE 74 | ;; use autopair everywhere but c buffers 75 | 76 | (add-hook 'c-mode-common-hook 77 | #'(lambda () 78 | (setq autopair-dont-activate t) ;; for emacsen < 24 79 | (autopair-mode -1)) ;; for emacsen >= 24 80 | ) 81 | #+END_EXAMPLE 82 | 83 | * More tricks 84 | 85 | =autopair-dont-pair= lets you define special cases of characters you 86 | don't want paired. Its default value skips pairing single-quote 87 | characters when inside a comment literal, even if the language 88 | syntax tables does pair these characters. 89 | 90 | As a further example, to also prevent the ={= (opening brace) 91 | character from being autopaired in C++ comments use this in your 92 | .emacs. 93 | 94 | #+BEGIN_EXAMPLE 95 | (add-hook 'c++-mode-hook 96 | #'(lambda () 97 | (push ? 98 | (getf autopair-dont-pair :comment)))) 99 | #+END_EXAMPLE 100 | 101 | 102 | =autopair-handle-action-fns= lets you write some emacs-lisp that 103 | overrides/extends the actions taken by autopair after it decides 104 | something must be paired, skipped or deleted. To work with triple 105 | quoting in python mode, you can use this for example: 106 | 107 | #+BEGIN_EXAMPLE 108 | (add-hook 'python-mode-hook 109 | #'(lambda () 110 | (setq autopair-handle-action-fns 111 | (list #'autopair-default-handle-action 112 | #'autopair-python-triple-quote-action)))) 113 | #+END_EXAMPLE 114 | 115 | where =autopair-python-triple-quote-action= is an example of a 116 | user-written function (which is bundled in =autopair.el=). 117 | 118 | See [[http://code.google.com/p/autopair/issues/detail?id=13][this issue]] for an example of clever use of this variable (thanks 119 | [[http://code.google.com/u/alexduller/][alexduller]]). 120 | 121 | =autopair-extra-pairs= lets you define extra pairing and skipping 122 | behaviour for pairs not programmed into the syntax table. Watch out, 123 | this is work-in-progress, a little unstable and does not help 124 | balancing at all. To have =<= and =>= pair in =c++-mode= buffers, 125 | but only in code, use: 126 | 127 | #+BEGIN_EXAMPLE 128 | (add-hook 'c++-mode-hook 129 | #'(lambda () 130 | (push '(?< . ?>) 131 | (getf autopair-extra-pairs :code)))) 132 | #+END_EXAMPLE 133 | 134 | if you program in emacs-lisp you might also like the following to 135 | pair backtick (=`=) and quote (='=). 136 | 137 | #+BEGIN_EXAMPLE 138 | (add-hook 'emacs-lisp-mode-hook 139 | #'(lambda () 140 | (push '(?` . ?') 141 | (getf autopair-extra-pairs :comment)) 142 | (push '(?` . ?') 143 | (getf autopair-extra-pairs :string)))) 144 | #+END_EXAMPLE 145 | 146 | * Workarounds 147 | 148 | Once you set =autopair-global-mode= everything mostly _just works_ 149 | but a few extensions use tricks that interfere with autopair's own 150 | tricks, disabling autopair or some of the extension's 151 | functionality. Using the customization techniques described above, 152 | there are plenty of very good workarounds for =slime-mode=, 153 | =latex-mode=, =term-mode= and even =viper-mode=. 154 | 155 | See [[http://code.google.com/p/autopair/issues/detail?id=20&can=1&q=status:Workaround][the workaround list]]. 156 | 157 | * How it works 158 | 159 | The extension works by rebinding the braces and quotes keys, but can 160 | still be minimally intrusive, since the original binding is always 161 | called as if autopair did not exist. 162 | 163 | The decision of which keys to actually rebind is taken at minor-mode 164 | activation time, based on the current major mode's syntax tables. To 165 | achieve this kind of behaviour, an Emacs variable 166 | =emulation-mode-map-alists= was used. 167 | 168 | If you set =autopair-pair-criteria= and =autopair-skip-criteria= to the symbol 169 | =help-balance= (which, by the way, is the default), braces are not 170 | autopaired/autoskipped in all situations; the decision to autopair 171 | or autoskip a brace is taken according to the following table: 172 | 173 | #+BEGIN_EXAMPLE 174 | +---------+------------+-----------+-------------------+ 175 | | 1234567 | autopair? | autoskip? | notes | 176 | +---------+------------+-----------+-------------------+ 177 | | (()) | yyyyyyy | ---yy-- | balanced | 178 | +---------+------------+-----------+-------------------+ 179 | | (())) | ------y | ---yyy- | too many closings | 180 | +---------+------------+-----------+-------------------+ 181 | | ((()) | yyyyyyy | ------- | too many openings | 182 | +---------+------------+-----------+-------------------+ 183 | #+END_EXAMPLE 184 | 185 | The table is read like this: in a buffer with 7 characters laid out 186 | like the first column, an "y" marks points where an opening brace is 187 | autopaired and in which places would a closing brace be 188 | autoskipped. Quote pairing tries to support similar "intelligence". 189 | -------------------------------------------------------------------------------- /README_DEVEL.org: -------------------------------------------------------------------------------- 1 | * General 2 | 3 | python-mode.el is composed from components-python-mode directory 4 | using `components2pythonmode' shell-script 5 | 6 | Get its source-files doing 7 | 8 | git clone https://gitlab.com/python-mode-devs/components-python-mode 9 | 10 | while master is at 11 | https://gitlab.com/python-mode-devs/python-mode.git 12 | 13 | An effective way users may contribute is telling 14 | us how Python-mode is used and which command is missing 15 | still. 16 | 17 | Several files in developing branch components-python-mode are generated 18 | by functions in devel/python-mode-utils.el 19 | It's marked at the head of these files 20 | 21 | 22 | * Output buffers 23 | There will be 24 | - one set internally to process, where the real work is done: 25 | py-buffer-name 26 | - a generic one, results may arrive finally, visible for user: 27 | py-output-buffer 28 | Commands might set their output-buffers, "*Python Completions*" for example. 29 | 30 | * Organizing source code to edit Python 31 | Commands are grouped by action WRT Python forms 32 | 33 | ** backward FORM / forward of FORM 34 | *** forward FORM left corner 35 | ** mark FORM 36 | ** copy FORM 37 | ** kill FORM 38 | ** delete FORM 39 | ** up Form 40 | ** down form 41 | 42 | Basically use ‘backward’ and ‘forward’ instead of beginning/end of 43 | ‘py-beginning-of-statement’ aliased ‘py-backward-statement’ etc. 44 | beginning/end of forms are reserved for booleans. 45 | A separating convention, intended to make sripting easier. 46 | 47 | * Organizing source code to run Python 48 | A ‘py-python-’ form may have a ‘py-ipython’ sibling 49 | 50 | * Bugs, feature requests 51 | Please use bug-tracker at 52 | https://gitlab.com/python-mode-devs/python-mode/issues 53 | 54 | 55 | * Testing 56 | 57 | Tests in batch-mode are run via run-travis-ci.sh 58 | 59 | However, there is no need to use batch-mode for a single 60 | test. Batch-mode has some quirks and bugs. Tests in 61 | test/py-ert-interactive-tests.el are expected to succeed when called 62 | interactively, not in batch-mode. 63 | 64 | Start tests from emacs -Q 65 | All needed beside python-mode.el is 66 | test/setup-ert-tests.el 67 | and the file, which contains the test. 68 | Run the test M-x ert TESTNAME RET 69 | 70 | Instruments it for the debugger with M-x edebug-defun RET after or 71 | inside the test . Use to step. 72 | 73 | * Completion directory 74 | contains some Pymacs related stuff 75 | There was a conflict when Pymacs was installed from source, 76 | therefor it's not loaded by default 77 | 78 | * History 79 | Remarks like lp:837065 refer to a former repository at https://launchpad.net/, 80 | https://bugs.launchpad.net/bugs/837065 81 | 82 | -------------------------------------------------------------------------------- /ToDo.org: -------------------------------------------------------------------------------- 1 | * (get-char-property pos 'syntax-table) 2 | 3 | text-properties-at 4 | 5 | remove-text-properties 6 | alter-text-property 7 | get-text-property 8 | 9 | (set (make-local-variable 'comint-output-filter-functions) 10 | '(ansi-color-process-output 11 | python-shell-comint-watch-for-first-prompt-output-filter 12 | python-pdbtrack-comint-output-filter-function 13 | python-comint-postoutput-scroll-to-bottom)) 14 | 15 | * autopair mode 16 | * py-fill-paren test 17 | * py--beginning-of- position auch von start 18 | * use comint-bol 19 | * which-func-mode in shell-buffer 20 | * py-ert-find-definition-test-1 21 | * py-indent-region-left 22 | * delimiters 23 | ( ) [ ] { } 24 | , : . ; @ = 25 | += -= *= /= //= %= 26 | &= |= ^= >>= <<= **= 27 | * py-report-comint-variable-setting, variables-prepare 28 | * New keys setting in `py-python-shell-mode-map' 29 | 30 | [(control c)(control l)] 'comint-dynamic-list-input-ring) 31 | [(control c)(control r)] 'comint-previous-prompt) 32 | 33 | Behaviour similar to Emacs comint/Python environment. 34 | Taken from shift-keys, which are still there: 35 | 36 | [(control c)(<)] 'py-shift-left) 37 | [(control c)(>)] 'py-shift-right) 38 | 39 | * py--escape-open-paren-col1 unbenutzt 40 | * -V terminates the process 41 | * py-load-pymacs-p in python-mode.el 42 | * pdb 43 | in gud.el 44 | (run-hooks 'pdb-mode-hook)) 45 | * pdb breakpoints 46 | http://stackoverflow.com/questions/6980749/simpler-way-to-put-pdb-breakpoints-in-python-code 47 | python -m pdb your_script.py 48 | 49 | It will break on the 1st line, then you'll be able to add a breakpoint wherever you want in your code using the break command, its syntax is: 50 | 51 | b(reak) [[filename:]lineno | function[, condition]] 52 | 53 | * idlw-shell.el 54 | ;; Python-mode, bundled with many Emacs installs, quite cavalierly 55 | ;; adds this function to the global default hook. It interferes 56 | ;; with overlay-arrows. 57 | (remove-hook 'comint-output-filter-functions 'py-pdbtrack-track-stack-file) 58 | 59 | 60 | * def (a, 61 | 62 | ): no indent 63 | * am Ende von else: no completion 64 | * py-help-at-point fails at `readlines' 65 | with open('GivenFixtures.txt', 'r') as gv: 66 | # datei = gv.read() 67 | text = gv.readlines() 68 | 69 | * let's dedicated shells buffer-name start with process-serial-no 70 | * py-minor-expression/token, py-expression/value 71 | * py-describe-symbol-fails-on-modules-lp:919719-test 72 | * print_function IPython completion von prin 73 | * py-fill-string-django-test 74 | * fill-paragraph-in-docstring-lp-1161232-test 75 | * py-execute-buffer-python2-switch-test 76 | * ipython-complete-lp-1102226-test 77 | * Bogus-whitespace-left-in-docstring-after-wrapping-lp-1178455-test 78 | * cls-pseudo-keyword-lp:328849-test 79 | * py-execute-region-error-test 80 | * more-docstring-filling-woes-lp-1102296-nil-test 81 | * inconvenient-window-splitting-behavior-ipython-lp-1018996-test 82 | * py-electric-comment-add-space-lp:828398-test 83 | * py-help-at-point mit fast 84 | * py--fast-send-string store return 85 | * normalize py-execute-buffer-python-switch etc. 86 | * augmented-assigment-test 87 | * switch-windows-on-execute-p-test - warum Fehler? 88 | * mention py-buffer-name holds current exec-buffer value 89 | * Python 3.3.0 (default, Oct 01 2012, 09:13:30) [GCC] on linux 90 | Type "help", "copyright", "credits" or "license" for more information. 91 | >>> ... >>> >>> ... ... ... ... ... ... ... ... ... >>> >>> ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... >>> Traceback (most recent call last): 92 | File "", line 1, in 93 | FileNotFoundError: [Errno 2] No such file or directory: '/tmp/python3-19061qd.py' 94 | * py-indent-tabs-mode design 95 | * make-temp-name zu md5, ein.py 96 | * `py-always-split-windows-p' renamed py-split-if-not-visible-p 97 | * py-buffer-name.txt 98 | * py-mode-output-map 99 | * python-mode-utils.el aktualisieren - fast-process Output buffer 100 | * in py-shell 101 | (args 102 | (cond (py-fast-process-p nil) 103 | * py-auto-completion-mode-p 104 | * forward-sexp-test 105 | * with-output-to-temp-buffer, 106 | * py-orig-buffer-or-file 107 | * py-remove-cwd-from-path 108 | * sys.version_info 109 | * py-ipython-complete-lp:927136-test 110 | * TODO py-max-help-buffer-p 111 | * TODO py-beginning-of-elif 112 | * TODO py-execute-python-mode-v5 returns position, now result 113 | use orig 114 | * TODO implement respective to shell-dumb-shell-regexp 115 | * TODO make `py-complete-completion-at-point' command 116 | * TODO run shebang in ansi-term, provide resp. commands 117 | * TODO dispay index in speedbar 118 | * TODO python3 smart detect for py-execute- 119 | * TODO py-electric-colon: insert colon 120 | * TODO py-decomment 121 | * TODO py-output-buffer 122 | * TODO Emacs Python Tested Environment 123 | Many Emacs users keep there own environemt composed 124 | of the extensions around. Therefor offering everthing 125 | possibly needed right from the spot is not that 126 | promising as elsewhere - moreover, there is a 127 | probability, stuff delivered might disturb existing 128 | workflow. OTOH many users will spend more time than 129 | necessary collecting all this stuff from a plenty of 130 | sources, which often need some tweaks. A Solution 131 | might be indicating tested install examples. 132 | 133 | * TODO py-down-block-same-level 134 | * TODO py-execute-statement-version 135 | generic command, execute according to version customized in `py-execute-version' 136 | * TODO describe-mode remove unused key labels 137 | * TODO KEYWORDS = frozenset(keyword.kwlist + ['print']) - SINGLETONS 138 | grasp keyword.kwlist as py-minor-expression 139 | * Text is read-only - Usache war prompt in comint, Konflikt mit setup 140 | * py-split-window-on-execute-lp-1361531-bpython-test 141 | * yanking back funkt nicht 142 | -------------------------------------------------------------------------------- /byte-compile-directory.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # -- byte-compile Emacs Lisp files delivered with python-mode.el 3 | 4 | # Author: 2015-2021 https://gitlab.com/groups/python-mode-devs" 5 | 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | # Commentary: Edit the vars pointing to the directories/files 18 | # holding your python-mode for test 19 | # assumes python-mode files in or below current directory 20 | 21 | # Code: 22 | 23 | 24 | # the path 25 | PDIR=`pwd` 26 | 27 | # python-mode file to load 28 | if [ -s "python-components-mode.el" ]; 29 | then 30 | PYTHONMODE='python-components-mode.el' 31 | else 32 | PYTHONMODE='python-mode.el' 33 | fi 34 | 35 | EMACS=emacs 36 | PYMACSDIR=Pymacs 37 | 38 | $EMACS -Q --batch --eval "(message (emacs-version))" --eval "(when (featurep 'python-mode)(unload-feature 'python-mode t))" --eval "(add-to-list 'load-path \"$PDIR/\")" --eval "(add-to-list 'load-path \"$PYMACSDIR/\")" -load "$PDIR/$PYTHONMODE" --eval '(byte-recompile-directory default-directory 1 t)' 39 | 40 | 41 | -------------------------------------------------------------------------------- /completion/auto-complete-pycomplete.el: -------------------------------------------------------------------------------- 1 | ;;; auto-complete-pycomplete.el --- an auto-complete source for pycomplete.el 2 | 3 | ;; Copyright (C) 2012 Urs Fleisch 4 | 5 | ;; Author: Urs Fleisch 6 | ;; Keywords: languages, processes, python, oop 7 | 8 | ;; This program is free software; you can redistribute it and/or modify 9 | ;; it under the terms of the GNU General Public License as published by 10 | ;; the Free Software Foundation, either version 3 of the License, or 11 | ;; (at your option) any later version. 12 | 13 | ;; This program is distributed in the hope that it will be useful, 14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ;; GNU General Public License for more details. 17 | 18 | ;; You should have received a copy of the GNU General Public License 19 | ;; along with this program. If not, see . 20 | 21 | ;;; Commentary: 22 | 23 | ;; The ac-source can be enabled solely using 24 | ;; (setq ac-sources '(ac-source-pycomplete)) 25 | ;; or before the other sources using 26 | ;; (add-to-list 'ac-sources 'ac-source-pycomplete). 27 | 28 | ;;; Code: 29 | 30 | (require 'pycomplete) 31 | (require 'auto-complete) 32 | 33 | (defun ac-pycomplete-document (symbol) 34 | (let* ((full-prefix (py-complete-enhanced-symbol-before-point)) 35 | (full-symbol (concat (substring full-prefix 0 (- (length ac-prefix))) symbol))) 36 | (py-complete-docstring-for-symbol full-symbol))) 37 | 38 | (defun ac-pycomplete-candidates () 39 | (py-complete-completions-for-symbol 40 | (py-complete-enhanced-symbol-before-point))) 41 | 42 | (ac-define-source pycomplete 43 | '((candidates . ac-pycomplete-candidates) 44 | (document . ac-pycomplete-document))) 45 | 46 | (provide 'auto-complete-pycomplete) 47 | ;;; auto-complete-pycomplete.el ends here 48 | -------------------------------------------------------------------------------- /completion/company-pycomplete.el: -------------------------------------------------------------------------------- 1 | ;;; company-pycomplete.el --- a company-mode completion back-end for pycomplete.el 2 | 3 | ;; Copyright (C) 2012 Urs Fleisch 4 | 5 | ;; Author: Urs Fleisch 6 | ;; Keywords: languages, processes, python, oop 7 | 8 | ;; This program is free software; you can redistribute it and/or modify 9 | ;; it under the terms of the GNU General Public License as published by 10 | ;; the Free Software Foundation, either version 3 of the License, or 11 | ;; (at your option) any later version. 12 | 13 | ;; This program is distributed in the hope that it will be useful, 14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ;; GNU General Public License for more details. 17 | 18 | ;; You should have received a copy of the GNU General Public License 19 | ;; along with this program. If not, see . 20 | 21 | ;;; Commentary: 22 | 23 | ;; The backend can be enabled using 24 | ;; (setq company-backends '((company-pycomplete))) 25 | 26 | ;;; Code: 27 | 28 | (require 'pycomplete) 29 | (require 'company) 30 | 31 | (defun company-pycomplete--grab-symbol () 32 | ;; stolen from company-pysmell--grab-symbol 33 | (let ((symbol (company-grab-symbol))) 34 | (when symbol 35 | (cons symbol 36 | (save-excursion 37 | (let ((pos (point))) 38 | (goto-char (- (point) (length symbol))) 39 | (while (eq (char-before) ?.) 40 | (goto-char (1- (point))) 41 | (skip-syntax-backward "w_")) 42 | (- pos (point)))))))) 43 | 44 | 45 | (defun company-pycomplete-doc-buffer (candidate) 46 | "Return buffer with docstring of CANDIDATE if it is available." 47 | (let* ((full-prefix (py-complete-enhanced-symbol-before-point)) 48 | (full-symbol (concat full-prefix (company-strip-prefix candidate))) 49 | (doc (py-complete-docstring-for-symbol full-symbol))) 50 | (when (and (stringp doc) (> (length doc) 0)) 51 | (with-current-buffer (company-doc-buffer) 52 | (insert doc) 53 | (current-buffer))))) 54 | 55 | (defun company-pycomplete-location (candidate) 56 | "Return location of CANDIDATE in cons form (FILE . LINE) if it is available." 57 | (let* ((full-prefix (py-complete-enhanced-symbol-before-point)) 58 | (full-symbol (concat full-prefix (company-strip-prefix candidate)))) 59 | (py-complete-location full-symbol))) 60 | 61 | (defun company-pycomplete (command &optional arg &rest ignored) 62 | "A `company-mode' completion back-end for pycomplete." 63 | (interactive (list 'interactive)) 64 | (case command 65 | ('interactive (company-begin-backend 'company-pycomplete)) 66 | ('prefix (and (derived-mode-p 'python-mode) 67 | (not (company-in-string-or-comment)) 68 | (company-pycomplete--grab-symbol))) 69 | ('candidates (py-complete-completions)) 70 | ('doc-buffer (company-pycomplete-doc-buffer arg)) 71 | ('location (company-pycomplete-location arg)))) 72 | 73 | (provide 'company-pycomplete) 74 | ;;; company-pycomplete.el ends here 75 | -------------------------------------------------------------------------------- /completion/test_pycomplete.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os, sys 4 | import linecache 5 | import tempfile 6 | from pycomplete import * 7 | 8 | def test_signature(): 9 | assert pysignature('') == '' 10 | assert pysignature('os.path.join') == 'join: (a, *p)' 11 | assert pysignature('json.dump').startswith( 12 | 'dump: (obj, fp, skipkeys=False, ensure_ascii=True, ') 13 | assert pysignature('json.JSONEncoder.encode') == 'encode: (self, o)' 14 | assert pysignature('json.JSONEncoder').startswith( 15 | '__init__: (self, skipkeys=False, ensure_ascii=True, ') 16 | assert pysignature('xml.dom.minidom.parse') == \ 17 | 'parse: (file, parser=None, bufsize=None)' 18 | assert pysignature('csv.reader') == \ 19 | 'csv_reader = reader(iterable [, dialect=\'excel\']' 20 | assert pysignature('super') in ( 21 | 'super(type) -> unbound super object', 22 | 'super() -> same as super(__class__, )', 23 | 'super(type, obj) -> bound super object; requires isinstance(obj, type)') 24 | 25 | def test_help(): 26 | assert pyhelp('os.path.join').startswith('Help on function join') 27 | assert pyhelp('logging', imports=('import logging',)).startswith( 28 | 'Help on package logging:\n\nNAME\n logging\n') 29 | assert pyhelp('csv', imports=('import csv',)).startswith( 30 | 'Help on module csv:\n\nNAME\n csv - CSV parsing and writing.\n') 31 | assert pyhelp('import').startswith( 32 | ('The ``import`` statement\n************************\n', 33 | 'The "import" statement\n**********************\n')) 34 | assert pyhelp('pydoc.help').startswith( 35 | 'Help on class Helper in module pydoc') 36 | assert pyhelp('') == '' 37 | 38 | def test_complete(): 39 | assert pycomplete('') == '' 40 | assert pycomplete('sys.getd') == ['getdefaultencoding', 'getdlopenflags'] 41 | assert pycomplete('set') == ['set', 'setattr'] 42 | assert pycomplete('settr') is None 43 | assert pycomplete('settr', imports=['from sys import settrace']) == [ 44 | 'ace'] 45 | # Test with cached imports 46 | assert pycomplete('settr') == ['ace'] 47 | # Not cached for other files 48 | fpath = os.path.abspath(__file__) 49 | assert pycomplete('settr', fname=fpath) is None 50 | assert pycomplete('settr', fname=fpath, 51 | imports=['from sys import settrace']) == ['ace'] 52 | assert pycomplete('foo.') is None 53 | assert pycomplete('JSONEnc') is None 54 | assert pycomplete('JSONEnc', imports=['from json import *']) == ['oder'] 55 | assert pycomplete('A') == [ 56 | 'ArithmeticError', 'AssertionError', 'AttributeError'] 57 | 58 | def test_completions(): 59 | all_completions = pycompletions('') 60 | assert all_completions[0] == 'ArithmeticError' 61 | assert all_completions[-1] == 'zip' 62 | assert pycompletions('os.path.jo') == ['join'] 63 | assert pycompletions('settr', imports=['']) == [] 64 | assert pycompletions('settr', 65 | imports=['from sys import settrace']) == ['settrace'] 66 | # Check if imports are still cached. 67 | assert pycompletions('settr', imports=None) == ['settrace'] 68 | # Change list of imports, so that cache is invalidated. 69 | assert pycompletions('settr', imports=['']) == [] 70 | 71 | def test_location(): 72 | fn, line = pylocation('os.path.join') 73 | assert os.path.exists(fn) 74 | assert linecache.getline(fn, line).startswith('def join') 75 | assert pylocation('io.StringIO') is None 76 | fn, line = pylocation('json') 77 | assert os.path.exists(fn) 78 | assert pylocation('for') is None 79 | 80 | def test_docstring(): 81 | assert pydocstring('os.path.abspath') == 'Return an absolute path.' 82 | assert pydocstring('os.path').startswith( 83 | 'Common operations on Posix pathnames.\n') 84 | assert pydocstring('json.JSONEncoder.encode').startswith( 85 | 'Return a JSON string representation of a Python data structure.\n') 86 | assert pydocstring('yield') == '' 87 | assert pydocstring('numbers.Real.real') == \ 88 | 'Real numbers are their real component.' 89 | assert pydocstring('notexisting') == '' 90 | assert pydocstring('re.IGNORECASE') == '' 91 | 92 | def test_parse_source(): 93 | tmp_file = tempfile.NamedTemporaryFile(suffix='.py', mode='w') 94 | name = tmp_file.name 95 | with tmp_file.file as fh: 96 | assert pyparse('not_existing', only_reload=True) == None 97 | assert pyparse('not_existing') == \ 98 | "[Errno 2] No such file or directory: 'not_existing'" 99 | assert pyparse(name) is None 100 | # Nothing imported so far 101 | assert pycompletions('dat' , name) == [] 102 | src = """ 103 | "Doc for module." 104 | from __future__ import print_function 105 | import sys, os, io, re 106 | from datetime import date, \ 107 | time 108 | import argparse 109 | if os.getenv('LC'): 110 | import linecache 111 | 112 | modvar = 1 113 | mod_re = re.compile(r'^test') 114 | 115 | def testfunc(): 116 | "Doc for testfunc." 117 | import urllib 118 | 119 | def emptyfunc(): 120 | "Function with only docstring." 121 | 122 | class TestClass(date): 123 | "Doc for TestClass." 124 | CONST1 = 7 125 | CONST2 = 'abc' 126 | CONST3 = ['a', ] 127 | 128 | def __init__(self): 129 | self._member1 = 'string member' 130 | self._member2 = None 131 | self.__member3 = [ None, open('not_existing') ] 132 | self.member4 = argparse.ArgumentParser() 133 | self.member4 = None 134 | self.member5 = open('not_existing') 135 | self.member6 = self.member7 = { 'multiple': 'targets' } 136 | self.member8, self.member9 = 'tuple', 'assignment' 137 | self.member10 = [ n for n in range(3) ] 138 | self.member11 = SyntaxError() 139 | self.member12 = testfunc() 140 | def testmeth(self, arg1=modvar): 141 | "Doc for testmeth." 142 | sys.stdout.write('From testmeth %d' % arg1) 143 | if arg1 == 2: 144 | self._member1 = None 145 | @staticmethod 146 | def teststaticmeth(arg1=2): 147 | "Doc for teststaticmeth." 148 | sys.stdout.write('From teststaticmeth %d' % arg1) 149 | @classmethod 150 | def testclassmeth(cls, arg1=3): 151 | "Doc for testclassmeth." 152 | open('not_existing') 153 | @property 154 | def testprop(self): 155 | "Doc for testprop." 156 | return 4 * 8 157 | 158 | if __name__ == '__main__': 159 | testfunc() 160 | """ 161 | num_src_lines = len(src.splitlines()) 162 | fh.write(src) 163 | fh.flush() 164 | assert pyparse(name) == None 165 | # Check if only global imports are visible 166 | assert pycompletions('dat' , name) == ['date'] 167 | assert pycompletions('tim' , name) == ['time'] 168 | assert pycompletions('url' , name) == [] 169 | assert pycompletions('line' , name) == ['linecache'] 170 | assert pycompletions('os' , name) == ['os'] 171 | # Check for definitions in local file 172 | assert pycompletions('test' , name) == ['testfunc'] 173 | assert pycompletions('TestClass.CO' , name) == \ 174 | ['CONST1', 'CONST2', 'CONST3'] 175 | assert pycompletions('TestClass.test' , name) == \ 176 | ['testclassmeth', 'testmeth', 'testprop', 'teststaticmeth'] 177 | # Check for instance members 178 | assert pycompletions('TestClass._mem', name) == \ 179 | ['_member1', '_member2'] 180 | assert pycompletions('TestClass.__mem', name) == ['__member3'] 181 | assert pycompletions('TestClass._member1.start', name) == \ 182 | ['startswith'] 183 | assert pycompletions('TestClass._member2.', name) == [] 184 | assert pycompletions('TestClass.__member3.ext', name) == \ 185 | ['extend'] 186 | if sys.version_info[0] < 3: 187 | assert pycompletions('TestClass.member4.prin', name) == \ 188 | ['print_help', 'print_usage', 'print_version'] 189 | assert pycompletions('TestClass.member5.writel', name) == \ 190 | ['writelines'] 191 | assert pycompletions('TestClass.member6.from', name) == \ 192 | ['fromkeys'] 193 | assert pycompletions('TestClass.member7.from', name) == \ 194 | ['fromkeys'] 195 | assert pycompletions('TestClass.member10.ext', name) == \ 196 | ['extend'] 197 | assert pycompletions('TestClass.member11.ar', name) == \ 198 | ['args'] 199 | assert pycompletions('modvar.num', name) == ['numerator'] 200 | assert pycompletions('mod_re.ma', name) == ['match'] 201 | assert pydocstring('TestClass._member1', name) == '' 202 | assert pydocstring('TestClass._member2', name) == '' 203 | assert pydocstring('TestClass.__member3', name) == '' 204 | # Check for super class 205 | assert pycompletions('TestClass.week' , name) == ['weekday'] 206 | assert pycompletions('TestClass.utc' , name) == [] 207 | # Check signature, documentation and location 208 | assert pysignature('TestClass.testmeth', name) == \ 209 | 'testmeth: (self, arg1=1)' 210 | assert pydocstring('testfunc', name) == \ 211 | 'Doc for testfunc.' 212 | assert pylocation('TestClass.testclassmeth', name) == \ 213 | (name, num_src_lines - 10) 214 | # Verify that loaded symbols are not affected by transient 215 | # syntax error 216 | fh.write('while') 217 | fh.flush() 218 | assert pyparse(name) == \ 219 | 'invalid syntax (%s, line %d)' % (os.path.basename(name), 220 | num_src_lines + 1) 221 | assert pycompletions('dat' , name) == ['date'] 222 | # Replace file contents and check new imports 223 | fh.seek(0) 224 | fh.truncate(0) 225 | fh.write('import urllib\n') 226 | fh.flush() 227 | assert pyparse(name) == None 228 | assert pycompletions('dat' , name) == [] 229 | assert pycompletions('url' , name) == ['urllib'] 230 | 231 | def run_tests(): 232 | test_complete() 233 | test_completions() 234 | test_help() 235 | test_signature() 236 | test_location() 237 | test_docstring() 238 | test_parse_source() 239 | 240 | if __name__ == "__main__": 241 | run_tests() 242 | -------------------------------------------------------------------------------- /devel/README: -------------------------------------------------------------------------------- 1 | This directory stores some tools and snippets meant for 2 | developers only. 3 | 4 | Please don't load resp. use, unless you are conscient 5 | what you are doing. 6 | 7 | -------------------------------------------------------------------------------- /devel/fundocu2infoformats.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # -- extract and convert documentation from Emacs Lisp files 3 | 4 | # Author: Andreas Röhler 5 | 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | # Commentary: 17 | 18 | # tests Emacs python-mode 19 | # 20 | # Code: 21 | 22 | # Edit the vars pointing to the directories/files 23 | # holding your python-mode for test 24 | 25 | # assumes python-mode files in current directory 26 | 27 | # the path 28 | # needs being in `test' directory 29 | PDIR=`pwd` 30 | 31 | 32 | # write PATH-TO-EMACS source code directory here 33 | # EMACS_SOURCE_DIR="$HOME/emacs-20110426" 34 | EMACS_SOURCE_DIR=$HOME/emacs-23.4 35 | 36 | # python-mode file to load 37 | if [ -s "../python-components-mode.el" ]; 38 | then 39 | PYTHONMODE="../python-components-mode.el" 40 | else 41 | PYTHONMODE="../python-mode.el" 42 | fi 43 | 44 | if [ $1 ]; then 45 | EINGABE=$1 46 | fi 47 | 48 | 49 | if [ $EMACS_SOURCE_DIR ]; then 50 | 51 | EMACS="${EMACS_SOURCE_DIR}/src/emacs" 52 | 53 | # else 54 | # EMACS=emacs 55 | # when installed Emacs shall be used, CCCMDS must be set 56 | # CCCMDS="${EMACS_SOURCE_DIR}/lisp/progmodes/cc-cmds.el" 57 | 58 | # ERG=$(echo $LOGNAME | sed 's/^s\(.*\)/m/') 59 | # if [ $ERG == "m" ]; then 60 | 61 | # EMACS_SOURCE_DIR="$HOME/emacs-20110426" 62 | # else 63 | 64 | # EMACS_SOURCE_DIR="~/emacs-20110426" 65 | # fi 66 | 67 | HIGHL="../highlight-indentation.el" 68 | 69 | CLMACS="${EMACS_SOURCE_DIR}/lisp/emacs-lisp/cl-macs.el" 70 | BYTECOMP="${EMACS_SOURCE_DIR}/lisp/emacs-lisp/bytecomp.el" 71 | CUSTOM="${EMACS_SOURCE_DIR}/lisp/custom.el" 72 | ANSICOLOR="${EMACS_SOURCE_DIR}/lisp/ansi-color.el" 73 | COMINT="${EMACS_SOURCE_DIR}/lisp/comint.el" 74 | CCCMDS="${EMACS_SOURCE_DIR}/lisp/progmodes/cc-cmds.el" 75 | SHELL="${EMACS_SOURCE_DIR}/lisp/shell.el" 76 | PYMACS="../pymacs.el" 77 | # file holding the tests 78 | TESTFILE="py-bug-numbered-tests.el" 79 | TESTFILE2="python-mode-test.el" 80 | DOCU=/tools/fundocu2infoformats.el 81 | 82 | echo "\$PYMACS: $PYMACS" 83 | 84 | $EMACS -Q --batch --eval "(message (emacs-version))" --eval "(when (featurep 'python-mode)(unload-feature 'python-mode t))" --eval "(add-to-list 'load-path \"$PDIR/\")" --eval "(setq py-install-directory \".\")" -load "$PYMACS" -load $CCCMDS -load $COMINT -load $SHELL -load $ANSICOLOR -load $CLMACS -load $BYTECOMP -load $CUSTOM -load $PYTHONMODE \ 85 | --funcall finds-from-programm \ 86 | 87 | 88 | else 89 | 90 | cat < 42 | Insert operator ">" with surrounding spaces. 43 | e.g., `>' will become ` > '. 44 | 45 | With optional ARG, insert ` >= '. 46 | 47 | See also `py-smart-operator-insert' 48 | * py-smart-operator-+ 49 | Insert operator "+" with surrounding spaces. 50 | e.g., `+' will become ` + ', `+=' will become ` += '. 51 | 52 | With optional ARG, insert ` += '. 53 | 54 | See also `py-smart-operator-insert' 55 | * py-smart-operator-- 56 | Insert operator "-" with surrounding spaces. 57 | e.g., `-' will become ` - ', `-=' will become ` -= '. 58 | 59 | With optional numerical ARG 4 -- M-4 --, insert ` -= '. 60 | 61 | See also `py-smart-operator-insert' 62 | * py-smart-operator-\? 63 | Insert operator "?" with space. 64 | e.g., `?' will become `? '. 65 | 66 | With optional ARG, insert ` ?= '. 67 | 68 | See also `py-smart-operator-insert' 69 | * py-smart-operator-! 70 | Insert operator "!" with space. 71 | e.g., `!' will become `! '. 72 | 73 | With optional ARG, insert ` != '. 74 | 75 | See also `py-smart-operator-insert' 76 | * py-smart-operator-% 77 | Insert operator "%" with space. 78 | e.g., `%' will become `% '. 79 | 80 | With optional ARG, insert ` %= '. 81 | 82 | See also `py-smart-operator-insert' 83 | * py-smart-operator-= 84 | Insert operator "=" with surrounding spaces. 85 | e.g., `=' will become ` = '. 86 | 87 | With optional ARG, insert ` == '. 88 | 89 | See also `py-smart-operator-insert' 90 | * py-smart-operator-| 91 | Insert operator "|" with surrounding spaces. 92 | e.g., `|' will become ` | '. 93 | 94 | With optional ARG, insert ` || '. 95 | 96 | See also `py-smart-operator-insert' 97 | * py-toggle-smart-operator 98 | If `py-smart-operator-mode-p' should be on or off. 99 | 100 | Returns value of `py-smart-operator-mode-p' switched to. 101 | * py-smart-operator-mode-off 102 | Make sure, `py-smart-operator-mode-p' is off. 103 | 104 | Returns value of `py-smart-operator-mode-p'. 105 | -------------------------------------------------------------------------------- /doc/commands-py-smart-operator.rst: -------------------------------------------------------------------------------- 1 | Python-mode commands 2 | 3 | ==================== 4 | 5 | py-smart-operator-mode-on 6 | ------------------------- 7 | Make sure, `py-smart-operator-mode-p' is on. 8 | 9 | Returns value of `py-smart-operator-mode-p'. 10 | 11 | smart-operator-self-insert-command 12 | ---------------------------------- 13 | Insert the entered operator plus surrounding spaces. 14 | 15 | py-smart-operator-self-insert-command 16 | ------------------------------------- 17 | Insert the entered operator plus surrounding spaces. 18 | 19 | py-smart-operator-< 20 | ------------------- 21 | Insert operator "<" with surrounding spaces. 22 | e.g., `<' will become ` < ', `<=' will become ` <= '. 23 | 24 | With optional ARG, insert ` <= '. 25 | 26 | See also `py-smart-operator-insert' 27 | 28 | py-smart-operator-: 29 | ------------------- 30 | See `py-smart-operator-insert'. 31 | 32 | py-smart-operator-\. 33 | -------------------- 34 | Insert operator "." with space. 35 | e.g., `.' will become `. ' 36 | 37 | With optional ARG, insert ` .= '. 38 | 39 | See also `py-smart-operator-insert' 40 | 41 | py-smart-operator-& 42 | ------------------- 43 | Insert operator "&" with surrounding spaces. 44 | e.g., `&' will become ` & ', `&=' will become ` &= '. 45 | 46 | With optional ARG, insert ` &= '. 47 | 48 | See also `py-smart-operator-insert' 49 | 50 | py-smart-operator-* 51 | ------------------- 52 | Insert operator "*" with surrounding spaces. 53 | e.g., `*' will become ` * ', `*=' will become ` *= '. 54 | 55 | With optional ARG, insert ` *= '. 56 | 57 | See also `py-smart-operator-insert' 58 | 59 | py-smart-operator-> 60 | ------------------- 61 | Insert operator ">" with surrounding spaces. 62 | e.g., `>' will become ` > '. 63 | 64 | With optional ARG, insert ` >= '. 65 | 66 | See also `py-smart-operator-insert' 67 | 68 | py-smart-operator-+ 69 | ------------------- 70 | Insert operator "+" with surrounding spaces. 71 | e.g., `+' will become ` + ', `+=' will become ` += '. 72 | 73 | With optional ARG, insert ` += '. 74 | 75 | See also `py-smart-operator-insert' 76 | 77 | py-smart-operator-- 78 | ------------------- 79 | Insert operator "-" with surrounding spaces. 80 | e.g., `-' will become ` - ', `-=' will become ` -= '. 81 | 82 | With optional numerical ARG 4 -- M-4 --, insert ` -= '. 83 | 84 | See also `py-smart-operator-insert' 85 | 86 | py-smart-operator-\? 87 | -------------------- 88 | Insert operator "?" with space. 89 | e.g., `?' will become `? '. 90 | 91 | With optional ARG, insert ` ?= '. 92 | 93 | See also `py-smart-operator-insert' 94 | 95 | py-smart-operator-! 96 | ------------------- 97 | Insert operator "!" with space. 98 | e.g., `!' will become `! '. 99 | 100 | With optional ARG, insert ` != '. 101 | 102 | See also `py-smart-operator-insert' 103 | 104 | py-smart-operator-% 105 | ------------------- 106 | Insert operator "%" with space. 107 | e.g., `%' will become `% '. 108 | 109 | With optional ARG, insert ` %= '. 110 | 111 | See also `py-smart-operator-insert' 112 | 113 | py-smart-operator-= 114 | ------------------- 115 | Insert operator "=" with surrounding spaces. 116 | e.g., `=' will become ` = '. 117 | 118 | With optional ARG, insert ` == '. 119 | 120 | See also `py-smart-operator-insert' 121 | 122 | py-smart-operator-| 123 | ------------------- 124 | Insert operator "|" with surrounding spaces. 125 | e.g., `|' will become ` | '. 126 | 127 | With optional ARG, insert ` || '. 128 | 129 | See also `py-smart-operator-insert' 130 | 131 | py-toggle-smart-operator 132 | ------------------------ 133 | If `py-smart-operator-mode-p' should be on or off. 134 | 135 | Returns value of `py-smart-operator-mode-p' switched to. 136 | 137 | py-smart-operator-mode-off 138 | -------------------------- 139 | Make sure, `py-smart-operator-mode-p' is off. 140 | 141 | Returns value of `py-smart-operator-mode-p'. 142 | 143 | -------------------------------------------------------------------------------- /doc/commands-pycomplete.org: -------------------------------------------------------------------------------- 1 | pycomplete.el commands 2 | 3 | * py-complete-which-class 4 | Return current class name based on point. 5 | If no class name is found, return nil. 6 | * py-complete 7 | Complete symbol before point using Pymacs. 8 | * py-complete-help 9 | get help on a python expression 10 | * py-complete-help-thing-at-point 11 | 12 | * py-complete-signature-expr 13 | 14 | * py-complete-electric-lparen 15 | electricly insert '(', and try to get a signature for the stuff to the left 16 | * py-complete-electric-comma 17 | electricly insert ',', and redisplay latest signature 18 | * py-complete-goto-definition 19 | Got to definition of Python function. 20 | * py-complete-set-keymap 21 | Define key map with pycomplete functions. 22 | * py-complete-initialize 23 | Initialize pycomplete hooks. 24 | Should be called from python-mode-hook. Keys are set when 25 | `py-complete-set-keymap-p' is non-nil. 26 | -------------------------------------------------------------------------------- /doc/commands-pycomplete.rst: -------------------------------------------------------------------------------- 1 | Python-mode commands 2 | 3 | ==================== 4 | 5 | py-complete-which-class 6 | ----------------------- 7 | Return current class name based on point. 8 | If no class name is found, return nil. 9 | 10 | py-complete 11 | ----------- 12 | Complete symbol before point using Pymacs. 13 | 14 | py-complete-help 15 | ---------------- 16 | get help on a python expression 17 | 18 | py-complete-help-thing-at-point 19 | ------------------------------- 20 | 21 | 22 | py-complete-signature-expr 23 | -------------------------- 24 | 25 | 26 | py-complete-electric-lparen 27 | --------------------------- 28 | electricly insert '(', and try to get a signature for the stuff to the left 29 | 30 | py-complete-electric-comma 31 | -------------------------- 32 | electricly insert ',', and redisplay latest signature 33 | 34 | py-complete-goto-definition 35 | --------------------------- 36 | Got to definition of Python function. 37 | 38 | py-complete-set-keymap 39 | ---------------------- 40 | Define key map with pycomplete functions. 41 | 42 | py-complete-initialize 43 | ---------------------- 44 | Initialize pycomplete hooks. 45 | Should be called from python-mode-hook. Keys are set when 46 | `py-complete-set-keymap-p' is non-nil. 47 | 48 | -------------------------------------------------------------------------------- /doc/commands-smart-operator.org: -------------------------------------------------------------------------------- 1 | smart-operator.el commands 2 | 3 | * smart-operator-self-insert-command 4 | Insert the entered operator plus surrounding spaces. 5 | * ar-smart-operator-self-insert-command 6 | Insert the entered operator plus surrounding spaces. 7 | * smart-operator-< 8 | Insert operator "<" with surrounding spaces. 9 | e.g., `<' will become ` < ', `<=' will become ` <= '. 10 | 11 | With optional ARG, insert ` <= '. 12 | 13 | See also `smart-operator-insert' 14 | * smart-operator-: 15 | See `smart-operator-insert'. 16 | * smart-operator-\. 17 | Insert operator "." with space. 18 | e.g., `.' will become `. ' 19 | 20 | With optional ARG, insert ` .= '. 21 | 22 | See also `smart-operator-insert' 23 | * smart-operator-& 24 | Insert operator "&" with surrounding spaces. 25 | e.g., `&' will become ` & ', `&=' will become ` &= '. 26 | 27 | With optional ARG, insert ` &= '. 28 | 29 | See also `smart-operator-insert' 30 | * smart-operator-* 31 | Insert operator "*" with surrounding spaces. 32 | e.g., `*' will become ` * ', `*=' will become ` *= '. 33 | 34 | With optional ARG, insert ` *= '. 35 | 36 | See also `smart-operator-insert' 37 | * smart-operator-> 38 | Insert operator ">" with surrounding spaces. 39 | e.g., `>' will become ` > ', `>=' will become ` >= '. 40 | 41 | With optional ARG, insert ` >= '. 42 | 43 | See also `smart-operator-insert' 44 | * smart-operator-+ 45 | Insert operator "+" with surrounding spaces. 46 | e.g., `+' will become ` + ', `+=' will become ` += '. 47 | 48 | With optional ARG, insert ` += '. 49 | 50 | See also `smart-operator-insert' 51 | * smart-operator-- 52 | Insert operator "-" with surrounding spaces. 53 | e.g., `-' will become ` - ', `-=' will become ` -= '. 54 | 55 | With optional ARG, insert ` -= '. 56 | 57 | See also `smart-operator-insert' 58 | * smart-operator-\? 59 | Insert operator "?" with space. 60 | e.g., `?' will become `? '. 61 | 62 | With optional ARG, insert ` ?= '. 63 | 64 | See also `smart-operator-insert' 65 | * smart-operator-! 66 | Insert operator "!" with space. 67 | e.g., `!' will become `! '. 68 | 69 | With optional ARG, insert ` != '. 70 | 71 | See also `smart-operator-insert' 72 | * smart-operator-% 73 | Insert operator "%" with space. 74 | e.g., `%' will become `% '. 75 | 76 | With optional ARG, insert ` %= '. 77 | 78 | See also `smart-operator-insert' 79 | -------------------------------------------------------------------------------- /doc/commands-smart-operator.rst: -------------------------------------------------------------------------------- 1 | Python-mode commands 2 | 3 | ==================== 4 | 5 | smart-operator-self-insert-command 6 | ---------------------------------- 7 | Insert the entered operator plus surrounding spaces. 8 | 9 | ar-smart-operator-self-insert-command 10 | ------------------------------------- 11 | Insert the entered operator plus surrounding spaces. 12 | 13 | smart-operator-< 14 | ---------------- 15 | Insert operator "<" with surrounding spaces. 16 | e.g., `<' will become ` < ', `<=' will become ` <= '. 17 | 18 | With optional ARG, insert ` <= '. 19 | 20 | See also `smart-operator-insert' 21 | 22 | smart-operator-: 23 | ---------------- 24 | See `smart-operator-insert'. 25 | 26 | smart-operator-\. 27 | ----------------- 28 | Insert operator "." with space. 29 | e.g., `.' will become `. ' 30 | 31 | With optional ARG, insert ` .= '. 32 | 33 | See also `smart-operator-insert' 34 | 35 | smart-operator-& 36 | ---------------- 37 | Insert operator "&" with surrounding spaces. 38 | e.g., `&' will become ` & ', `&=' will become ` &= '. 39 | 40 | With optional ARG, insert ` &= '. 41 | 42 | See also `smart-operator-insert' 43 | 44 | smart-operator-* 45 | ---------------- 46 | Insert operator "*" with surrounding spaces. 47 | e.g., `*' will become ` * ', `*=' will become ` *= '. 48 | 49 | With optional ARG, insert ` *= '. 50 | 51 | See also `smart-operator-insert' 52 | 53 | smart-operator-> 54 | ---------------- 55 | Insert operator ">" with surrounding spaces. 56 | e.g., `>' will become ` > ', `>=' will become ` >= '. 57 | 58 | With optional ARG, insert ` >= '. 59 | 60 | See also `smart-operator-insert' 61 | 62 | smart-operator-+ 63 | ---------------- 64 | Insert operator "+" with surrounding spaces. 65 | e.g., `+' will become ` + ', `+=' will become ` += '. 66 | 67 | With optional ARG, insert ` += '. 68 | 69 | See also `smart-operator-insert' 70 | 71 | smart-operator-- 72 | ---------------- 73 | Insert operator "-" with surrounding spaces. 74 | e.g., `-' will become ` - ', `-=' will become ` -= '. 75 | 76 | With optional ARG, insert ` -= '. 77 | 78 | See also `smart-operator-insert' 79 | 80 | smart-operator-\? 81 | ----------------- 82 | Insert operator "?" with space. 83 | e.g., `?' will become `? '. 84 | 85 | With optional ARG, insert ` ?= '. 86 | 87 | See also `smart-operator-insert' 88 | 89 | smart-operator-! 90 | ---------------- 91 | Insert operator "!" with space. 92 | e.g., `!' will become `! '. 93 | 94 | With optional ARG, insert ` != '. 95 | 96 | See also `smart-operator-insert' 97 | 98 | smart-operator-% 99 | ---------------- 100 | Insert operator "%" with space. 101 | e.g., `%' will become `% '. 102 | 103 | With optional ARG, insert ` %= '. 104 | 105 | See also `smart-operator-insert' 106 | 107 | -------------------------------------------------------------------------------- /extensions/python-components-skeletons.el: -------------------------------------------------------------------------------- 1 | ;;; python-components-skeletons.el --- python-mode skeletons 2 | 3 | ;; Maintainer: Andreas Roehler 4 | ;; Keywords: languages 5 | 6 | ;; This program is free software; you can redistribute it and/or modify 7 | ;; it under the terms of the GNU General Public License as published by 8 | ;; the Free Software Foundation, either version 3 of the License, or 9 | ;; (at your option) any later version. 10 | 11 | ;; This program is distributed in the hope that it will be useful, 12 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ;; GNU General Public License for more details. 15 | 16 | ;; You should have received a copy of the GNU General Public License 17 | ;; along with this program. If not, see . 18 | 19 | ;;; Commentary: Derived from GNU python.el, where it's instrumented as abbrev; errors are mine 20 | 21 | ;;; Code: 22 | (define-skeleton py-else 23 | "Auxiliary skeleton." 24 | nil 25 | (unless (eq ?y (read-char "Add `else' clause? (y for yes or RET for no) ")) 26 | (signal 'quit t)) 27 | < "else:" \n) 28 | 29 | (define-skeleton py-if 30 | "If condition " 31 | "if " "if " str ":" \n 32 | _ \n 33 | ("other condition, %s: " 34 | < "elif " str ":" \n 35 | > _ \n nil) 36 | '(py-else) | ^) 37 | 38 | (define-skeleton py-while 39 | "Condition: " 40 | "while " "while " str ":" \n 41 | > -1 _ \n 42 | '(py-else) | ^) 43 | 44 | (define-skeleton py-for 45 | "Target, %s: " 46 | "for " "for " str " in " (skeleton-read "Expression, %s: ") ":" \n 47 | > -1 _ \n 48 | '(py-else) | ^) 49 | 50 | (define-skeleton py-try/except 51 | "Py-try/except skeleton " 52 | "try:" "try:" \n 53 | > -1 _ \n 54 | ("Exception, %s: " 55 | < "except " str '(python-target) ":" \n 56 | > _ \n nil) 57 | < "except:" \n 58 | > _ \n 59 | '(py-else) | ^) 60 | 61 | (define-skeleton py-target 62 | "Auxiliary skeleton." 63 | "Target, %s: " ", " str | -2) 64 | 65 | (define-skeleton py-try/finally 66 | "Py-try/finally skeleton " 67 | "try:" \n 68 | > -1 _ \n 69 | < "finally:" \n 70 | > _ \n) 71 | 72 | (define-skeleton py-def 73 | "Name: " 74 | "def " str " (" ("Parameter, %s: " (unless (equal ?\( (char-before)) ", ") 75 | str) "):" \n 76 | "\"\"\"" - "\"\"\"" \n ; Fixme: extra space inserted -- why?). 77 | > _ \n) 78 | 79 | (define-skeleton py-class 80 | "Name: " 81 | "class " str " (" ("Inheritance, %s: " 82 | (unless (equal ?\( (char-before)) ", ") 83 | str) 84 | & ")" | -2 ; close list or remove opening 85 | ":" \n 86 | "\"\"\"" - "\"\"\"" \n 87 | > _ \n) 88 | 89 | ;;; 90 | 91 | (provide 'python-components-skeletons) 92 | ;;; python-components-skeletons.el ends here 93 | -------------------------------------------------------------------------------- /py-setup-ert-tests.el: -------------------------------------------------------------------------------- 1 | ;;; py-setup-ert-tests.el --- Provide needed forms -*- lexical-binding: t; -*- 2 | 3 | ;; URL: https://gitlab.com/python-mode-devs 4 | ;; Keywords: lisp 5 | 6 | ;; This program is free software; you can redistribute it and/or modify 7 | ;; it under the terms of the GNU General Public License as published by 8 | ;; the Free Software Foundation, either version 3 of the License, or 9 | ;; (at your option) any later version. 10 | 11 | ;; This program is distributed in the hope that it will be useful, 12 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ;; GNU General Public License for more details. 15 | 16 | ;; You should have received a copy of the GNU General Public License 17 | ;; along with this program. If not, see . 18 | 19 | ;;; Commentary: 20 | 21 | ;;; Code: 22 | 23 | (defmacro py-test (contents mode verbose &rest body) 24 | "Create temp buffer inserting CONTENTS. 25 | 26 | BODY is code to be executed within the temp buffer " 27 | (declare (indent 1) (debug t)) 28 | `(with-temp-buffer 29 | (let (hs-minor-mode py--imenu-create-index-p) 30 | (insert ,contents) 31 | (funcall ,mode) 32 | (when ,verbose 33 | (switch-to-buffer (current-buffer)) 34 | (font-lock-fontify-region (point-min)(point-max))) 35 | ,@body))) 36 | 37 | (defmacro py-test-point-min (contents mode verbose &rest body) 38 | "Create temp buffer inserting CONTENTS. 39 | BODY is code to be executed within the temp buffer. Point is 40 | at the beginning of buffer." 41 | (declare (debug t)) 42 | `(with-temp-buffer 43 | (let (hs-minor-mode py--imenu-create-index-p) 44 | (insert ,contents) 45 | (funcall ,mode) 46 | (goto-char (point-min)) 47 | (and ,verbose 48 | (switch-to-buffer (current-buffer)) 49 | (font-lock-fontify-region (point-min)(point-max))) 50 | ,@body))) 51 | 52 | (provide 'py-setup-ert-tests) 53 | ;; py-setup-ert-tests.el ends here 54 | -------------------------------------------------------------------------------- /pyflakespep8.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Author: Keegan Carruthers-Smith 4 | # https://bitbucket.org/keegancsmith/dotfiles/raw/tip/misc/pyflakespep8.py 5 | 6 | import commands 7 | import re 8 | import sys 9 | 10 | def make_re(*msgs): 11 | return re.compile('(%s)' % '|'.join(msgs)) 12 | 13 | pyflakes_ignore = make_re('unable to detect undefined names') 14 | pyflakes_warning = make_re( 15 | 'imported but unused', 16 | 'is assigned to but never used', 17 | 'redefinition of unused', 18 | ) 19 | pep8_ignore = ['E501'] 20 | pep8_warning = make_re('.') 21 | 22 | def pyflakespep8(cmd, ignore_re, warning_re): 23 | output = commands.getoutput(cmd) 24 | for line in output.splitlines(): 25 | if ignore_re and ignore_re.search(line): 26 | continue 27 | elif ': ' in line and warning_re.search(line): 28 | line = '%s: WARNING %s' % tuple(line.split(': ', 1)) 29 | print line 30 | 31 | pyflakespep8('pyflakes %s' % sys.argv[1], pyflakes_ignore, pyflakes_warning) 32 | print '## pyflakes above, pep8 below ##' 33 | pep8_ignore = ' '.join('--ignore=%s' % i for i in pep8_ignore) 34 | pyflakespep8('pep8 %s --repeat %s' % (pep8_ignore, sys.argv[1]), None, pep8_warning) 35 | -------------------------------------------------------------------------------- /python-mode-compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # -- 3 | 4 | # Author: Andreas Roehler 5 | 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | # Commentary: 17 | 18 | # tests Emacs python-mode 19 | # 20 | # Code: 21 | 22 | # Edit the vars pointing to the directories/files 23 | # holding your python-mode for test 24 | 25 | # assumes python-mode files in current directory 26 | 27 | # the path 28 | # needs being in `test' directory 29 | PDIR=`pwd` 30 | 31 | 32 | # write PATH-TO-EMACS source code directory here 33 | EMACS_SOURCE_DIR= 34 | EMACS_SOURCE_DIR="$HOME/emacs-23.4" 35 | 36 | # python-mode file to load 37 | if [ -s "python-components-mode.el" ]; 38 | then 39 | PYTHONMODE="python-components-mode.el" 40 | else 41 | PYTHONMODE="python-mode.el" 42 | fi 43 | 44 | if [ $1 ]; then 45 | EMACS_SOURCE_DIR=$1 46 | fi 47 | 48 | 49 | if [ $EMACS_SOURCE_DIR ]; then 50 | 51 | EMACS="${EMACS_SOURCE_DIR}/src/emacs" 52 | 53 | # else 54 | # EMACS=emacs 55 | # when installed Emacs shall be used, CCCMDS must be set 56 | # CCCMDS="${EMACS_SOURCE_DIR}/lisp/progmodes/cc-cmds.el" 57 | 58 | # ERG=$(echo $LOGNAME | sed 's/^s\(.*\)/m/') 59 | # if [ $ERG == "m" ]; then 60 | 61 | # EMACS_SOURCE_DIR="$HOME/emacs-20110426" 62 | # else 63 | 64 | # EMACS_SOURCE_DIR="~/emacs-20110426" 65 | # fi 66 | 67 | HIGHL="highlight-indentation.el" 68 | CLMACS="${EMACS_SOURCE_DIR}/lisp/emacs-lisp/cl-macs.el" 69 | BYTECOMP="${EMACS_SOURCE_DIR}/lisp/emacs-lisp/bytecomp.el" 70 | CUSTOM="${EMACS_SOURCE_DIR}/lisp/custom.el" 71 | ANSICOLOR="${EMACS_SOURCE_DIR}/lisp/ansi-color.el" 72 | COMINT="${EMACS_SOURCE_DIR}/lisp/comint.el" 73 | CCCMDS="${EMACS_SOURCE_DIR}/lisp/progmodes/cc-cmds.el" 74 | SHELL="${EMACS_SOURCE_DIR}/lisp/shell.el" 75 | SKEL="${EMACS_SOURCE_DIR}/lisp/skeleton.el" 76 | PYMACS="pymacs.el" 77 | # file holding the tests 78 | TESTFILE="test/py-bug-numbered-tests.el" 79 | TESTFILE2="test/python-mode-test.el" 80 | CEXEC="python-extended-executes.el" 81 | 82 | echo "\$PYMACS: $PYMACS" 83 | echo "\$PYTHONMODE: $PYTHONMODE" 84 | echo "\$PDIR/\$TESTFILE: $PDIR/$TESTFILE" 85 | 86 | $EMACS -Q --batch --eval "(message (emacs-version))" --eval "(when (featurep 'python)(unload-feature 'python t))" --eval "(when (featurep 'python-mode)(unload-feature 'python-mode t))" --eval "(add-to-list 'load-path \"$PDIR/\")" --eval "(add-to-list 'load-path \"$TESTDIR/\")" --eval "(setq py-install-directory \".\")" -load "$PYMACS" -load $CCCMDS -load $COMINT -load $SHELL -load $ANSICOLOR -load $CLMACS -load $CUSTOM -load $SKEL -load "${EMACS_SOURCE_DIR}/extensions/$HIGHL" -load $PYTHONMODE --eval "(quietly-read-abbrev-file (expand-file-name \"~/.abbrev_defs\"))" \ 87 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/python-components-mode.el\"))" \ 88 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/column-marker.el\"))" \ 89 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/highlight-indentation.el\"))" \ 90 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/pymacs.el\"))" \ 91 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/python-components-completion.el\"))" \ 92 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/python-components-edit.el\"))" \ 93 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/python-components-electric.el\"))" \ 94 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/python-components-exec-forms.el\"))" \ 95 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/python-components-execute.el\"))" \ 96 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/python-components-extensions.el\"))" \ 97 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/python-components-help.el\"))" \ 98 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/python-components-imenu.el\"))" \ 99 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/python-components-intern.el\"))" \ 100 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/python-components-macros.el\"))" \ 101 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/python-components-mode.el\"))" \ 102 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/feg-python-el-extracts.el\"))" \ 103 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/python-components-move.el\"))" \ 104 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/python-components-named-shells.el\"))" \ 105 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/python-components-pdb.el\"))" \ 106 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/python-components-re-forms.el\"))" \ 107 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/python-components-send.el\"))" \ 108 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/python-components-shell-complete.el\"))" \ 109 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/python-components-skeletons.el\"))" \ 110 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/python-extended-executes.el\"))" \ 111 | \ 112 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/test/py-bug-numbered-tests.el\"))" \ 113 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/test/python-mode-test.el\"))" \ 114 | --eval "(byte-compile-file (expand-file-name \"~/arbeit/emacs/python-modes/components-python-mode/test/python-executes-test.el\"))" \ 115 | 116 | else 117 | 118 | cat < 4 | ;; Keywords: languages, convenience 5 | 6 | ;; This program is free software; you can redistribute it and/or modify 7 | ;; it under the terms of the GNU General Public License as published by 8 | ;; the Free Software Foundation, either version 3 of the License, or 9 | ;; (at your option) any later version. 10 | 11 | ;; This program is distributed in the hope that it will be useful, 12 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ;; GNU General Public License for more details. 15 | 16 | ;; You should have received a copy of the GNU General Public License 17 | ;; along with this program. If not, see . 18 | 19 | ;;; Commentary: Edit `py-test-pyshellname-list' before 20 | ;; running this test-builder or give a list of shells as 21 | ;; arguments 22 | 23 | ;;; Code: 24 | 25 | (defun python-complete-test (&optional arg) 26 | (interactive "p") 27 | (let ((teststring "#! /usr/bin/env python 28 | pri")) 29 | (py-bug-tests-intern 'python-complete-base arg teststring))) 30 | 31 | (defun python-complete-base () 32 | (save-excursion (completion-at-point)) 33 | ;; (sit-for 0.1) 34 | (assert (looking-at "nt") nil "py-completion-at-point-test failed")) 35 | 36 | (defun usr-bin-python-complete-test (&optional arg) 37 | (interactive "p") 38 | (let ((teststring "#! /usr/bin/python 39 | pri")) 40 | (py-bug-tests-intern 'usr-bin-python-complete-base arg teststring))) 41 | 42 | (defun usr-bin-python-complete-base () 43 | (save-excursion (completion-at-point)) 44 | ;; (sit-for 0.1) 45 | (assert (looking-at "nt") nil "py-completion-at-point-test failed")) 46 | 47 | (defun usr-bin-python2.7-complete-test (&optional arg) 48 | (interactive "p") 49 | (let ((teststring "#! /usr/bin/python2.7 50 | pri")) 51 | (py-bug-tests-intern 'usr-bin-python2.7-complete-base arg teststring))) 52 | 53 | (defun usr-bin-python2.7-complete-base () 54 | (save-excursion (completion-at-point)) 55 | ;; (sit-for 0.1) 56 | (assert (looking-at "nt") nil "py-completion-at-point-test failed")) 57 | 58 | (defun home-speck-arbeit-python-epdfree-epd_free-7.2-2-rh5-x86-bin-python2.7-complete-test (&optional arg) 59 | (interactive "p") 60 | (let ((teststring "#! /home/speck/arbeit/python/epdfree/epd_free-7.2-2-rh5-x86/bin/python2.7 61 | pri")) 62 | (py-bug-tests-intern 'home-speck-arbeit-python-epdfree-epd_free-7.2-2-rh5-x86-bin-python2.7-complete-base arg teststring))) 63 | 64 | (defun home-speck-arbeit-python-epdfree-epd_free-7.2-2-rh5-x86-bin-python2.7-complete-base () 65 | (save-excursion (completion-at-point)) 66 | ;; (sit-for 0.1) 67 | (assert (looking-at "nt") nil "py-completion-at-point-test failed")) 68 | 69 | (defun usr-bin-python3-complete-test (&optional arg) 70 | (interactive "p") 71 | (let ((teststring "#! /usr/bin/python3 72 | pri")) 73 | (py-bug-tests-intern 'usr-bin-python3-complete-base arg teststring))) 74 | 75 | (defun usr-bin-python3-complete-base () 76 | (save-excursion (completion-at-point)) 77 | ;; (sit-for 0.1) 78 | (assert (looking-at "nt") nil "py-completion-at-point-test failed")) 79 | 80 | (defun usr-bin-python3.1-complete-test (&optional arg) 81 | (interactive "p") 82 | (let ((teststring "#! /usr/bin/python3.1 83 | pri")) 84 | (py-bug-tests-intern 'usr-bin-python3.1-complete-base arg teststring))) 85 | 86 | (defun usr-bin-python3.1-complete-base () 87 | (save-excursion (completion-at-point)) 88 | ;; (sit-for 0.1) 89 | (assert (looking-at "nt") nil "py-completion-at-point-test failed")) 90 | 91 | (defun ipython-complete-test (&optional arg) 92 | (interactive "p") 93 | (let ((teststring "#! /usr/bin/env ipython 94 | pri")) 95 | (py-bug-tests-intern 'ipython-complete-base arg teststring))) 96 | 97 | (defun ipython-complete-base () 98 | (save-excursion (completion-at-point)) 99 | ;; (sit-for 0.1) 100 | (assert (looking-at "nt") nil "py-completion-at-point-test failed")) 101 | 102 | (defun usr-bin-ipython-complete-test (&optional arg) 103 | (interactive "p") 104 | (let ((teststring "#! /usr/bin/ipython 105 | pri")) 106 | (py-bug-tests-intern 'usr-bin-ipython-complete-base arg teststring))) 107 | 108 | (defun usr-bin-ipython-complete-base () 109 | (save-excursion (completion-at-point)) 110 | ;; (sit-for 0.1) 111 | (assert (looking-at "nt") nil "py-completion-at-point-test failed")) 112 | 113 | (defun home-speck-arbeit-python-epd_free-7.1-2-rh5-x86-bin-ipython-complete-test (&optional arg) 114 | (interactive "p") 115 | (let ((teststring "#! /home/speck/arbeit/python/epd_free-7.1-2-rh5-x86/bin/ipython 116 | pri")) 117 | (py-bug-tests-intern 'home-speck-arbeit-python-epd_free-7.1-2-rh5-x86-bin-ipython-complete-base arg teststring))) 118 | 119 | (defun home-speck-arbeit-python-epd_free-7.1-2-rh5-x86-bin-ipython-complete-base () 120 | (save-excursion (completion-at-point)) 121 | ;; (sit-for 0.1) 122 | (assert (looking-at "nt") nil "py-completion-at-point-test failed")) 123 | 124 | 125 | (provide "py-completion-tests") 126 | ;;; py-completion-tests ends here 127 | 128 | -------------------------------------------------------------------------------- /test/py-ert-always-split-lp-1361531-tests.el: -------------------------------------------------------------------------------- 1 | ;;; py-ert-always-split-lp-1361531-tests.el --- Test splitting 2 | 3 | ;; URL: https://gitlab.com/python-mode-devs 4 | ;; Keywords: languages, convenience 5 | 6 | ;; This program is free software; you can redistribute it and/or modify 7 | ;; it under the terms of the GNU General Public License as published by 8 | ;; the Free Software Foundation, either version 3 of the License, or 9 | ;; (at your option) any later version. 10 | 11 | ;; This program is distributed in the hope that it will be useful, 12 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ;; GNU General Public License for more details. 15 | 16 | ;; You should have received a copy of the GNU General Public License 17 | ;; along with this program. If not, see . 18 | 19 | ;;; Commentary: 20 | 21 | ;; This file is generated by function from python-mode-utils.el - see in 22 | ;; directory devel. Edits here might not be persistent. 23 | 24 | ;;; Code: 25 | 26 | 27 | (ert-deftest py-ert-always-split-dedicated-lp-1361531-python-test () 28 | (py-test-with-temp-buffer 29 | "#! /usr/bin/env python 30 | # -*- coding: utf-8 -*- 31 | print(\"I'm the py-always-split-dedicated-lp-1361531-python-test\")" 32 | (delete-other-windows) 33 | (let* ((py-split-window-on-execute 'always) 34 | (erg1 (progn (py-execute-statement-python-dedicated) py-output-buffer)) 35 | (erg2 (progn (py-execute-statement-python-dedicated) py-output-buffer))) 36 | (sit-for 1 t) 37 | (when py-debug-p (message "(count-windows) %s" (count-windows))) 38 | (should (< 2 (count-windows))) 39 | (py-kill-buffer-unconditional erg1) 40 | (py-kill-buffer-unconditional erg2) 41 | (py-restore-window-configuration)))) 42 | 43 | (ert-deftest py-ert-always-split-dedicated-lp-1361531-ipython-test () 44 | (py-test-with-temp-buffer 45 | "#! /usr/bin/env ipython 46 | # -*- coding: utf-8 -*- 47 | print(\"I'm the py-always-split-dedicated-lp-1361531-ipython-test\")" 48 | (delete-other-windows) 49 | (let* ((py-split-window-on-execute 'always) 50 | (erg1 (progn (py-execute-statement-ipython-dedicated) py-output-buffer)) 51 | (erg2 (progn (py-execute-statement-ipython-dedicated) py-output-buffer))) 52 | (sit-for 1 t) 53 | (when py-debug-p (message "(count-windows) %s" (count-windows))) 54 | (should (< 2 (count-windows))) 55 | (py-kill-buffer-unconditional erg1) 56 | (py-kill-buffer-unconditional erg2) 57 | (py-restore-window-configuration)))) 58 | 59 | (ert-deftest py-ert-always-split-dedicated-lp-1361531-jython-test () 60 | (py-test-with-temp-buffer 61 | "#! /usr/bin/env jython 62 | # -*- coding: utf-8 -*- 63 | print(\"I'm the py-always-split-dedicated-lp-1361531-jython-test\")" 64 | (delete-other-windows) 65 | (let* ((py-split-window-on-execute 'always) 66 | (erg1 (progn (py-execute-statement-jython-dedicated) py-output-buffer)) 67 | (erg2 (progn (py-execute-statement-jython-dedicated) py-output-buffer))) 68 | (sit-for 1 t) 69 | (when py-debug-p (message "(count-windows) %s" (count-windows))) 70 | (should (< 2 (count-windows))) 71 | (py-kill-buffer-unconditional erg1) 72 | (py-kill-buffer-unconditional erg2) 73 | (py-restore-window-configuration)))) 74 | 75 | (ert-deftest py-ert-always-split-dedicated-lp-1361531-python3-test () 76 | (py-test-with-temp-buffer 77 | "#! /usr/bin/env python3 78 | # -*- coding: utf-8 -*- 79 | print(\"I'm the py-always-split-dedicated-lp-1361531-python3-test\")" 80 | (delete-other-windows) 81 | (let* ((py-split-window-on-execute 'always) 82 | (erg1 (progn (py-execute-statement-python3-dedicated) py-output-buffer)) 83 | (erg2 (progn (py-execute-statement-python3-dedicated) py-output-buffer))) 84 | (sit-for 1 t) 85 | (when py-debug-p (message "(count-windows) %s" (count-windows))) 86 | (should (< 2 (count-windows))) 87 | (py-kill-buffer-unconditional erg1) 88 | (py-kill-buffer-unconditional erg2) 89 | (py-restore-window-configuration)))) 90 | 91 | ;; py-ert-always-split-lp-1361531-tests.el ends here 92 | (provide 'py-ert-always-split-lp-1361531-tests) 93 | -------------------------------------------------------------------------------- /test/py-ert-always-split-tests.el: -------------------------------------------------------------------------------- 1 | ;;; py-ert-always-split-tests.el --- Test splitting -*- lexical-binding: t; -*- 2 | 3 | ;; URL: https://gitlab.com/python-mode-devs 4 | ;; Keywords: languages, convenience 5 | 6 | ;; This program is free software; you can redistribute it and/or modify 7 | ;; it under the terms of the GNU General Public License as published by 8 | ;; the Free Software Foundation, either version 3 of the License, or 9 | ;; (at your option) any later version. 10 | 11 | ;; This program is distributed in the hope that it will be useful, 12 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ;; GNU General Public License for more details. 15 | 16 | ;; You should have received a copy of the GNU General Public License 17 | ;; along with this program. If not, see . 18 | 19 | ;;; Commentary: 20 | 21 | ;; This file is generated by function from python-mode-utils.el - see in 22 | ;; directory devel. Edits here might not be persistent. 23 | 24 | ;;; Code: 25 | 26 | (require 'py-setup-ert-tests) 27 | 28 | (ert-deftest py-ert-always-split-dedicated-lp-1361531-python-test () 29 | (py-test 30 | "#! /usr/bin/env python 31 | # -*- coding: utf-8 -*- 32 | print(\"I'm the py-always-split-dedicated-lp-1361531-python-test\")" 33 | (delete-other-windows) 34 | (let* ((py-split-window-on-execute 'always) 35 | (erg1 (progn (py-execute-statement-python-dedicated) py-output-buffer)) 36 | (erg2 (progn (py-execute-statement-python-dedicated) py-output-buffer))) 37 | (sit-for 0.1 t) 38 | (when py-debug-p (message "(count-windows) %s" (count-windows))) 39 | (should (< 2 (count-windows))) 40 | (py-kill-buffer-unconditional erg1) 41 | (py-kill-buffer-unconditional erg2) 42 | (py-restore-window-configuration)))) 43 | 44 | (ert-deftest py-ert-always-split-dedicated-lp-1361531-ipython-test () 45 | (py-test 46 | "#! /usr/bin/env ipython 47 | # -*- coding: utf-8 -*- 48 | print(\"I'm the py-always-split-dedicated-lp-1361531-ipython-test\")" 49 | (delete-other-windows) 50 | (let* ((py-split-window-on-execute 'always) 51 | (erg1 (progn (py-execute-statement-ipython-dedicated) py-output-buffer)) 52 | (erg2 (progn (py-execute-statement-ipython-dedicated) py-output-buffer))) 53 | (sit-for 0.1 t) 54 | (when py-debug-p (message "(count-windows) %s" (count-windows))) 55 | (should (< 2 (count-windows))) 56 | (py-kill-buffer-unconditional erg1) 57 | (py-kill-buffer-unconditional erg2) 58 | (py-restore-window-configuration)))) 59 | 60 | (ert-deftest py-ert-always-split-dedicated-lp-1361531-jython-test () 61 | (py-test 62 | "#! /usr/bin/env jython 63 | # -*- coding: utf-8 -*- 64 | print(\"I'm the py-always-split-dedicated-lp-1361531-jython-test\")" 65 | (delete-other-windows) 66 | (let* ((py-split-window-on-execute 'always) 67 | (erg1 (progn (py-execute-statement-jython-dedicated) py-output-buffer)) 68 | (erg2 (progn (py-execute-statement-jython-dedicated) py-output-buffer))) 69 | (sit-for 0.1 t) 70 | (when py-debug-p (message "(count-windows) %s" (count-windows))) 71 | (should (< 2 (count-windows))) 72 | (py-kill-buffer-unconditional erg1) 73 | (py-kill-buffer-unconditional erg2) 74 | (py-restore-window-configuration)))) 75 | 76 | (ert-deftest py-ert-always-split-dedicated-lp-1361531-python3-test () 77 | (py-test 78 | "#! /usr/bin/env python3 79 | # -*- coding: utf-8 -*- 80 | print(\"I'm the py-always-split-dedicated-lp-1361531-python3-test\")" 81 | (delete-other-windows) 82 | (let* ((py-split-window-on-execute 'always) 83 | (erg1 (progn (py-execute-statement-python3-dedicated) py-output-buffer)) 84 | (erg2 (progn (py-execute-statement-python3-dedicated) py-output-buffer))) 85 | (sit-for 0.1 t) 86 | (when py-debug-p (message "(count-windows) %s" (count-windows))) 87 | (should (< 2 (count-windows))) 88 | (py-kill-buffer-unconditional erg1) 89 | (py-kill-buffer-unconditional erg2) 90 | (py-restore-window-configuration)))) 91 | 92 | ;; py-ert-always-split-tests.el ends here 93 | (provide 'py-ert-always-split-tests) 94 | -------------------------------------------------------------------------------- /test/py-ert-execute-block-test.el: -------------------------------------------------------------------------------- 1 | ;;; py-ert-execute-block-test.el --- py-execute-block tests 2 | 3 | ;; URL: https://gitlab.com/python-mode-devs 4 | ;; Keywords: languages, convenience 5 | 6 | ;; This program is free software; you can redistribute it and/or modify 7 | ;; it under the terms of the GNU General Public License as published by 8 | ;; the Free Software Foundation, either version 3 of the License, or 9 | ;; (at your option) any later version. 10 | 11 | ;; This program is distributed in the hope that it will be useful, 12 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ;; GNU General Public License for more details. 15 | 16 | ;; You should have received a copy of the GNU General Public License 17 | ;; along with this program. If not, see . 18 | 19 | ;;; Commentary: 20 | 21 | ;; This file is generated by function from python-mode-utils.el - see in 22 | ;; directory devel. Edits here might not be persistent. 23 | 24 | ;;; Code: 25 | 26 | (ert-deftest py-ert-execute-block-python-test () 27 | (let ((buffer (py--choose-buffer-name "python"))) 28 | (py-test 29 | "if True: 30 | print(\"one\") 31 | print(\"two\")" 32 | (py-execute-block-python) 33 | (set-buffer buffer) 34 | (should (search-backward "two"))))) 35 | 36 | (ert-deftest py-ert-execute-block-python2-test () 37 | (let ((buffer (py--choose-buffer-name "python2"))) 38 | (py-test 39 | "if True: 40 | print(\"one\") 41 | print(\"two\")" 42 | (py-execute-block-python2) 43 | (set-buffer buffer) 44 | (should (search-backward "two"))))) 45 | 46 | (ert-deftest py-ert-execute-block-python3-test () 47 | (let ((buffer (py--choose-buffer-name "python3"))) 48 | (py-test 49 | "if True: 50 | print(\"one\") 51 | print(\"two\")" 52 | (py-execute-block-python3) 53 | (set-buffer buffer) 54 | (should (search-backward "two"))))) 55 | 56 | (ert-deftest py-ert-execute-block-ipython-test () 57 | (let ((buffer (py--choose-buffer-name "ipython"))) 58 | (py-test 59 | "if True: 60 | print(\"one\") 61 | print(\"two\")" 62 | (py-execute-block-ipython) 63 | (set-buffer buffer) 64 | (should (search-backward "two"))))) 65 | 66 | (ert-deftest py-ert-execute-block-ipython3-test () 67 | (let ((buffer (py--choose-buffer-name "ipython3"))) 68 | (py-test 69 | "if True: 70 | print(\"one\") 71 | print(\"two\")" 72 | (py-execute-block-ipython3) 73 | (set-buffer buffer) 74 | (should (search-backward "two"))))) 75 | 76 | (provide 'py-ert-execute-block-test) 77 | ;;; py-ert-execute-block-test.el here 78 | -------------------------------------------------------------------------------- /test/py-ert-execute-region-test.el: -------------------------------------------------------------------------------- 1 | ;;; py-ert-execute-region-test.el --- py-execute-region tests -*- lexical-binding: t; -*- -*- lexical-binding: t; -*- 2 | 3 | ;; URL: https://gitlab.com/python-mode-devs 4 | ;; Keywords: languages, convenience 5 | 6 | ;; This program is free software; you can redistribute it and/or modify 7 | ;; it under the terms of the GNU General Public License as published by 8 | ;; the Free Software Foundation, either version 3 of the License, or 9 | ;; (at your option) any later version. 10 | 11 | ;; This program is distributed in the hope that it will be useful, 12 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ;; GNU General Public License for more details. 15 | 16 | ;; You should have received a copy of the GNU General Public License 17 | ;; along with this program. If not, see . 18 | 19 | ;;; Commentary: 20 | 21 | ;;; Code: 22 | 23 | (require 'py-setup-ert-tests) 24 | 25 | (ert-deftest py-ert-execute-region-python-test () 26 | (py-test 27 | "print(\"one\") 28 | print(\"two\")" 29 | 'python-mode 30 | 'py-verbose-p 31 | (if 32 | (executable-find "python") 33 | (let ((buffer "*Python*")) 34 | (py-execute-region-python (point-min) (point-max)) 35 | ;; (sit-for 0.5 t) 36 | (set-buffer buffer) 37 | (goto-char (point-max)) 38 | (should (search-backward "two")))) 39 | (when py-verbose-p (message "%s" "Don't see a ‘python’ executable")))) 40 | 41 | (ert-deftest py-ert-execute-region-python3-test () 42 | (py-test 43 | "print(\"one\") 44 | print(\"two\")" 45 | 'python-mode 46 | 'py-verbose-p 47 | (if 48 | (executable-find "python3") 49 | (let ((buffer "*Python3*")) 50 | (py-execute-region-python3 (point-min) (point-max)) 51 | (set-buffer (get-buffer buffer)) 52 | (goto-char (point-max)) 53 | (should (search-backward "two"))) 54 | (when py-verbose-p (message "%s" "Don't see a ‘python3’ executable"))))) 55 | 56 | (ert-deftest py-ert-execute-region-ipython-test () 57 | (py-test 58 | "print(\"one\") 59 | print(\"two\")" 60 | 'python-mode 61 | 'py-verbose-p 62 | (if 63 | (ignore-errors (executable-find "ipython")) 64 | (let ((buffer "*IPython*")) 65 | (py-execute-region-ipython (point-min) (point-max)) 66 | (set-buffer buffer) 67 | ;; (accept-process-output (get-buffer-process buffer) 0.1) 68 | ;; (switch-to-buffer (current-buffer)) 69 | (goto-char (point-max)) 70 | ;; (sit-for 0.5 t) 71 | (should (search-backward "two")))) 72 | (when py-verbose-p 73 | (message "py-ert-execute-region-ipython-test: %s" "No executable found!")))) 74 | 75 | 76 | (ert-deftest py-ert-execute-region-ipython3-test () 77 | (py-test 78 | "print(\"one\") 79 | print(\"two\")" 80 | 'python-mode 81 | 'py-verbose-p 82 | (if 83 | (ignore-errors (executable-find "ipython3")) 84 | (let ((buffer "*IPython3*") 85 | ;; (buffer (py--choose-buffer-name "ipython3")) 86 | (inhibit-point-motion-hooks t)) 87 | (py-execute-region-ipython3 (point-min) (point-max)) 88 | (set-buffer buffer) 89 | (when py-debug-p (message "current-buffer0: %s" (current-buffer)) 90 | (sit-for 0.1) 91 | ;; (accept-process-output (get-buffer-process buffer) 1) 92 | (when py-debug-p (message "current-buffer1: %s" (current-buffer))) 93 | ;; (goto-char (point-max)) 94 | ;; (switch-to-buffer (current-buffer)) 95 | (when py-debug-p (message "current-buffer2: %s" (current-buffer))) 96 | (goto-char (point-max)) 97 | (when py-debug-p (message "current-buffer3: %s" (current-buffer))) 98 | ;; (font-lock-ensure) 99 | ;; (sit-for 2) 100 | (when py-debug-p (message "current-buffer4: %s" (current-buffer))) 101 | (should (search-backward "two"))))) 102 | (when py-verbose-p 103 | (message "py-ert-execute-region-ipython3-test: %s" "No executable found!")))) 104 | 105 | (ert-deftest py-ert-execute-region-jython-test () 106 | (py-test 107 | "print(\"one\") 108 | print(\"two\")" 109 | 'python-mode 110 | 'py-verbose-p 111 | (if 112 | (executable-find "jython") 113 | (let ((buffer "*Jython*")) 114 | (py-execute-region-jython (point-min) (point-max)) 115 | (set-buffer buffer) 116 | (goto-char (point-max)) 117 | (should (search-backward "two")))) 118 | (when py-verbose-p 119 | (message "py-ert-execute-region-jython-test: %s" "No executable found!")))) 120 | 121 | (provide 'py-ert-execute-region-test) 122 | ;;; py-ert-execute-region-test.el here 123 | -------------------------------------------------------------------------------- /test/py-ert-hide-tests.el: -------------------------------------------------------------------------------- 1 | ;;; py-ert-hide-tests.el --- 2 | 3 | ;; URL: https://gitlab.com/python-mode-devs 4 | ;; Keywords: languages, convenience 5 | 6 | ;; This program is free software; you can redistribute it and/or modify 7 | ;; it under the terms of the GNU General Public License as published by 8 | ;; the Free Software Foundation, either version 3 of the License, or 9 | ;; (at your option) any later version. 10 | 11 | ;; This program is distributed in the hope that it will be useful, 12 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ;; GNU General Public License for more details. 15 | 16 | ;; You should have received a copy of the GNU General Public License 17 | ;; along with this program. If not, see . 18 | 19 | (require 'py-setup-ert-tests) 20 | 21 | ;; (ert-deftest py-ert-hide-partial-expression-test-Li7vPR () 22 | 23 | ;; (py-test-point-min " 24 | ;; class kugel(object): 25 | ;; zeit = time.strftime('%Y%m%d--%H-%M-%S') 26 | 27 | ;; def pylauf(self): 28 | ;; \"\"\"Eine Doku fuer pylauf\"\"\" 29 | ;; ausgabe = [\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \", \" \"] 30 | 31 | ;; ausgabe[0] = treffer 32 | ;; if treffer in gruen: 33 | ;; # print \"0, Gruen\" 34 | ;; datei.write(str(spiel[i]) + \"\\n\") 35 | ;; " 36 | ;; (font-lock-ensure) 37 | ;; (search-forward "+ \"") 38 | ;; (py-hide-partial-expression) 39 | ;; (should (string-match "overlay from 315 to 317" (prin1-to-string (car (overlays-at (point)))))) 40 | ;; (py-show) 41 | ;; (should (not (string-match "overlay" (prin1-to-string (car (overlays-at (point))))))) 42 | ;; )) 43 | 44 | (ert-deftest py-ert-hide-expression-test () 45 | (py-test-point-min " 46 | class kugel(object): 47 | zeit = time.strftime('%Y%m%d--%H-%M-%S') 48 | def pylauf(self): 49 | \"\"\"Eine Doku fuer pylauf\"\"\" 50 | ausgabe = [\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \", \" \"] 51 | ausgabe[0] = treffer 52 | if treffer in gruen: 53 | # print \"0, Gruen\" 54 | datei.write(str(spiel[i]) + \"\\n\") 55 | " 56 | 'python-mode 57 | 'py-verbose-p 58 | (font-lock-ensure) 59 | (search-forward "+ \"") 60 | (py-hide-expression) 61 | (should (string-match "overlay from 286 to 319" (prin1-to-string (car (overlays-at (point)))))) 62 | (py-show) 63 | (should (not (string-match "overlay" (prin1-to-string (car (overlays-at (point))))))))) 64 | 65 | (ert-deftest py-ert-hide-clause-test-qsv8kt () 66 | (py-test-point-min " 67 | class kugel(object): 68 | zeit = time.strftime('%Y%m%d--%H-%M-%S') 69 | def pylauf(self): 70 | \"\"\"Eine Doku fuer pylauf\"\"\" 71 | ausgabe = [\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \", \" \"] 72 | ausgabe[0] = treffer 73 | if treffer in gruen: 74 | # print \"0, Gruen\" 75 | datei.write(str(spiel[i]) + \"\\n\") 76 | " 77 | 'python-mode 78 | 'py-verbose-p 79 | (font-lock-ensure) 80 | (search-forward "+ \"") 81 | (py-hide-clause) 82 | (should (string-match "overlay from 222 to 319" (prin1-to-string (car (overlays-at (point)))))) 83 | (py-show) 84 | (should (not (string-match "overlay" (prin1-to-string (car (overlays-at (point))))))))) 85 | 86 | 87 | (ert-deftest py-ert-hide-clause-test-rO7k4k () 88 | (py-test "if 0 < treffer: 89 | if 18 < treffer: 90 | ausgabe[6] = treffer 91 | else: 92 | ausgabe[7] = treffer 93 | " 94 | 'python-mode 95 | 'py-verbose-p 96 | (font-lock-ensure) 97 | (goto-char (point-max)) 98 | (search-backward "6") 99 | (py-hide-clause) 100 | ;; (should (search-forward "else")) 101 | (should-not (string-match (prin1-to-string (car (overlays-at (point)))) "overlay from 21 to 105" )) 102 | (should-not (string-match (prin1-to-string (car (overlays-at (point)))) "overlay from 21 to 65")))) 103 | 104 | (ert-deftest py-ert-hide-block-test-5j57vC () 105 | (py-test-point-min " 106 | class kugel(object): 107 | zeit = time.strftime('%Y%m%d--%H-%M-%S') 108 | def pylauf(self): 109 | \"\"\"Eine Doku fuer pylauf\"\"\" 110 | ausgabe = [\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \", \" \"] 111 | ausgabe[0] = treffer 112 | if treffer in gruen: 113 | # print \"0, Gruen\" 114 | datei.write(str(spiel[i]) + \"\\n\") 115 | " 116 | 'python-mode 117 | 'py-verbose-p 118 | ;; (font-lock-ensure) 119 | (search-forward "+ \"") 120 | (py-hide-block) 121 | (should (string-match "overlay from 222 to 319" (prin1-to-string (car (overlays-at (point)))))) 122 | (py-show) 123 | (should (not (string-match "overlay" (prin1-to-string (car (overlays-at (point))))))))) 124 | 125 | (ert-deftest py-ert-hide-def-test () 126 | (py-test-point-min " 127 | class kugel(object): 128 | zeit = time.strftime('%Y%m%d--%H-%M-%S') 129 | def pylauf(self): 130 | \"\"\"Eine Doku fuer pylauf\"\"\" 131 | ausgabe = [\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \", \" \"] 132 | ausgabe[0] = treffer 133 | if treffer in gruen: 134 | # print \"0, Gruen\" 135 | datei.write(str(spiel[i]) + \"\\n\") 136 | " 137 | 'python-mode 138 | 'py-verbose-p 139 | ;; (font-lock-ensure) 140 | (search-forward "+ \"") 141 | (py-hide-def) 142 | (should (string-match "overlay from 73 to 319" (prin1-to-string (car (overlays-at (point)))))) 143 | (py-show) 144 | (should (not (string-match "overlay" (prin1-to-string (car (overlays-at (point))))))))) 145 | 146 | (ert-deftest py-ert-hide-class-test () 147 | (py-test-point-min " 148 | class kugel(object): 149 | zeit = time.strftime('%Y%m%d--%H-%M-%S') 150 | def pylauf(self): 151 | \"\"\"Eine Doku fuer pylauf\"\"\" 152 | ausgabe = [\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \", \" \"] 153 | ausgabe[0] = treffer 154 | if treffer in gruen: 155 | # print \"0, Gruen\" 156 | datei.write(str(spiel[i]) + \"\\n\") 157 | " 158 | 'python-mode 159 | 'py-verbose-p 160 | (switch-to-buffer (current-buffer)) 161 | ;; (font-lock-ensure) 162 | (search-forward "+ \"") 163 | (py-hide-class) 164 | (should (string-match "overlay from 2 to 319" (prin1-to-string (car (overlays-at (point)))))) 165 | (py-show) 166 | (should (not (string-match "overlay" (prin1-to-string (car (overlays-at (point))))))))) 167 | 168 | (ert-deftest py-ert-hide-indent-test-dTRpuQ () 169 | (py-test-point-min " 170 | class kugel(object): 171 | zeit = time.strftime('%Y%m%d--%H-%M-%S') 172 | def pylauf(self): 173 | \"\"\"Eine Doku fuer pylauf\"\"\" 174 | ausgabe = [\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \", \" \"] 175 | ausgabe[0] = treffer 176 | if treffer in gruen: 177 | print \"0, Gruen\" 178 | # print \"0, Gruen\" 179 | datei.write(str(spiel[i]) + \"\\n\") 180 | " 181 | 'python-mode 182 | 'py-verbose-p 183 | ;; (font-lock-ensure) 184 | (search-forward "+ \"") 185 | (py-hide-indent) 186 | (should (string-match "overlay from 255 to 348" (prin1-to-string (car (overlays-at (point)))))) 187 | (py-show) 188 | (should (not (string-match "overlay" (prin1-to-string (car (overlays-at (point))))))))) 189 | 190 | (ert-deftest py-ert-hide-block-test-dTRpuQ () 191 | (py-test 192 | "def f(first, second): 193 | if first == 1: 194 | return 11 195 | elif first == 2: 196 | return 22 197 | if second == 12: 198 | return 211 199 | elif second == 22: 200 | return 244 201 | else: 202 | return 25 203 | " 204 | 'python-mode 205 | 'py-verbose-p 206 | (goto-char (point-max)) 207 | (should (search-backward "else")) 208 | (py-hide-block) 209 | (should (string-match "overlay from 109 to 216" (prin1-to-string (car (overlays-at (point)))))))) 210 | 211 | 212 | (provide 'py-ert-hide-tests) 213 | ;;; py-ert-hide-tests.el ends here 214 | -------------------------------------------------------------------------------- /test/py-ert-just-two-split-lp-1361531-tests.el: -------------------------------------------------------------------------------- 1 | ;;; py-ert-just-two-split-lp-1361531-tests.el --- Test splitting 2 | 3 | ;; URL: https://gitlab.com/python-mode-devs 4 | ;; Keywords: languages, convenience 5 | 6 | ;; This program is free software; you can redistribute it and/or modify 7 | ;; it under the terms of the GNU General Public License as published by 8 | ;; the Free Software Foundation, either version 3 of the License, or 9 | ;; (at your option) any later version. 10 | 11 | ;; This program is distributed in the hope that it will be useful, 12 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ;; GNU General Public License for more details. 15 | 16 | ;; You should have received a copy of the GNU General Public License 17 | ;; along with this program. If not, see . 18 | 19 | ;;; Commentary: 20 | 21 | ;; This file is generated by function from python-mode-utils.el - see in 22 | ;; directory devel. Edits here might not be persistent. 23 | 24 | ;;; Code: 25 | 26 | (require 'setup-ert-tests) 27 | 28 | (ert-deftest py-ert-just-two-split-dedicated-lp-1361531-python2-test () 29 | (py-test-with-temp-buffer 30 | "#! /usr/bin/env python2 31 | # -*- coding: utf-8 -*- 32 | print(\"I'm the py-just-two-split-dedicated-lp-1361531-python2-test\")" 33 | (delete-other-windows) 34 | (let* ((py-split-window-on-execute 'just-two) 35 | (erg1 (progn (py-execute-statement-python2-dedicated) py-output-buffer)) 36 | (erg2 (progn (py-execute-statement-python2-dedicated) py-output-buffer))) 37 | (sit-for 1 t) 38 | (when py-debug-p (message "(count-windows) %s" (count-windows))) 39 | (should (eq 2 (count-windows))) 40 | (py-kill-buffer-unconditional erg1) 41 | (py-kill-buffer-unconditional erg2) 42 | (py-restore-window-configuration)))) 43 | 44 | (ert-deftest py-ert-just-two-split-dedicated-lp-1361531-python3-test () 45 | (py-test-with-temp-buffer 46 | "#! /usr/bin/env python3 47 | # -*- coding: utf-8 -*- 48 | print(\"I'm the py-just-two-split-dedicated-lp-1361531-python3-test\")" 49 | (delete-other-windows) 50 | (let* ((py-split-window-on-execute 'just-two) 51 | (erg1 (progn (py-execute-statement-python3-dedicated) py-output-buffer)) 52 | (erg2 (progn (py-execute-statement-python3-dedicated) py-output-buffer))) 53 | (sit-for 1 t) 54 | (when py-debug-p (message "(count-windows) %s" (count-windows))) 55 | (should (eq 2 (count-windows))) 56 | (py-kill-buffer-unconditional erg1) 57 | (py-kill-buffer-unconditional erg2) 58 | (py-restore-window-configuration)))) 59 | 60 | ;; py-ert-just-two-split-lp-1361531-tests.el ends here 61 | (provide 'py-ert-just-two-split-lp-1361531-tests) 62 | -------------------------------------------------------------------------------- /test/py-ert-position-functions-test.el: -------------------------------------------------------------------------------- 1 | ;;; py-ert-position-functions-test.el --- test -*- lexical-binding: t; -*- 2 | 3 | ;; URL: https://gitlab.com/python-mode-devs 4 | ;; Keywords: languages 5 | 6 | ;; This program is free software; you can redistribute it and/or modify 7 | ;; it under the terms of the GNU General Public License as published by 8 | ;; the Free Software Foundation, either version 3 of the License, or 9 | ;; (at your option) any later version. 10 | 11 | ;; This program is distributed in the hope that it will be useful, 12 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ;; GNU General Public License for more details. 15 | 16 | ;; You should have received a copy of the GNU General Public License 17 | ;; along with this program. If not, see . 18 | 19 | ;;; Commentary: 20 | 21 | ;; 22 | 23 | ;;; Code: 24 | 25 | (ert-deftest py-ert--beginning-of-def-position-functionp-test () 26 | (should (functionp 'py--beginning-of-def-position))) 27 | 28 | (ert-deftest py-ert--beginning-of-class-position-functionp-test () 29 | (should (functionp 'py--beginning-of-class-position))) 30 | 31 | (ert-deftest py-ert--beginning-of-def-or-class-position-functionp-test () 32 | (should (functionp 'py--beginning-of-def-or-class-position))) 33 | 34 | (ert-deftest py-ert--beginning-of-expression-position-functionp-test () 35 | (should (functionp 'py--beginning-of-expression-position))) 36 | 37 | (ert-deftest py-ert--beginning-of-partial-expression-position-functionp-test () 38 | (should (functionp 'py--beginning-of-partial-expression-position))) 39 | 40 | (ert-deftest py-ert--beginning-of-minor-block-position-functionp-test () 41 | (should (functionp 'py--beginning-of-minor-block-position))) 42 | 43 | (ert-deftest py-ert--beginning-of-if-block-position-functionp-test () 44 | (should (functionp 'py--beginning-of-if-block-position))) 45 | 46 | (ert-deftest py-ert--beginning-of-try-block-position-functionp-test () 47 | (should (functionp 'py--beginning-of-try-block-position))) 48 | 49 | (ert-deftest py-ert--beginning-of-except-block-position-functionp-test () 50 | (should (functionp 'py--beginning-of-except-block-position))) 51 | 52 | (ert-deftest py-ert--beginning-of-statement-position-bol-functionp-test () 53 | (should (functionp 'py--beginning-of-statement-position-bol))) 54 | 55 | (ert-deftest py-ert--beginning-of-block-position-bol-functionp-test () 56 | (should (functionp 'py--beginning-of-block-position-bol))) 57 | 58 | (ert-deftest py-ert--beginning-of-clause-position-bol-functionp-test () 59 | (should (functionp 'py--beginning-of-clause-position-bol))) 60 | 61 | (ert-deftest py-ert--beginning-of-block-or-clause-position-bol-functionp-test () 62 | (should (functionp 'py--beginning-of-block-or-clause-position-bol))) 63 | 64 | (ert-deftest py-ert--beginning-of-def-position-bol-functionp-test () 65 | (should (functionp 'py--beginning-of-def-position-bol))) 66 | 67 | (ert-deftest py-ert--beginning-of-class-position-bol-functionp-test () 68 | (should (functionp 'py--beginning-of-class-position-bol))) 69 | 70 | (ert-deftest py-ert--beginning-of-def-or-class-position-bol-functionp-test () 71 | (should (functionp 'py--beginning-of-def-or-class-position-bol))) 72 | 73 | (ert-deftest py-ert--beginning-of-minor-block-position-bol-functionp-test () 74 | (should (functionp 'py--beginning-of-minor-block-position-bol))) 75 | 76 | (ert-deftest py-ert--beginning-of-if-block-position-bol-functionp-test () 77 | (should (functionp 'py--beginning-of-if-block-position-bol))) 78 | 79 | (ert-deftest py-ert--beginning-of-try-block-position-bol-functionp-test () 80 | (should (functionp 'py--beginning-of-try-block-position-bol))) 81 | 82 | (ert-deftest py-ert--beginning-of-except-block-position-bol-functionp-test () 83 | (should (functionp 'py--beginning-of-except-block-position-bol))) 84 | 85 | (ert-deftest py-ert--beginning-of-statement-position-functionp-test () 86 | (should (functionp 'py--beginning-of-statement-position))) 87 | 88 | (ert-deftest py-ert--beginning-of-block-position-functionp-test () 89 | (should (functionp 'py--beginning-of-block-position))) 90 | 91 | (ert-deftest py-ert--beginning-of-clause-position-functionp-test () 92 | (should (functionp 'py--beginning-of-clause-position))) 93 | 94 | (ert-deftest py-ert--beginning-of-block-or-clause-position-functionp-test () 95 | (should (functionp 'py--beginning-of-block-or-clause-position))) 96 | 97 | (ert-deftest py-ert--beginning-of-buffer-position-functionp-test () 98 | (should (functionp 'py--beginning-of-buffer-position))) 99 | 100 | (ert-deftest py-ert--beginning-of-comment-position-functionp-test () 101 | (should (functionp 'py--beginning-of-comment-position))) 102 | 103 | (ert-deftest py-ert--end-of-comment-position-functionp-test () 104 | (should (functionp 'py--end-of-comment-position))) 105 | 106 | (ert-deftest py-ert--beginning-of-paragraph-position-functionp-test () 107 | (should (functionp 'py--beginning-of-paragraph-position))) 108 | 109 | (ert-deftest py-ert--end-of-paragraph-position-functionp-test () 110 | (should (functionp 'py--end-of-paragraph-position))) 111 | 112 | (ert-deftest py-ert-end-of-list-position-functionp-test () 113 | (should (functionp 'py-end-of-list-position))) 114 | 115 | (ert-deftest py-ert--end-of-buffer-position-functionp-test () 116 | (should (functionp 'py--end-of-buffer-position))) 117 | 118 | (ert-deftest py-ert-list-beginning-position-functionp-test () 119 | (should (functionp 'py-list-beginning-position))) 120 | 121 | (ert-deftest py-ert--end-of-statement-position-functionp-test () 122 | (should (functionp 'py--end-of-statement-position))) 123 | 124 | (ert-deftest py-ert--end-of-block-position-functionp-test () 125 | (should (functionp 'py--end-of-block-position))) 126 | 127 | (ert-deftest py-ert--end-of-clause-position-functionp-test () 128 | (should (functionp 'py--end-of-clause-position))) 129 | 130 | (ert-deftest py-ert--end-of-block-or-clause-position-functionp-test () 131 | (should (functionp 'py--end-of-block-or-clause-position))) 132 | 133 | (ert-deftest py-ert--end-of-def-position-functionp-test () 134 | (should (functionp 'py--end-of-def-position))) 135 | 136 | (ert-deftest py-ert--end-of-class-position-functionp-test () 137 | (should (functionp 'py--end-of-class-position))) 138 | 139 | (ert-deftest py-ert--end-of-def-or-class-position-functionp-test () 140 | (should (functionp 'py--end-of-def-or-class-position))) 141 | 142 | (ert-deftest py-ert--end-of-buffer-position-functionp-test () 143 | (should (functionp 'py--end-of-buffer-position))) 144 | 145 | (ert-deftest py-ert--end-of-expression-position-functionp-test () 146 | (should (functionp 'py--end-of-expression-position))) 147 | 148 | (ert-deftest py-ert--end-of-partial-expression-position-functionp-test () 149 | (should (functionp 'py--end-of-partial-expression-position))) 150 | 151 | (ert-deftest py-ert--end-of-minor-block-position-functionp-test () 152 | (should (functionp 'py--end-of-minor-block-position))) 153 | 154 | (ert-deftest py-ert--end-of-if-block-position-functionp-test () 155 | (should (functionp 'py--end-of-if-block-position))) 156 | 157 | (ert-deftest py-ert--end-of-try-block-position-functionp-test () 158 | (should (functionp 'py--end-of-try-block-position))) 159 | 160 | (ert-deftest py-ert--end-of-except-block-position-functionp-test () 161 | (should (functionp 'py--end-of-except-block-position))) 162 | 163 | (ert-deftest py-ert--end-of-top-level-position-functionp-test () 164 | (should (functionp 'py--end-of-top-level-position))) 165 | 166 | (ert-deftest py-ert--end-of-statement-position-bol-functionp-test () 167 | (should (functionp 'py--end-of-statement-position-bol))) 168 | 169 | (ert-deftest py-ert--end-of-block-position-bol-functionp-test () 170 | (should (functionp 'py--end-of-block-position-bol))) 171 | 172 | (ert-deftest py-ert--end-of-clause-position-bol-functionp-test () 173 | (should (functionp 'py--end-of-clause-position-bol))) 174 | 175 | (ert-deftest py-ert--end-of-block-or-clause-position-bol-functionp-test () 176 | (should (functionp 'py--end-of-block-or-clause-position-bol))) 177 | 178 | (ert-deftest py-ert--end-of-def-position-bol-functionp-test () 179 | (should (functionp 'py--end-of-def-position-bol))) 180 | 181 | (ert-deftest py-ert--end-of-class-position-bol-functionp-test () 182 | (should (functionp 'py--end-of-class-position-bol))) 183 | 184 | (ert-deftest py-ert--end-of-minor-block-position-bol-functionp-test () 185 | (should (functionp 'py--end-of-minor-block-position-bol))) 186 | 187 | (ert-deftest py-ert--end-of-if-block-position-bol-functionp-test () 188 | (should (functionp 'py--end-of-if-block-position-bol))) 189 | 190 | (ert-deftest py-ert--end-of-try-block-position-bol-functionp-test () 191 | (should (functionp 'py--end-of-try-block-position-bol))) 192 | 193 | (ert-deftest py-ert-kill-block-functionp-test () 194 | (should (functionp 'py-kill-block))) 195 | 196 | (provide 'py-ert-position-functions-test) 197 | ;;; py-ert-position-functions-test.el ends here 198 | -------------------------------------------------------------------------------- /test/py-executable-python-tests.el: -------------------------------------------------------------------------------- 1 | ;; py-executable-python-tests.el --- testing python-mode.el -*- lexical-binding: t; -*- 2 | 3 | ;; Keywords: languages 4 | 5 | ;; GNU Emacs is free software: you can redistribute it and/or modify 6 | ;; it under the terms of the GNU General Public License as published by 7 | ;; the Free Software Foundation, either version 3 of the License, or 8 | ;; (at your option) any later version. 9 | 10 | ;; GNU Emacs is distributed in the hope that it will be useful, 11 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ;; GNU General Public License for more details. 14 | 15 | ;; You should have received a copy of the GNU General Public License 16 | ;; along with GNU Emacs. If not, see . 17 | 18 | ;;; Commentary: 19 | 20 | ;;; Code: 21 | 22 | (require 'py-setup-ert-tests) 23 | 24 | (ert-deftest py-dedicated-shell-test-7tw0PH () 25 | "" 26 | 'python-mode 27 | 'py-verbose-p 28 | (if (not (ignore-errors (executable-find "python"))) 29 | (message "py-dedicated-shell-test-7tw0PH: %s" "No python executable found!") 30 | (let ((erg (buffer-name (py-shell nil nil t "python")))) 31 | (should (< 8 (length erg))) 32 | (should (eq 0 (string-match "^*Python" erg)))))) 33 | 34 | (ert-deftest py-shell-python-lp-1398530-test-Haizw1 () 35 | "" 36 | 'python-mode 37 | 'py-verbose-p 38 | (if (not (executable-find "python" 39 | )) 40 | (message "py-shell-python-lp-1398530-test-Haizw1: %s" "No python executable found!") 41 | (when (buffer-live-p (get-buffer "*Python*")) 42 | (py-kill-buffer-unconditional "*Python*")) 43 | (py-test 44 | "" 45 | (when py-debug-p (switch-to-buffer (current-buffer))) 46 | (let ((py-shell-name "python")) 47 | (py-shell) 48 | (sit-for 0.1 t) 49 | (should (buffer-live-p (get-buffer "*Python*"))))))) 50 | 51 | (ert-deftest py-shell-python3-lp-1398530-test-gm7LwH () 52 | (py-test 53 | "" 54 | 'python-mode 55 | 'py-verbose-p 56 | (if (not (executable-find "python3")) 57 | (message "py-shell-python3-lp-1398530-test-gm7LwH: %s" "No python3 executable found!") 58 | (when (buffer-live-p (get-buffer "*Python3*")) 59 | (py-kill-buffer-unconditional "*Python3*")) 60 | (let ((py-shell-name "python3")) 61 | (py-shell) 62 | (sit-for 0.1 t) 63 | (should (buffer-live-p (get-buffer "*Python3*"))))))) 64 | 65 | (ert-deftest py-python-mode-v5-behavior-test-bSPpqY () 66 | "" 67 | 'python-mode 68 | 'py-verbose-p 69 | (let ((python-mode-v5-behavior-p t)) 70 | (python3) 71 | (sit-for 0.1) 72 | (should (buffer-live-p (get-buffer "*Python Output*"))) 73 | (py-kill-buffer-unconditional "*Python Output*"))) 74 | 75 | (ert-deftest py-python-mode-v5-behavior-test-2n0wbL () 76 | "" 77 | 'python-mode 78 | 'py-verbose-p 79 | (when (buffer-live-p (get-buffer "*Python Output*")) 80 | (py-kill-buffer-unconditional "*Python Output*")) 81 | (let ((python-mode-v5-behavior-p t)) 82 | (py-execute-string "asdf") 83 | (sit-for 0.1) 84 | (should (buffer-live-p (get-buffer "*Python Output*"))) 85 | (py-kill-buffer-unconditional "*Python Output*"))) 86 | 87 | (provide 'py-executable-python-tests) 88 | ;;; py-executable-python-tests.el ends here 89 | -------------------------------------------------------------------------------- /test/py-execute-region-commandp-test.el: -------------------------------------------------------------------------------- 1 | ;;; py-execute-region-commandp-test.el --- Test execute region forms -*- lexical-binding: t; -*- 2 | 3 | ;; URL: https://gitlab.com/python-mode-devs 4 | ;; Keywords: languages, convenience 5 | 6 | ;; This program is free software; you can redistribute it and/or modify 7 | ;; it under the terms of the GNU General Public License as published by 8 | ;; the Free Software Foundation, either version 3 of the License, or 9 | ;; (at your option) any later version. 10 | 11 | ;; This program is distributed in the hope that it will be useful, 12 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ;; GNU General Public License for more details. 15 | 16 | ;; You should have received a copy of the GNU General Public License 17 | ;; along with this program. If not, see . 18 | 19 | ;;; Commentary: 20 | 21 | ;; This file is generated by function from python-mode-utils.el - see in 22 | ;; directory devel. Edits here might not be persistent. 23 | 24 | ;;; Code: 25 | 26 | (ert-deftest py-execute-region-commandp-test-g4jSXk () 27 | (should (commandp 'py-execute-region))) 28 | 29 | (ert-deftest py-execute-region-dedicated-commandp-test-xjNPtU () 30 | (should (commandp 'py-execute-region-dedicated))) 31 | 32 | (ert-deftest py-ert-execute-region-python-commandp-test-mzriCL () 33 | (should (commandp 'py-execute-region-python))) 34 | 35 | (ert-deftest py-ert-execute-region-python-dedicated-commandp-test-n2l8Rk () 36 | (should (commandp 'py-execute-region-python-dedicated))) 37 | 38 | (ert-deftest py-ert-execute-region-python2-commandp-test-Yu8rSb () 39 | (should (commandp 'py-execute-region-python2))) 40 | 41 | (ert-deftest py-ert-execute-region-python2-dedicated-commandp-test-5IZGJK () 42 | (should (commandp 'py-execute-region-python2-dedicated))) 43 | 44 | (ert-deftest py-ert-execute-region-python3-commandp-test-YUa0DB () 45 | (should (commandp 'py-execute-region-python3))) 46 | 47 | (ert-deftest py-ert-execute-region-python3-dedicated-commandp-test-r8bz99 () 48 | (should (commandp 'py-execute-region-python3-dedicated))) 49 | 50 | (ert-deftest py-ert-execute-region-ipython-commandp-test-i3uGX0 () 51 | (should (commandp 'py-execute-region-ipython))) 52 | 53 | (ert-deftest py-ert-execute-region-ipython-dedicated-commandp-test-buWchz () 54 | (should (commandp 'py-execute-region-ipython-dedicated))) 55 | 56 | (ert-deftest py-ert-execute-region-ipython3-commandp-test-2yrvuU () 57 | (should (commandp 'py-execute-region-ipython3))) 58 | 59 | (ert-deftest py-ert-execute-region-ipython3-dedicated-commandp-test-VzBZLv () 60 | (should (commandp 'py-execute-region-ipython3-dedicated))) 61 | 62 | (ert-deftest py-ert-execute-region-jython-commandp-test-8HNOqn () 63 | (should (commandp 'py-execute-region-jython))) 64 | 65 | (ert-deftest py-ert-execute-region-jython-dedicated-commandp-test-HKVyeY () 66 | (should (commandp 'py-execute-region-jython-dedicated))) 67 | 68 | (provide 'py-execute-region-commandp-test) 69 | ;;; py-execute-region-commandp-test.el ends here 70 | -------------------------------------------------------------------------------- /test/py-interactive-tests.el: -------------------------------------------------------------------------------- 1 | ;;; py-interactive-tests.el --- Tests expected to succeed interactively -*- lexical-binding: t; -*- 2 | 3 | ;; Copyright (C) 2015 Andreas Röhler 4 | 5 | ;; Author: Andreas Röhler 6 | ;; Keywords: lisp 7 | 8 | ;; This program is free software; you can redistribute it and/or modify 9 | ;; it under the terms of the GNU General Public License as published by 10 | ;; the Free Software Foundation, either version 3 of the License, or 11 | ;; (at your option) any later version. 12 | 13 | ;; This program is distributed in the hope that it will be useful, 14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ;; GNU General Public License for more details. 17 | 18 | ;; You should have received a copy of the GNU General Public License 19 | ;; along with this program. If not, see . 20 | 21 | ;;; Commentary: 22 | 23 | ;; 24 | 25 | ;;; Code: 26 | 27 | (defun py-shell-complete-test (&optional arg load-branch-function) 28 | (interactive "p") 29 | (let ((teststring (concat py-test-shebang " 30 | # -*- coding: utf-8 -*- 31 | impo"))) 32 | (py-bug-tests-intern 'py-shell-complete-base arg teststring))) 33 | 34 | (defun py-shell-complete-base () 35 | (when (and (interactive-p) py-debug-p) (switch-to-buffer (current-buffer)) 36 | (font-lock-fontify-buffer)) 37 | (sit-for 0.1 t) 38 | (py-shell-complete) 39 | (sit-for 0.1) 40 | (assert (looking-back "import") nil "py-shell-complete-test failed")) 41 | 42 | (ert-deftest py-ert-execute-statement-fast-1 () 43 | (py-test-with-temp-buffer-point-min 44 | "print(1)" 45 | (let ((py-fast-process-p t) 46 | (py-return-result-p t) 47 | py-result py-store-result-p) 48 | (py-execute-statement) 49 | (should (string= "1" py-result))))) 50 | 51 | (ert-deftest py-ert-execute-statement-fast-2 () 52 | (py-test-with-temp-buffer-point-min 53 | "print(2)" 54 | (let ((py-fast-process-p t) 55 | (py-return-result-p t) 56 | py-result py-store-result-p) 57 | (py-execute-statement-fast) 58 | (should (string= "2" py-result))))) 59 | 60 | (ert-deftest py-ert-fast-complete-1 () 61 | (py-test-with-temp-buffer 62 | "obj" 63 | (let ((py-return-result-p t) 64 | py-result py-store-result-p) 65 | (when py-debug-p (switch-to-buffer (current-buffer))) 66 | (py-fast-complete) 67 | (should (eq (char-before) 40))))) 68 | 69 | (ert-deftest py-shell-complete-in-dedicated-shell () 70 | (let (erg 71 | ;; py-split-window-on-execute 72 | py-switch-buffers-on-execute-p) 73 | (with-temp-buffer 74 | (python-mode) 75 | (setq erg (python-dedicated)) 76 | (with-current-buffer erg 77 | (goto-char (point-max)) 78 | ;; (when py-debug-p (switch-to-buffer (current-buffer))) 79 | ;; (switch-to-buffer (current-buffer)) 80 | (insert "pri") 81 | (sit-for 1 t) 82 | (call-interactively 'py-indent-or-complete) 83 | (sit-for 0.1 t) 84 | (should (or (eq 40 (char-before)) 85 | ;; python may just offer print( 86 | (buffer-live-p (get-buffer "*Python Completions*")))) 87 | (py-kill-buffer-unconditional erg))))) 88 | 89 | (provide 'py-interactive-tests) 90 | ;;; py-interactive-tests.el ends here 91 | -------------------------------------------------------------------------------- /test/py-non-travis-tests.el: -------------------------------------------------------------------------------- 1 | ;;; py-non-travis-tests.el --- non-travis tests 2 | 3 | 4 | ;; URL: https://gitlab.com/python-mode-devs 5 | 6 | ;; Keywords: lisp 7 | 8 | ;; This program is free software; you can redistribute it and/or modify 9 | ;; it under the terms of the GNU General Public License as published by 10 | ;; the Free Software Foundation, either version 3 of the License, or 11 | ;; (at your option) any later version. 12 | 13 | ;; This program is distributed in the hope that it will be useful, 14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ;; GNU General Public License for more details. 17 | 18 | ;; You should have received a copy of the GNU General Public License 19 | ;; along with this program. If not, see . 20 | 21 | ;;; Commentary: 22 | 23 | ;; 24 | 25 | ;;; Code: 26 | 27 | (ert-deftest py-complete-in-ipython-shell-test () 28 | (let ((py-shell-name "ipython") 29 | ;; (py-switch-buffers-on-execute-p t) 30 | ) 31 | (py-kill-buffer-unconditional "*IPython*") 32 | (ipython) 33 | (goto-char (point-max)) 34 | (insert "pri") 35 | (py-indent-or-complete) 36 | (forward-word -1) 37 | (should (eq ?p (char-after))))) 38 | 39 | (ert-deftest py-ert-script-buffer-appears-instead-of-python-shell-buffer-lp-957561-test () 40 | (py-test 41 | "#! /usr/bin/env python 42 | # -*- coding: utf-8 -*- 43 | print(\"I'm the script-buffer-appears-instead-of-python-shell-buffer-lp-957561-test\") 44 | " 45 | (let (py-switch-buffers-on-execute-p 46 | (py-split-window-on-execute t)) 47 | (delete-other-windows) 48 | (ipython) 49 | (sit-for 0.1) 50 | (py-execute-buffer-ipython) 51 | ;; (should (window-live-p (other-buffer))) 52 | (should (not (window-full-height-p)))))) 53 | 54 | (ert-deftest py-ert-socket-modul-completion-lp-1284141 () 55 | (dolist (ele py-ert-test-default-executables) 56 | (when (buffer-live-p (get-buffer "*Python Completions*")) 57 | (py-kill-buffer-unconditional (get-buffer "*Python Completions*"))) 58 | (py-test 59 | "import socket\nsocket." 60 | (let ((py-debug-p t) 61 | (py-shell-name ele) 62 | oldbuf) 63 | (when py-debug-p (switch-to-buffer (current-buffer)) 64 | (font-lock-ensure)) 65 | (py-indent-or-complete) 66 | (if (string-match "ipython" ele) 67 | (sit-for 0.5) 68 | (sit-for 0.1)) 69 | (should (buffer-live-p (get-buffer "*Python Completions*"))) 70 | (set-buffer "*Python Completions*") 71 | (switch-to-buffer (current-buffer)) 72 | (goto-char (point-min)) 73 | (sit-for 0.1) 74 | (prog1 (should (search-forward "socket.")) 75 | (py-kill-buffer-unconditional (current-buffer))))))) 76 | 77 | (provide 'py-non-travis-tests) 78 | ;;; py-non-travis-tests.el ends here 79 | -------------------------------------------------------------------------------- /test/py-setup-ert-tests.el: -------------------------------------------------------------------------------- 1 | ;;; py-setup-ert-tests.el --- Provide needed forms -*- lexical-binding: t; -*- 2 | 3 | ;; URL: https://gitlab.com/python-mode-devs 4 | ;; Keywords: lisp 5 | 6 | ;; This program is free software; you can redistribute it and/or modify 7 | ;; it under the terms of the GNU General Public License as published by 8 | ;; the Free Software Foundation, either version 3 of the License, or 9 | ;; (at your option) any later version. 10 | 11 | ;; This program is distributed in the hope that it will be useful, 12 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ;; GNU General Public License for more details. 15 | 16 | ;; You should have received a copy of the GNU General Public License 17 | ;; along with this program. If not, see . 18 | 19 | ;;; Commentary: 20 | 21 | ;;; Code: 22 | 23 | ;; (require 'org) 24 | 25 | ;; (setq py-debug-p t) 26 | 27 | (if (file-readable-p "../python-components-mode.el") 28 | (load (expand-file-name "../python-components-mode.el") nil t) 29 | (when (file-readable-p "../python-mode.el") 30 | (load (expand-file-name "../python-mode.el") nil t))) 31 | 32 | (require 'font-lock) 33 | 34 | 35 | (unless (functionp 'ar-syntax-class-atpt) 36 | (defun ar-syntax-class-atpt (&optional pos) 37 | "Return the syntax class part of the syntax at point. " 38 | (interactive "p") 39 | (let* ((pos (or pos (point))) 40 | (erg (logand (car (syntax-after pos)) 65535))) 41 | (when erg (message "%s" erg)) erg))) 42 | 43 | (unless (functionp 'ar-syntax-atpt) 44 | (defun ar-syntax-atpt (&optional arg docu pos) 45 | (interactive "p") 46 | (when pos 47 | (goto-char pos)) 48 | (let* ((elt (car (if (featurep 'xemacs) 49 | (char-syntax (char-after)) 50 | (syntax-after (point))))) 51 | (stax (cond ((eq elt 0) "0 whitespace") 52 | ((eq elt 5) "5 close parenthesis") 53 | ((eq elt 10) "10 character quote") 54 | ((eq elt 1) "1 punctuation") 55 | ((eq elt 6) "6 expression prefix") 56 | ((eq elt 11) "11 comment-start") 57 | ((eq elt 2) "2 word") 58 | ((eq elt 7) "7 string quote") 59 | ((eq elt 12) "12 comment-end") 60 | ((eq elt 3) "3 symbol") 61 | ((eq elt 8) "8 paired delimiter") 62 | ((eq elt 13) "13 inherit") 63 | ((eq elt 4) "4 open parenthesis") 64 | ((eq elt 9) "9 escape") 65 | ((eq elt 14) "14 generic comment") 66 | ((eq elt 15) "15 generic string")))) 67 | (when arg 68 | (message (format "%s" stax))) 69 | (if docu 70 | (format "%s" stax) 71 | elt)))) 72 | 73 | (defmacro py-test (contents mode verbose &rest body) 74 | "Create temp buffer inserting CONTENTS. 75 | 76 | BODY is code to be executed within the temp buffer " 77 | (declare (indent 1) (debug t)) 78 | `(with-temp-buffer 79 | (let (hs-minor-mode py--imenu-create-index-p) 80 | (insert ,contents) 81 | (funcall ,mode) 82 | (when ,verbose 83 | (switch-to-buffer (current-buffer)) 84 | (font-lock-fontify-region (point-min)(point-max))) 85 | ,@body))) 86 | 87 | (defmacro py-test-point-min (contents mode verbose &rest body) 88 | "Create temp buffer inserting CONTENTS. 89 | BODY is code to be executed within the temp buffer. Point is 90 | at the beginning of buffer." 91 | (declare (debug t)) 92 | `(with-temp-buffer 93 | (let (hs-minor-mode py--imenu-create-index-p) 94 | (insert ,contents) 95 | (funcall ,mode) 96 | (goto-char (point-min)) 97 | (and ,verbose 98 | (switch-to-buffer (current-buffer)) 99 | (font-lock-fontify-region (point-min)(point-max))) 100 | ,@body))) 101 | 102 | (defmacro py-test-with-temp-buffer (contents &rest body) 103 | "Create temp buffer in `python-mode' inserting CONTENTS. 104 | BODY is code to be executed within the temp buffer. Point is 105 | at the end of buffer." 106 | (declare (indent 1) (debug t)) 107 | `(with-temp-buffer 108 | (let ( 109 | ;; (python-indend-offset 4) 110 | python-indent-guess-indent-offset 111 | hs-minor-mode py--imenu-create-index-p) 112 | ;; (and (featurep 'python) (unload-feature 'python)) 113 | (insert ,contents) 114 | (python-mode) 115 | (when py-debug-p 116 | ;; (message "py-python-edit-version: %s" py-python-edit-version) 117 | (switch-to-buffer (current-buffer)) 118 | (font-lock-fontify-region (point-min) (point-max))) 119 | ,@body))) 120 | 121 | (defmacro py-test-with-temp-buffer-point-min (contents &rest body) 122 | "Create temp buffer in `python-mode' inserting CONTENTS. 123 | BODY is code to be executed within the temp buffer. Point is 124 | at the beginning of buffer." 125 | (declare (indent 1) (debug t)) 126 | `(with-temp-buffer 127 | (let ( 128 | ;; (python-indent-offset 4) 129 | python-indent-guess-indent-offset 130 | hs-minor-mode py--imenu-create-index-p) 131 | (python-mode) 132 | (insert ,contents) 133 | (goto-char (point-min)) 134 | (when py-debug-p 135 | (switch-to-buffer (current-buffer)) 136 | (font-lock-fontify-region (point-min) (point-max))) 137 | ,@body))) 138 | 139 | ;; from jit-lock.el 140 | (defmacro with-buffer-prepared-for-jit-lock (&rest body) 141 | "Execute BODY in current buffer, overriding several variables. 142 | Preserves the `buffer-modified-p' state of the current buffer." 143 | (declare (debug t)) 144 | `(let ((inhibit-point-motion-hooks t)) 145 | (with-silent-modifications 146 | ,@body))) 147 | 148 | (defmacro py-test-mode-explizit (contents mode debug &rest body) 149 | "Create temp buffer inserting CONTENTS. 150 | 151 | BODY is code to be executed within the temp buffer " 152 | (declare (indent 1) (debug t)) 153 | `(with-temp-buffer 154 | (let (hs-minor-mode) 155 | (funcall ,mode) 156 | (insert ,contents) 157 | (when ,debug 158 | (switch-to-buffer (current-buffer)) 159 | (save-excursion (font-lock-fontify-region (point-min)(point-max))) 160 | ,@body)) 161 | ;; (sit-for 0.1) 162 | )) 163 | 164 | (defmacro py-test-mode-explizit-point-min (contents mode debug &rest body) 165 | "Create temp buffer inserting CONTENTS. 166 | BODY is code to be executed within the temp buffer. Point is 167 | at the beginning of buffer." 168 | (declare (indent 1) (debug t)) 169 | `(with-temp-buffer 170 | (let (hs-minor-mode) 171 | (funcall ,mode) 172 | (insert ,contents) 173 | (goto-char (point-min)) 174 | (when ,debug 175 | (switch-to-buffer (current-buffer)) 176 | (save-excursion (font-lock-fontify-region (point-min)(point-max)))) 177 | ,@body))) 178 | 179 | (provide 'py-setup-ert-tests) 180 | ;; py-setup-ert-tests.el ends here 181 | -------------------------------------------------------------------------------- /test/py-shell-arg-ert-tests.el: -------------------------------------------------------------------------------- 1 | ;;; py-shell-arg-ert-tests.el --- py-shell ert tests -*- lexical-binding: t; -*- 2 | 3 | ;; URL: https://gitlab.com/python-mode-devs 4 | ;; Keywords: languages, convenience 5 | 6 | ;; This program is free software; you can redistribute it and/or modify 7 | ;; it under the terms of the GNU General Public License as published by 8 | ;; the Free Software Foundation, either version 3 of the License, or 9 | ;; (at your option) any later version. 10 | 11 | ;; This program is distributed in the hope that it will be useful, 12 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ;; GNU General Public License for more details. 15 | 16 | ;; You should have received a copy of the GNU General Public License 17 | ;; along with this program. If not, see . 18 | 19 | ;;; Commentary: 20 | 21 | ;; This file is generated by function from python-mode-utils.el - see in 22 | ;; directory devel. Edits here might not be persistent. 23 | 24 | ;;; Code: 25 | 26 | (ert-deftest py-ert-python-shell-test () 27 | (let ((py-python-command-args (list "-i -c\"abc=4\""))) 28 | (py-kill-buffer-unconditional "*Python*") 29 | (python) 30 | (should (buffer-live-p (get-buffer "*Python*"))) 31 | (set-buffer (get-buffer "*Python*")) 32 | (should (string= "4" py-result)) 33 | (should (< 1 comint-last-input-end)))) 34 | 35 | (ert-deftest py-ert-python2-shell-test () 36 | (let ((py-python2-command-args (list "-i -c\"abc=4\""))) 37 | (py-kill-buffer-unconditional "*Python2*") 38 | (python2) 39 | (should (buffer-live-p (get-buffer "*Python2*"))) 40 | (set-buffer (get-buffer "*Python2*")) 41 | (should (string= "4" py-result)) 42 | (should (< 1 comint-last-input-end)))) 43 | 44 | (ert-deftest py-ert-python3-shell-test () 45 | (let ((py-python3-command-args (list "-i -c\"abc=4\""))) 46 | (py-kill-buffer-unconditional "*Python3*") 47 | (python3) 48 | (should (buffer-live-p (get-buffer "*Python3*"))) 49 | (set-buffer (get-buffer "*Python3*")) 50 | (should (string= "4" py-result)) 51 | (should (< 1 comint-last-input-end)))) 52 | 53 | (ert-deftest py-ert-ipython-shell-test () 54 | (let ((py-ipython-command-args (list "-i -c\"abc=4\""))) 55 | (py-kill-buffer-unconditional "*IPython*") 56 | (ipython) 57 | (should (buffer-live-p (get-buffer "*IPython*"))) 58 | (set-buffer (get-buffer "*IPython*")) 59 | (should (string= "4" py-result)) 60 | (should (< 1 comint-last-input-end)))) 61 | 62 | (ert-deftest py-ert-ipython2-shell-test () 63 | (let ((py-ipython2-command-args (list "-i -c\"abc=4\""))) 64 | (py-kill-buffer-unconditional "*IPython2*") 65 | (ipython2) 66 | (should (buffer-live-p (get-buffer "*IPython2*"))) 67 | (set-buffer (get-buffer "*IPython2*")) 68 | (should (string= "4" py-result)) 69 | (should (< 1 comint-last-input-end)))) 70 | 71 | (ert-deftest py-ert-ipython3-shell-test () 72 | (let ((py-ipython3-command-args (list "-i -c\"abc=4\""))) 73 | (py-kill-buffer-unconditional "*IPython3*") 74 | (ipython3) 75 | (should (buffer-live-p (get-buffer "*IPython3*"))) 76 | (set-buffer (get-buffer "*IPython3*")) 77 | (should (string= "4" py-result)) 78 | (should (< 1 comint-last-input-end)))) 79 | 80 | (ert-deftest py-ert-jython-shell-test () 81 | (let ((py-jython-command-args (list "-i -c\"abc=4\""))) 82 | (py-kill-buffer-unconditional "*Jython*") 83 | (jython) 84 | (should (buffer-live-p (get-buffer "*Jython*"))) 85 | (set-buffer (get-buffer "*Jython*")) 86 | (should (string= "4" py-result)) 87 | (should (< 1 comint-last-input-end)))) 88 | 89 | (provide 'py-shell-arg-ert-tests) 90 | ;;; py-shell-arg-ert-tests.el ends here 91 | 92 | -------------------------------------------------------------------------------- /test/py-shell-completion-tests.el: -------------------------------------------------------------------------------- 1 | ;;; py-shell-completion-tests.el --- Test completion for available Python shell 2 | 3 | ;; URL: https://gitlab.com/python-mode-devs 4 | ;; Keywords: languages 5 | 6 | ;; This program is free software; you can redistribute it and/or modify 7 | ;; it under the terms of the GNU General Public License as published by 8 | ;; the Free Software Foundation, either version 3 of the License, or 9 | ;; (at your option) any later version. 10 | 11 | ;; This program is distributed in the hope that it will be useful, 12 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ;; GNU General Public License for more details. 15 | 16 | ;; You should have received a copy of the GNU General Public License 17 | ;; along with this program. If not, see . 18 | 19 | ;;; Commentary: Edit `py-test-pyshellname-list' before 20 | ;; running this test-builder or give a list of shells as 21 | ;; arguments 22 | 23 | ;;; Code: 24 | 25 | (defun python-shell-complete-test () 26 | (interactive) 27 | (let (py-switch-buffers-on-execute-p 28 | py-split-window-on-execute) 29 | (py-test (py-shell nil nil t "python") 30 | (sit-for 0.1 t) 31 | (when (called-interactively-p 'interactive) 32 | (switch-to-buffer (current-buffer))) 33 | ;; (goto-char (point-max)) 34 | (sit-for 0.1 t) 35 | (goto-char (or (and (boundp 'comint-last-prompt)(cdr comint-last-prompt)) (point-max))) 36 | (sit-for 0.2 t) 37 | ;; (goto-char (point-max)) 38 | (insert "pri") 39 | (py-shell-complete) 40 | (sit-for 0.2 t) 41 | (assert (member (char-before) (list ?\( ?t)) nil "python-shell-complete-test failed")))) 42 | 43 | (defun python2.7-shell-complete-test () 44 | (interactive) 45 | (let (py-switch-buffers-on-execute-p 46 | py-split-window-on-execute) 47 | (set-buffer (py-shell nil nil t "python2.7")) 48 | (when (called-interactively-p 'interactive) 49 | (switch-to-buffer (current-buffer))) 50 | (sit-for 0.1) 51 | (goto-char (point-max)) 52 | (insert "pri") 53 | (py-shell-complete) 54 | (forward-word -1) 55 | (assert (looking-at "print") nil "python2.7-shell-complete-test failed") 56 | (message "%s" "python2.7-shell-complete-test passed"))) 57 | 58 | 59 | (defun arbeit-python-epdfree-epd_free-7.2-2-rh5-x86-bin-python2.7-shell-complete-test () 60 | (interactive) 61 | (let (py-switch-buffers-on-execute-p 62 | py-split-window-on-execute) 63 | (set-buffer (py-shell nil nil t "~/arbeit/python/epdfree/epd_free-7.2-2-rh5-x86/bin/python2.7")) 64 | (sit-for 0.2 t) 65 | (goto-char (point-max)) 66 | (insert "pri") 67 | (py-shell-complete) 68 | (sit-for 0.1) 69 | (forward-word -1) 70 | (assert (looking-at "print") nil "arbeit-python-epdfree-epd_free-7.2-2-rh5-x86-bin-python2.7-shell-complete-test failed") 71 | (when py-verbose-p (message "%s" "arbeit-python-epdfree-epd_free-7.2-2-rh5-x86-bin-python2.7-shell-complete-test passed")))) 72 | 73 | (defun python3-shell-complete-test () 74 | (interactive) 75 | (let (py-switch-buffers-on-execute-p 76 | py-split-window-on-execute) 77 | (set-buffer (py-shell nil nil t "python3")) 78 | (when (called-interactively-p 'interactive) 79 | (switch-to-buffer (current-buffer))) 80 | (goto-char (point-max)) 81 | (insert "pri") 82 | (py-shell-complete) 83 | (forward-word -1) 84 | (sit-for 0.1) 85 | (assert (looking-at "print") nil "python3-shell-complete-test failed") 86 | (message "%s" "python3-shell-complete-test passed"))) 87 | 88 | (defun ipython-shell-complete-test () 89 | (interactive) 90 | (let (py-switch-buffers-on-execute-p 91 | py-split-window-on-execute) 92 | (and (buffer-live-p (get-buffer "*Ipython*")) 93 | (kill-buffer-unconditional "*Ipython*")) 94 | (set-buffer (py-shell nil nil t "ipython")) 95 | (switch-to-buffer (current-buffer)) 96 | (sit-for 0.1) 97 | (goto-char (point-max)) 98 | ;; (comint-send-input) 99 | (insert "pri") 100 | 101 | (py-shell-complete) 102 | (sit-for 0.1) 103 | (assert (looking-back "print") nil "ipython-shell-complete-test failed") 104 | (message "%s" "ipython-shell-complete-test passed"))) 105 | 106 | 107 | (defun ipython-shell-complete-test () 108 | (interactive) 109 | (let (py-switch-buffers-on-execute-p 110 | py-split-window-on-execute) 111 | (set-buffer (py-shell nil nil t "/usr/bin/ipython")) 112 | (sit-for 0.1) 113 | (goto-char (point-max)) 114 | (insert "pri") 115 | (py-shell-complete) 116 | (sit-for 0.1 t) 117 | (forward-word -1) 118 | (assert (looking-at "print") nil "ipython-shell-complete-test failed") 119 | (message "%s" "ipython-shell-complete-test passed"))) 120 | 121 | 122 | (defun arbeit-python-epd_free-7.1-2-rh5-x86-bin-ipython-shell-complete-test () 123 | (interactive) 124 | (let (py-switch-buffers-on-execute-p 125 | py-split-window-on-execute) 126 | (set-buffer (py-shell nil nil t "~/arbeit/python/epd_free-7.1-2-rh5-x86/bin/ipython")) 127 | (sit-for 0.1) 128 | (switch-to-buffer (current-buffer)) 129 | (goto-char (point-max)) 130 | (insert "pri") 131 | (py-shell-complete) 132 | (sit-for 0.1 t) 133 | (forward-word -1) 134 | (assert (looking-at "print") nil "arbeit-python-epd_free-7.1-2-rh5-x86-bin-ipython-shell-complete-test failed") 135 | (message "%s" "arbeit-python-epd_free-7.1-2-rh5-x86-bin-ipython-shell-complete-test passed"))) 136 | 137 | 138 | 139 | (provide 'py-shell-completion-tests) 140 | ;;; py-shell-completion-tests ends here 141 | -------------------------------------------------------------------------------- /test/py-shell-ert-tests.el: -------------------------------------------------------------------------------- 1 | ;;; py-shell-ert-tests.el --- py-shell ert tests 2 | 3 | ;; Copyright (C) 2015 Andreas Roehler 4 | ;; Author: Andreas Roehler 5 | ;; Keywords: languages, convenience 6 | 7 | ;; This program is free software; you can redistribute it and/or modify 8 | ;; it under the terms of the GNU General Public License as published by 9 | ;; the Free Software Foundation, either version 3 of the License, or 10 | ;; (at your option) any later version. 11 | 12 | ;; This program is distributed in the hope that it will be useful, 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ;; GNU General Public License for more details. 16 | 17 | ;; You should have received a copy of the GNU General Public License 18 | ;; along with this program. If not, see . 19 | 20 | ;;; Commentary: 21 | 22 | ;; This file is generated by function from python-mode-utils.el - see in 23 | ;; directory devel. Edits here might not be persistent. 24 | 25 | ;;; Code: 26 | 27 | (ert-deftest py-ert-python-shell-test () 28 | (let ((py-python-command-args (list "-i -c\"abc=4\"")) 29 | (py-store-result-p t)) 30 | (py-kill-buffer-unconditional "*Python*") 31 | (python) 32 | (should (buffer-live-p (get-buffer "*Python*"))) 33 | (set-buffer (get-buffer "*Python*")) 34 | (should (string= "4" py-result)) 35 | (should (< 1 comint-last-input-end)))) 36 | 37 | (ert-deftest py-ert-python2-shell-test () 38 | (let ((py-python2-command-args (list "-i -c\"abc=4\""))) 39 | (py-kill-buffer-unconditional "*Python2*") 40 | (python2) 41 | (should (buffer-live-p (get-buffer "*Python2*"))) 42 | (set-buffer (get-buffer "*Python2*")) 43 | (should (string= "4" py-result)) 44 | (should (< 1 comint-last-input-end)))) 45 | 46 | (ert-deftest py-ert-python3-shell-test () 47 | (let ((py-python3-command-args (list "-i -c\"abc=4\""))) 48 | (py-kill-buffer-unconditional "*Python3*") 49 | (python3) 50 | (should (buffer-live-p (get-buffer "*Python3*"))) 51 | (set-buffer (get-buffer "*Python3*")) 52 | (should (string= "4" py-result)) 53 | (should (< 1 comint-last-input-end)))) 54 | 55 | (ert-deftest py-ert-ipython-shell-test () 56 | (let ((py-ipython-command-args (list "-i -c\"abc=4\""))) 57 | (py-kill-buffer-unconditional "*IPython*") 58 | (ipython) 59 | (should (buffer-live-p (get-buffer "*IPython*"))) 60 | (set-buffer (get-buffer "*IPython*")) 61 | (should (string= "4" py-result)) 62 | (should (< 1 comint-last-input-end)))) 63 | 64 | (ert-deftest py-ert-ipython2.7-shell-test () 65 | (let ((py-ipython2.7-command-args (list "-i -c\"abc=4\""))) 66 | (py-kill-buffer-unconditional "*IPython2.7*") 67 | (ipython2.7) 68 | (should (buffer-live-p (get-buffer "*IPython2.7*"))) 69 | (set-buffer (get-buffer "*IPython2.7*")) 70 | (should (string= "4" py-result)) 71 | (should (< 1 comint-last-input-end)))) 72 | 73 | (ert-deftest py-ert-ipython3-shell-test () 74 | (let ((py-ipython3-command-args (list "-i -c\"abc=4\""))) 75 | (py-kill-buffer-unconditional "*IPython3*") 76 | (ipython3) 77 | (should (buffer-live-p (get-buffer "*IPython3*"))) 78 | (set-buffer (get-buffer "*IPython3*")) 79 | (should (string= "4" py-result)) 80 | (should (< 1 comint-last-input-end)))) 81 | 82 | (ert-deftest py-ert-jython-shell-test () 83 | (let ((py-jython-command-args (list "-i -c\"abc=4\""))) 84 | (py-kill-buffer-unconditional "*Jython*") 85 | (jython) 86 | (should (buffer-live-p (get-buffer "*Jython*"))) 87 | (set-buffer (get-buffer "*Jython*")) 88 | (should (string= "4" py-result)) 89 | (should (< 1 comint-last-input-end)))) 90 | 91 | (provide 'py-shell-ert-tests) 92 | ;;; py-shell-ert-tests.el ends here 93 | -------------------------------------------------------------------------------- /test/py-split-window-on-execute-lp-1361531-test.el: -------------------------------------------------------------------------------- 1 | ;;; py-split-window-on-execute-lp-1361531-test.el --- Test splitting 2 | 3 | ;; Copyright (C) 2011-2014 Andreas Roehler 4 | ;; Author: Andreas Roehler 5 | ;; Keywords: languages, convenience 6 | 7 | ;; This program is free software; you can redistribute it and/or modify 8 | ;; it under the terms of the GNU General Public License as published by 9 | ;; the Free Software Foundation, either version 3 of the License, or 10 | ;; (at your option) any later version. 11 | 12 | ;; This program is distributed in the hope that it will be useful, 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ;; GNU General Public License for more details. 16 | 17 | ;; You should have received a copy of the GNU General Public License 18 | ;; along with this program. If not, see . 19 | 20 | ;;; Commentary: 21 | 22 | ;; This file is generated by function from python-mode-utils.el - see in 23 | ;; directory devel. Edits here might not be persistent. 24 | 25 | ;;; Code: 26 | 27 | (ert-deftest py--split-t-not-switch-wm-test () 28 | (py-test-with-temp-buffer 29 | "print(\"I'm the py-split-window-on-execute-lp-1361531-python-test\")" 30 | (let ((py-split-window-on-execute 1) 31 | py-switch-buffers-on-execute-p) 32 | (py-execute-statement-python3)) 33 | (should (window-live-p (get-buffer "*Python3*"))))) 34 | 35 | (defun py-split-window-on-execute-lp-1361531-python-test (&optional arg) 36 | (interactive "p") 37 | (let ((py-split-window-on-execute t) 38 | (teststring "#! /usr/bin/env python 39 | # -*- coding: utf-8 -*- 40 | print(\"I'm the py-split-window-on-execute-lp-1361531-python-test\")")) 41 | (py-bug-tests-intern 'py-split-window-on-execute-lp-1361531-python-base arg teststring))) 42 | 43 | (defun py-split-window-on-execute-lp-1361531-python-base () 44 | (when py-debug-p (message "py-split-window-on-execute: %s" py-split-window-on-execute)) 45 | (delete-other-windows) 46 | (py-execute-statement) 47 | (assert (eq 2 (count-windows)) nil "py-split-window-on-execute-lp-1361531-python-test failed") 48 | (py-kill-buffer-unconditional (current-buffer))) 49 | 50 | (defun py-split-window-on-execute-lp-1361531-ipython-test (&optional arg) 51 | (interactive "p") 52 | (let ((py-split-window-on-execute t) 53 | (teststring "#! /usr/bin/env ipython 54 | # -*- coding: utf-8 -*- 55 | print(\"I'm the py-split-window-on-execute-lp-1361531-ipython-test\")")) 56 | (py-bug-tests-intern 'py-split-window-on-execute-lp-1361531-ipython-base arg teststring))) 57 | 58 | (defun py-split-window-on-execute-lp-1361531-ipython-base () 59 | (when py-debug-p (message "py-split-window-on-execute: %s" py-split-window-on-execute)) 60 | (delete-other-windows) 61 | (py-execute-statement) 62 | (assert (eq 2 (count-windows)) nil "py-split-window-on-execute-lp-1361531-ipython-test failed") 63 | (py-kill-buffer-unconditional (current-buffer))) 64 | 65 | (defun py-split-window-on-execute-lp-1361531-python2-test () 66 | (interactive) 67 | (let ((py-split-window-on-execute t) 68 | (teststring "#! /usr/bin/env python2 69 | # -*- coding: utf-8 -*- 70 | print(\"I'm the py-split-window-on-execute-lp-1361531-python2-test\")")) 71 | (py-bug-tests-intern 'py-split-window-on-execute-lp-1361531-python2-base))) 72 | 73 | (defun py-split-window-on-execute-lp-1361531-python2-base () 74 | (when py-debug-p (message "py-split-window-on-execute: %s" py-split-window-on-execute)) 75 | (delete-other-windows) 76 | (py-execute-statement) 77 | (assert (eq 2 (count-windows)) nil "py-split-window-on-execute-lp-1361531-python2-test failed") 78 | (py-kill-buffer-unconditional (current-buffer))) 79 | 80 | (defun py-split-window-on-execute-lp-1361531-jython-test (&optional arg) 81 | (interactive "p") 82 | (let ((py-split-window-on-execute t) 83 | (teststring "#! /usr/bin/env jython 84 | # -*- coding: utf-8 -*- 85 | print(\"I'm the py-split-window-on-execute-lp-1361531-jython-test\")")) 86 | (py-bug-tests-intern 'py-split-window-on-execute-lp-1361531-jython-base arg teststring))) 87 | 88 | (defun py-split-window-on-execute-lp-1361531-jython-base () 89 | (when py-debug-p (message "py-split-window-on-execute: %s" py-split-window-on-execute)) 90 | (delete-other-windows) 91 | (py-execute-statement) 92 | (assert (eq 2 (count-windows)) nil "py-split-window-on-execute-lp-1361531-jython-test failed") 93 | (py-kill-buffer-unconditional (current-buffer))) 94 | 95 | (defun py-split-window-on-execute-lp-1361531-python3-test (&optional arg) 96 | (interactive "p") 97 | (let ((py-split-window-on-execute t) 98 | (teststring "#! /usr/bin/env python3 99 | # -*- coding: utf-8 -*- 100 | print(\"I'm the py-split-window-on-execute-lp-1361531-python3-test\")")) 101 | (py-bug-tests-intern 'py-split-window-on-execute-lp-1361531-python3-base arg teststring))) 102 | 103 | (defun py-split-window-on-execute-lp-1361531-python3-base () 104 | (when py-debug-p (message "py-split-window-on-execute: %s" py-split-window-on-execute)) 105 | (delete-other-windows) 106 | (py-execute-statement) 107 | (assert (eq 2 (count-windows)) nil "py-split-window-on-execute-lp-1361531-python3-test failed") 108 | (py-kill-buffer-unconditional (current-buffer))) 109 | 110 | (provide 'py-split-window-on-execute-lp-1361531-test) 111 | ;;; py-split-window-on-execute-lp-1361531-test.el here 112 | -------------------------------------------------------------------------------- /test/py-split-window-on-execute-test.el: -------------------------------------------------------------------------------- 1 | ;;; py-split-window-on-execute-test.el --- Test splitting 2 | 3 | ;; URL: https://gitlab.com/python-mode-devs 4 | ;; Keywords: languages, convenience 5 | 6 | ;; This program is free software; you can redistribute it and/or modify 7 | ;; it under the terms of the GNU General Public License as published by 8 | ;; the Free Software Foundation, either version 3 of the License, or 9 | ;; (at your option) any later version. 10 | 11 | ;; This program is distributed in the hope that it will be useful, 12 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ;; GNU General Public License for more details. 15 | 16 | ;; You should have received a copy of the GNU General Public License 17 | ;; along with this program. If not, see . 18 | 19 | ;;; Commentary: 20 | 21 | ;; This file is generated by function from python-mode-utils.el - see in 22 | ;; directory devel. Edits here might not be persistent. 23 | 24 | ;;; Code: 25 | 26 | 27 | (defun py-split-window-on-execute-lp-1361531-python-test (&optional arg) 28 | (interactive "p") 29 | (let ((py-split-window-on-execute t) 30 | (teststring "#! /usr/bin/env python 31 | # -*- coding: utf-8 -*- 32 | print(\"I'm the py-split-window-on-execute-lp-1361531-python-test\")")) 33 | (py-bug-tests-intern 'py-split-window-on-execute-lp-1361531-python-base arg teststring))) 34 | 35 | (defun py-split-window-on-execute-lp-1361531-python-base () 36 | (when py-debug-p (message "py-split-window-on-execute: %s" py-split-window-on-execute)) 37 | (delete-other-windows) 38 | (py-execute-statement) 39 | (assert (eq 2 (count-windows)) nil "py-split-window-on-execute-lp-1361531-python-test failed") 40 | (py-kill-buffer-unconditional (current-buffer))) 41 | 42 | (defun py-split-window-on-execute-lp-1361531-ipython-test (&optional arg) 43 | (interactive "p") 44 | (let ((py-split-window-on-execute t) 45 | (teststring "#! /usr/bin/env ipython 46 | # -*- coding: utf-8 -*- 47 | print(\"I'm the py-split-window-on-execute-lp-1361531-ipython-test\")")) 48 | (py-bug-tests-intern 'py-split-window-on-execute-lp-1361531-ipython-base arg teststring))) 49 | 50 | (defun py-split-window-on-execute-lp-1361531-ipython-base () 51 | (when py-debug-p (message "py-split-window-on-execute: %s" py-split-window-on-execute)) 52 | (delete-other-windows) 53 | (py-execute-statement) 54 | (assert (eq 2 (count-windows)) nil "py-split-window-on-execute-lp-1361531-ipython-test failed") 55 | (py-kill-buffer-unconditional (current-buffer))) 56 | 57 | (defun py-split-window-on-execute-lp-1361531-python2-test () 58 | (interactive) 59 | (let ((py-split-window-on-execute t) 60 | (teststring "#! /usr/bin/env python2 61 | # -*- coding: utf-8 -*- 62 | print(\"I'm the py-split-window-on-execute-lp-1361531-python2-test\")")) 63 | (py-bug-tests-intern 'py-split-window-on-execute-lp-1361531-python2-base))) 64 | 65 | (defun py-split-window-on-execute-lp-1361531-python2-base () 66 | (when py-debug-p (message "py-split-window-on-execute: %s" py-split-window-on-execute)) 67 | (delete-other-windows) 68 | (py-execute-statement) 69 | (assert (eq 2 (count-windows)) nil "py-split-window-on-execute-lp-1361531-python2-test failed") 70 | (py-kill-buffer-unconditional (current-buffer))) 71 | 72 | (defun py-split-window-on-execute-lp-1361531-jython-test (&optional arg) 73 | (interactive "p") 74 | (let ((py-split-window-on-execute t) 75 | (teststring "#! /usr/bin/env jython 76 | # -*- coding: utf-8 -*- 77 | print(\"I'm the py-split-window-on-execute-lp-1361531-jython-test\")")) 78 | (py-bug-tests-intern 'py-split-window-on-execute-lp-1361531-jython-base arg teststring))) 79 | 80 | (defun py-split-window-on-execute-lp-1361531-jython-base () 81 | (when py-debug-p (message "py-split-window-on-execute: %s" py-split-window-on-execute)) 82 | (delete-other-windows) 83 | (py-execute-statement) 84 | (assert (eq 2 (count-windows)) nil "py-split-window-on-execute-lp-1361531-jython-test failed") 85 | (py-kill-buffer-unconditional (current-buffer))) 86 | 87 | (defun py-split-window-on-execute-lp-1361531-python3-test (&optional arg) 88 | (interactive "p") 89 | (let ((py-split-window-on-execute t) 90 | (teststring "#! /usr/bin/env python3 91 | # -*- coding: utf-8 -*- 92 | print(\"I'm the py-split-window-on-execute-lp-1361531-python3-test\")")) 93 | (py-bug-tests-intern 'py-split-window-on-execute-lp-1361531-python3-base arg teststring))) 94 | 95 | (defun py-split-window-on-execute-lp-1361531-python3-base () 96 | (when py-debug-p (message "py-split-window-on-execute: %s" py-split-window-on-execute)) 97 | (delete-other-windows) 98 | (py-execute-statement) 99 | (assert (eq 2 (count-windows)) nil "py-split-window-on-execute-lp-1361531-python3-test failed") 100 | (py-kill-buffer-unconditional (current-buffer))) 101 | 102 | (provide 'py-split-window-on-execute-test) 103 | ;;; py-split-window-on-execute-test.el here 104 | -------------------------------------------------------------------------------- /test/python-mode-ert-tests-1.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Author: Andreas Roehler 4 | 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | # Commentary: 16 | 17 | # This script tests Emacs python-mode. 18 | 19 | # Caveats: 20 | # 21 | # needs being started in `test' directory 22 | # optional shell argument PATH/TO/EMACS-SOURCE-DIRECTORY might be given 23 | # 24 | # If testing with emacs-24 please be aware of bug 11984 [0], for the 25 | # time being the patch will need to be added manually. 26 | # 27 | # IPython 0.12 due to a bug in argparse requires a patch [1] to work. 28 | # 29 | # 0. http://debbugs.gnu.org/cgi/bugreport.cgi?bug=11984 30 | # 1. http://bugs.python.org/issue13720 31 | 32 | # Code: 33 | 34 | 35 | # if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then 36 | # hash -r 2>/dev/null 37 | # fi 38 | 39 | # needs being in `test' directory 40 | # PCOT=`pwd` 41 | PCOT=$PWD 42 | # PDIR=".." 43 | PDIR=$(cd ..; pwd) 44 | # the directory that this file is in. 45 | # TESTDIR="$(dirname "$0")" 46 | # PDIR="$TESTDIR/.." 47 | 48 | # write PATH-TO-EMACS source code default directory here 49 | EMACS_DEFAULT_DIR="/usr/share/emacs/24.2" 50 | 51 | EMACS_DIR= 52 | if [ $1 ]; then 53 | echo "\$1: $1" 54 | EMACS_DIR=$1 55 | else 56 | EMACS_DIR=$EMACS_DEFAULT_DIR 57 | fi 58 | 59 | [ -s python-mode-ert-results.txt ] && rm -f python-mode-ert-results.txt 60 | 61 | # else 62 | # cat < 4 | 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | # Commentary: 16 | 17 | # This script tests Emacs python-mode. 18 | 19 | # Caveats: 20 | # 21 | # needs being started in `test' directory 22 | # optional shell argument PATH/TO/EMACS-SOURCE-DIRECTORY might be given 23 | # 24 | # If testing with emacs-24 please be aware of bug 11984 [0], for the 25 | # time being the patch will need to be added manually. 26 | # 27 | # IPython 0.12 due to a bug in argparse requires a patch [1] to work. 28 | # 29 | # 0. http://debbugs.gnu.org/cgi/bugreport.cgi?bug=11984 30 | # 1. http://bugs.python.org/issue13720 31 | 32 | # Code: 33 | 34 | 35 | # if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then 36 | # hash -r 2>/dev/null 37 | # fi 38 | 39 | # needs being in `test' directory 40 | # PCOT=`pwd` 41 | PCOT=$PWD 42 | # PDIR=".." 43 | PDIR=$(cd ..; pwd) 44 | # the directory that this file is in. 45 | # TESTDIR="$(dirname "$0")" 46 | # PDIR="$TESTDIR/.." 47 | 48 | # write PATH-TO-EMACS source code default directory here 49 | EMACS_DEFAULT_DIR="/usr/share/emacs/24.2" 50 | 51 | EMACS_DIR= 52 | if [ $1 ]; then 53 | echo "\$1: $1" 54 | EMACS_DIR=$1 55 | else 56 | EMACS_DIR=$EMACS_DEFAULT_DIR 57 | fi 58 | 59 | [ -s python-mode-ert-results.txt ] && rm -f python-mode-ert-results.txt 60 | 61 | # else 62 | # cat < 4 | 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | # Commentary: 16 | 17 | # This script tests Emacs python-mode. 18 | 19 | # Caveats: 20 | # 21 | # needs being started in `test' directory 22 | # optional shell argument PATH/TO/EMACS-SOURCE-DIRECTORY might be given 23 | # 24 | # If testing with emacs-24 please be aware of bug 11984 [0], for the 25 | # time being the patch will need to be added manually. 26 | # 27 | # IPython 0.12 due to a bug in argparse requires a patch [1] to work. 28 | # 29 | # 0. http://debbugs.gnu.org/cgi/bugreport.cgi?bug=11984 30 | # 1. http://bugs.python.org/issue13720 31 | 32 | # Code: 33 | 34 | 35 | # if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then 36 | # hash -r 2>/dev/null 37 | # fi 38 | 39 | # needs being in `test' directory 40 | # PCOT=`pwd` 41 | PCOT=$PWD 42 | # PDIR=".." 43 | PDIR=$(cd ..; pwd) 44 | # the directory that this file is in. 45 | # TESTDIR="$(dirname "$0")" 46 | # PDIR="$TESTDIR/.." 47 | 48 | # write PATH-TO-EMACS source code default directory here 49 | EMACS_DEFAULT_DIR="/usr/share/emacs/24.2" 50 | 51 | EMACS_DIR= 52 | if [ $1 ]; then 53 | echo "\$1: $1" 54 | EMACS_DIR=$1 55 | else 56 | EMACS_DIR=$EMACS_DEFAULT_DIR 57 | fi 58 | 59 | [ -s python-mode-ert-results.txt ] && rm -f python-mode-ert-results.txt 60 | 61 | # else 62 | # cat < 5 | 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | # Commentary: 17 | 18 | # Check resp. edit the vars pointing to the directories/files 19 | # holding your python-mode and Emacsen for test 20 | 21 | # alternativly select Emacs by giving $EMACS_SOURCE_DIR 22 | # as shell arg 23 | # ./syntax-test.sh EMACS_SOURCE_DIR 24 | # Emacs will be looked up: ${EMACS_SOURCE_DIR}/src/emacs 25 | 26 | # assumes test files in current directory 27 | 28 | # the path 29 | PDIR=`pwd` 30 | 31 | # write PATH-TO-EMACS source code directory here 32 | # EMACS_SOURCE_DIR="$HOME/emacs-20110426" 33 | EMACS_SOURCE_DIR= 34 | 35 | # python-mode file to load 36 | if [ -s "../python-components-mode.el" ]; 37 | then 38 | PYTHONMODE="../python-components-mode.el" 39 | else 40 | PYTHONMODE="../python-mode.el" 41 | fi 42 | 43 | if [ $1 ]; then 44 | EMACS_SOURCE_DIR=$1 45 | fi 46 | 47 | if [ $EMACS_SOURCE_DIR ]; then 48 | 49 | EMACS="${EMACS_SOURCE_DIR}/src/emacs" 50 | 51 | # else 52 | # EMACS=emacs 53 | # when installed Emacs shall be used, CCCMDS must be set 54 | # CCCMDS="${EMACS_SOURCE_DIR}/lisp/progmodes/cc-cmds.el" 55 | 56 | MODEDIR=${PDIR%%/test} 57 | echo "\$MODEDIR: $MODEDIR" 58 | 59 | CCCMDS="${EMACS_SOURCE_DIR}/lisp/progmodes/cc-cmds.el" 60 | # file holding the tests 61 | TESTFILE="py-bug-numbered-tests.el" 62 | TESTFILE2="python-mode-test.el" 63 | 64 | EMACS23="$HOME/emacs-23.3/src/emacs-23.3.1" 65 | EMACS23python="$HOME/emacs-23.3/lisp/progmodes/python.el" 66 | EMACS24python="$HOME/emacs-20110426/lisp/progmodes/python.el" 67 | 68 | CCCMDS="${EMACS_VERZEICHNIS}/lisp/progmodes/cc-cmds.el" 69 | # file holding the tests 70 | TESTFILE="py-bug-numbered-tests.el" 71 | TESTFILE2="python-mode-test.el" 72 | TESTFILE3="python-mode-syntax-test.el" 73 | EMACS="${EMACS_VERZEICHNIS}/src/emacs" 74 | HIL="../highlight-indentation.el" 75 | 76 | if [ ${MODEDIR%%*modes/} == "components-python-mode" ]; 77 | then 78 | 79 | $EMACS -Q --batch --eval "(message (emacs-version))" --eval "(when (featurep 'python)(unload-feature 'python t))" --eval "(when (featurep 'python-mode)(unload-feature 'python-mode t))" --eval "(add-to-list 'load-path \"$PDIR/\")" -load "$MODEDIR/misc-utils.el" -load "$MODEDIR/beg-end.el" -load "$MODEDIR/sh-beg-end.el" -load "$MODEDIR/thingatpt-highlight.el" -load "$MODEDIR/thingatpt-utils-base.el" -load "$MODEDIR/thing-at-point-utils.el" -load "$MODEDIR/ar-comment-lor.el" -load "$MODEDIR/thingatpt-python-expressions.el" -load "$MODEDIR/highlight-indentation" -load "$MODEDIR/hungry-delete.el" \ 80 | -load "$MODEDIR/python-components-edit.el" -load "$MODEDIR/python-components-intern.el" -load "$MODEDIR/python-components-move.el" -load "$MODEDIR/python-mode-execute.el" -load "$MODEDIR/python-mode-send.el" -load "$MODEDIR/python-components-pdb.el" -load "$MODEDIR/python-components-skeletons.el" -load "$MODEDIR/python-components-help.el" -load "$MODEDIR/python-components-extensions.el" -load "$MODEDIR/python-components-imenu.el" -load "$MODEDIR/python-components-mode.el" -load "$PCOT/py-bug-numbered-tests.el" -load "$PCOT/python-mode-test.el" -load "$PDIR/$TESTFILE3" -load $CCCMDS --eval "(quietly-read-abbrev-file (expand-file-name \"~/.abbrev_defs\"))" \ 81 | --funcall erste-tqs-syntax-test 82 | 83 | $EMACS23 -Q --batch --eval "(message (emacs-version))" --eval "(when (featurep 'python)(unload-feature 'python t))" --eval "(when (featurep 'python-mode)(unload-feature 'python-mode t))" --eval "(add-to-list 'load-path \"$PDIR/\")" -load "$MODEDIR/misc-utils.el" -load "$MODEDIR/beg-end.el" -load "$MODEDIR/sh-beg-end.el" -load "$MODEDIR/thingatpt-highlight.el" -load "$MODEDIR/thingatpt-utils-base.el" -load "$MODEDIR/thing-at-point-utils.el" -load "$MODEDIR/ar-comment-lor.el" -load "$MODEDIR/thingatpt-python-expressions.el" -load "$MODEDIR/highlight-indentation" -load "$MODEDIR/hungry-delete.el" \ 84 | -load "$MODEDIR/python-components-edit.el" -load "$MODEDIR/python-components-intern.el" -load "$MODEDIR/python-components-move.el" -load "$MODEDIR/python-mode-execute.el" -load "$MODEDIR/python-mode-send.el" -load "$MODEDIR/python-components-pdb.el" -load "$MODEDIR/python-components-skeletons.el" -load "$MODEDIR/python-components-help.el" -load "$MODEDIR/python-components-extensions.el" -load "$MODEDIR/python-components-imenu.el" -load "$MODEDIR/python-components-mode.el" -load "$PCOT/py-bug-numbered-tests.el" -load "$PCOT/python-mode-test.el" -load "$PDIR/$TESTFILE3" -load $CCCMDS --eval "(quietly-read-abbrev-file (expand-file-name \"~/.abbrev_defs\"))" \ 85 | --funcall erste-tqs-syntax-test 86 | 87 | else 88 | echo "\$EMACS24python: $EMACS24python" 89 | $EMACS -Q --batch --eval "(message (emacs-version))" -load "$PDIR/$TESTFILE3" --load $EMACS24python --funcall erste-tqs-syntax-test 90 | echo 91 | echo "\$EMACS23python: $EMACS23python" 92 | $EMACS23 -Q --batch --eval "(message (emacs-version))" -load "$PDIR/$TESTFILE3" -load $EMACS23python --eval "(sit-for 0.1)" --funcall erste-tqs-syntax-test 93 | echo 94 | echo "unloading before" 95 | echo "\$EMACS23python: $EMACS23python" 96 | $EMACS23 -Q --batch --eval "(message (emacs-version))" -load "$PDIR/$TESTFILE3" --eval "(when (featurep 'python)(unload-feature 'python t))" -load $EMACS23python --eval "(sit-for 0.1)" --funcall erste-tqs-syntax-test 97 | echo 98 | echo "\$MODEDIR/python-mode.el: $MODEDIR/python-mode.el" 99 | $EMACS -Q --batch --eval "(message (emacs-version))" -load "$PDIR/$TESTFILE3" --load $MODEDIR/python-mode.el --eval "(sit-for 0.1)" --funcall erste-tqs-syntax-test 100 | echo 101 | echo "\$MODEDIR/python-mode.el: $MODEDIR/python-mode.el" 102 | $EMACS23 -Q --batch --eval "(message (emacs-version))" --eval "(when (featurep 'python)(unload-feature 'python t))" -load "$PDIR/$TESTFILE3" --load $MODEDIR/python-mode.el --eval "(sit-for 0.1)" --funcall erste-tqs-syntax-test 103 | 104 | fi 105 | -------------------------------------------------------------------------------- /test/test-triple-strings.py: -------------------------------------------------------------------------------- 1 | # Source: 2 | # http://launchpadlibrarian.net/22565844/test-triple-strings.py 3 | # Author: Ed Loper 4 | 5 | # This file tests python-mode's ability to handle triple-quoted 6 | # string. Here's how to tell if python-mode's doing the right thing: 7 | # 8 | # - All dashes (-) should *not* be marked as strings. 9 | # - All Os, Xs, s should be marked as strings. 10 | # - None of the quote marks around O's should be marked as strings. 11 | # - Quote marks that are between angle brackets (<...>) should be 12 | # marked as strings. Think of "X" as a pair of angle brackets 13 | # right next to one another. Also, quotes to the left of >s 14 | # and the right of with other characters should not affect 17 | # the fontificatin any; these characters were just used to make it 18 | # easier to see what the intended colorization is.) 19 | 20 | # Some easy cases: 21 | "O" 'O' "<'>" '<">' 22 | "O" 'O' "<'>" '<">' 23 | " O " ' O ' " < ' > " ' < " > ' 24 | """O""" '''O''' "<<<'>>>" '''<">''' 25 | 26 | # Some harder cases: 27 | """<">""" '''<'>''' 28 | 29 | # Some tricky cases with backslashes. 30 | '''<'>''' '''<\'''>''' '''<\\''' 31 | 32 | # Some tricky cases with more than 3 quotes in a row. 33 | "O""" "O" 34 | """">""" 35 | """">>""" 36 | """"X">""" 37 | """"X"">""" 38 | """O""""O" "" 39 | """O""""" "O" 40 | """O""""""<">""" 41 | """O"""""""X">""" 42 | """O""""""""X">""" 43 | """O""" "<<<>>>>" 44 | """""""""O""" "O" 45 | """O""""O""O""O""" 46 | """">""" """">>""" """">>>""" 47 | """"">""" """"">>""" """"">>>""" 48 | """"">>>""""O" """"">>>""""" 49 | """""""""<""X"X"">""" 50 | 51 | # One version had a bug with comments ending in string markers: " 52 | """O""" 53 | 54 | "" "" 55 | 56 | """<">""" '''<'>''' 57 | 58 | # Spanning multiple lines: 59 | 60 | "< 61 | >" 62 | 63 | '< 64 | >' 65 | 66 | """ 67 | < 68 | < 69 | < 70 | < 71 | ' 72 | X 73 | X 74 | X 75 | " 76 | > 77 | > 78 | """ 79 | -------------------------------------------------------------------------------- /website/.cvsignore: -------------------------------------------------------------------------------- 1 | *.html *.pyc 2 | -------------------------------------------------------------------------------- /website/.rsync-excludes: -------------------------------------------------------------------------------- 1 | .*~ 2 | *~ 3 | make.rules 4 | Makefile 5 | .rsync-excludes 6 | *.py 7 | -------------------------------------------------------------------------------- /website/Makefile: -------------------------------------------------------------------------------- 1 | ROOT_DIR=. 2 | ROOT_OFFSET=. 3 | 4 | include make.rules 5 | 6 | LOCAL_INCLUDE = 7 | 8 | all: $(TARGETS) 9 | 10 | always: 11 | @echo >/dev/null 12 | 13 | -------------------------------------------------------------------------------- /website/PMGenerator.py: -------------------------------------------------------------------------------- 1 | """Standard Generator with slight tweaks.""" 2 | 3 | from StandardGenerator import StandardGenerator 4 | 5 | try: 6 | import rst_html 7 | except ImportError: 8 | print 'Unable to import rst_html/docutils' 9 | print 'Get and install the docutils from docutils.sf.net' 10 | rst_html = None 11 | 12 | class PMGenerator(StandardGenerator): 13 | def __init__(self, file, rootdir, relthis): 14 | StandardGenerator.__init__(self, file, rootdir, relthis) 15 | self.rootdir = rootdir 16 | self.filename = file 17 | self.__body = None 18 | self.__cont = None 19 | 20 | def get_corner(self): 21 | return ('''
No Logo!
''' % 22 | self.__dict__) 23 | 24 | def get_banner(self): 25 | return '''\ 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 |
Python-Mode DocumentationPython
GNU EmacsXEmacs
36 | ''' % self.__dict__ 37 | 38 | def _grokbody(self): 39 | if self.__body is None: 40 | data = self._parser.fp.read() 41 | # convert to Unicode: 42 | text = data.decode(self.get_encoding()) 43 | if self.get_content_type() == 'text/x-rst': 44 | if rst_html is None: 45 | print 'ReST-to-HTML conversion not available' 46 | else: 47 | text = rst_html.process_rst(self.filename, text) 48 | # convert Unicode back to 8-bit string: 49 | text = text.encode(self.get_charset(), 'xmlcharrefreplace') 50 | i = text.find('') 51 | if i >= 0: 52 | self.__body = text[:i] 53 | self.__cont = text[i+17:] 54 | else: 55 | # there is no wide body 56 | self.__body = text 57 | 58 | def get_body(self): 59 | self._grokbody() 60 | return self.__body 61 | 62 | def get_cont(self): 63 | self._grokbody() 64 | return self.__cont 65 | 66 | def get_encoding(self): 67 | return self._parser.get('encoding', 'utf-8') 68 | 69 | def get_content_type(self): 70 | return self._parser.get('content-type', use_defaults=False) 71 | 72 | 73 | -------------------------------------------------------------------------------- /website/calcroot.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # 3 | # simple script to calculate HTROOT from ROOT_OFFSET. Pass ROOT_OFFSET in on 4 | # the command line 5 | 6 | import sys 7 | import os 8 | import string 9 | 10 | if sys.argv[1] == '.': 11 | print '.' 12 | else: 13 | print string.join(['..'] * len(string.split(sys.argv[1], os.sep)), os.sep) 14 | -------------------------------------------------------------------------------- /website/docs/.cvsignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /website/docs/Makefile: -------------------------------------------------------------------------------- 1 | ROOT_DIR=.. 2 | ROOT_OFFSET=docs 3 | 4 | include $(ROOT_DIR)/make.rules 5 | 6 | LOCAL_INCLUDE = 7 | 8 | SUBDIRS = 9 | 10 | all: $(SUBDIRS) 11 | 12 | local: $(TARGETS) 13 | 14 | $(TARGETS): links.h 15 | 16 | always: 17 | @echo >/dev/null 18 | 19 | -------------------------------------------------------------------------------- /website/docs/basics.ht: -------------------------------------------------------------------------------- 1 | Title: Python-Mode Basics 2 | Author: python-mode@python.org 3 | Meta: 4 | 5 | Content-Type: text/x-rst 6 | 7 | If you've used editing modes for other languages in Emacs, the basics of 8 | python-mode should be familiar to you. Keywords and strings are colored. 9 | When you type a newline character, the cursor is automatically indented 10 | according to the indentation and content of the preceding line. 11 | -------------------------------------------------------------------------------- /website/docs/customize.ht: -------------------------------------------------------------------------------- 1 | Title: Python-Mode Customization 2 | Author: python-mode@python.org 3 | Meta: 4 | 5 | Content-Type: text/x-rst 6 | 7 | Sorry, TBD. 8 | -------------------------------------------------------------------------------- /website/docs/index.ht: -------------------------------------------------------------------------------- 1 | Title: Python-Mode Documentation 2 | Author: python-mode@python.org 3 | Meta: 4 | 5 | Content-Type: text/x-rst 6 | 7 | Python-mode makes a number of editing and debugging features available to 8 | Python programmers who use GNU Emacs or XEmacs. Included in its basic 9 | feature set are: 10 | 11 | * syntax coloring 12 | 13 | * indent/dedent/electric newline support 14 | 15 | * movement across major functional sections of code 16 | 17 | * code execution in inferior Python processes 18 | 19 | * class/function marking 20 | 21 | * integration with pdb, the Python debugger 22 | -------------------------------------------------------------------------------- /website/docs/links.h: -------------------------------------------------------------------------------- 1 | 2 |

Sections

3 |
  • Introduction 4 |
  • Basic Functionality 5 |
  • Customization 6 |
  • Related Packages 7 | -------------------------------------------------------------------------------- /website/docs/related.ht: -------------------------------------------------------------------------------- 1 | Title: Related Packages 2 | Author: python-mode@python.org 3 | Meta: 4 | 5 | Content-Type: text/x-rst 6 | 7 | Sorry, TBD. 8 | -------------------------------------------------------------------------------- /website/index.ht: -------------------------------------------------------------------------------- 1 | Title: Python-Mode For Emacs 2 | Author: python-mode@python.org 3 | Meta: 4 | 7 | Content-Type: text/x-rst 8 | 9 | Nobody here but `us chickens`_ for now... 10 | 11 | Eventually we'll have some documentation and links. 12 | 13 | .. _us chickens: mailto:python-mode@python.org 14 | -------------------------------------------------------------------------------- /website/links.h: -------------------------------------------------------------------------------- 1 |

    Links:

    2 |
  • Project Page 3 |
  • Download 4 | -------------------------------------------------------------------------------- /website/make.rules: -------------------------------------------------------------------------------- 1 | # This requires GNU make. -*- makefile -*- 2 | # 3 | # To use this, a script must include the following minimal set of 4 | # stuff: 5 | # 6 | # include relative/path/to/scripts/make.rules 7 | # ROOT_DIR = relative/path/to 8 | # ROOT_OFFSET = path/of/cwd/relative/to/ROOT_DIR 9 | # 10 | # E.g. for the cp4e directory: 11 | # 12 | # include ../scripts/make.rules 13 | # ROOT_DIR = .. 14 | # ROOT_OFFSET = cp4e 15 | 16 | # Make rules for www.python.org ht->html generation. SOURCES 17 | # indirection filters out "*.ht" value when no ht files are around. 18 | SOURCES = $(wildcard *.ht) 19 | HTTARGETS = $(filter-out *.html,$(SOURCES:%.ht=%.html)) 20 | TARGETS = $(HTTARGETS) $(EXTRA_TARGETS) 21 | 22 | # Where to upload stuff for make install. LIVE_ROOT is the actual 23 | # physical location of files on the server. 24 | LIVE_HOST = shell.sourceforge.net 25 | LIVE_ROOT = /home/groups/p/py/python-mode/htdocs 26 | LIVE_DEST = $(LIVE_HOST):$(LIVE_ROOT)/$(ROOT_OFFSET) 27 | 28 | # rsync definitions. 29 | RSYNC_RSH = ssh 30 | 31 | # Validation 32 | HTML_CATALOG = /usr/share/sgml/html-4.01/HTML4.cat 33 | NSGMLS = nsgmls 34 | 35 | GLOBAL_EXCLUDES = 36 | # If the file .rsync-excludes exists in the make dir, use it. 37 | EXCLUDE_FROM = $(shell if [ -f .rsync-excludes ]; then \ 38 | echo "--exclude-from=.rsync-excludes"; \ 39 | else \ 40 | echo ""; \ 41 | fi) 42 | LOCAL_INCLUDE = 43 | 44 | SCRIPTDIR = $(ROOT_DIR) 45 | HT2HTML = $(shell which ht2html) 46 | HTSTYLE = PMGenerator 47 | HTALLFLAGS = -f -s $(HTSTYLE) 48 | HTROOT = $(shell $(SCRIPTDIR)/calcroot.py $(ROOT_OFFSET)) 49 | HTFLAGS = $(HTALLFLAGS) -r $(HTROOT) 50 | RST2HT = rst2ht.py 51 | RSTFLAGS = -g -t -s 52 | HTRELDIR = . 53 | #HTWF = $(SCRIPTDIR)/ht2html/htwf.py 54 | #HTWFFLAGS = -s $(HTSTYLE) -r $(HTROOT) 55 | 56 | GENERATED_HTML= $(SOURCES:.ht=.html) 57 | 58 | .SUFFIXES: .ht .html 59 | 60 | %.html : %.ht 61 | PYTHONPATH=$(SCRIPTDIR) $(HT2HTML) $(HTFLAGS) $(HTRELDIR)/$< 62 | 63 | all: $(TARGETS) 64 | 65 | $(HTTARGETS): $(HT2HTML) $(SCRIPTDIR)/$(HTSTYLE).py 66 | 67 | clean: 68 | -rm -f *~ .*~ *.py[co] 69 | 70 | realclean: clean 71 | -rm -f $(GENERATED_HTML) 72 | 73 | install: all local_install 74 | @if [ -z "$(ROOT_OFFSET)" ]; then \ 75 | echo "You have to specify a value for 'ROOT_OFFSET' in the makefile!"; \ 76 | false; \ 77 | fi 78 | @echo Push to $(LIVE_DEST) ... 79 | rsync --rsh=$(RSYNC_RSH) -v -l -u $(GLOBAL_EXCLUDES) $(EXCLUDE_FROM) $(HTTARGETS) *.ht $(LIVE_DEST) 80 | 81 | validate: $(TARGETS) 82 | for f in $(TARGETS); \ 83 | do echo $$f;\ 84 | $(NSGMLS) -s -c $(HTML_CATALOG) $$f; \ 85 | done 86 | 87 | wfcheck: 88 | $(HTWF) $(HTWFFLAGS) $(SOURCES) 89 | 90 | # Override local_install in Makefile for directory-specific install actions. 91 | local_install: 92 | 93 | recursive: all 94 | for dir in * ; do \ 95 | if [ -f $$dir/Makefile ] ; then \ 96 | echo "Changing to $$dir" ; \ 97 | cd $$dir ; make recursive; cd .. ; \ 98 | fi \ 99 | done 100 | --------------------------------------------------------------------------------