diff options
| author | Joakim Verona | 2014-06-23 09:41:17 +0200 |
|---|---|---|
| committer | Joakim Verona | 2014-06-23 09:41:17 +0200 |
| commit | c4916d541b6f91e80283b473c5191651c719228a (patch) | |
| tree | b8f4b0850983aaefc598a5db3f51e9fff9e457af /lisp/progmodes/python.el | |
| parent | ce8171797dafbde765170b79e5f154afc4872e86 (diff) | |
| parent | 814200c2675928b79ee0e023c0fc939ef0da8317 (diff) | |
| download | emacs-c4916d541b6f91e80283b473c5191651c719228a.tar.gz emacs-c4916d541b6f91e80283b473c5191651c719228a.zip | |
manual upstream merge
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 436442da2d0..743981b3714 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -155,15 +155,13 @@ | |||
| 155 | ;; the shell completion in background so you should run | 155 | ;; the shell completion in background so you should run |
| 156 | ;; `python-shell-send-buffer' from time to time to get better results. | 156 | ;; `python-shell-send-buffer' from time to time to get better results. |
| 157 | 157 | ||
| 158 | ;; Skeletons: 6 skeletons are provided for simple inserting of class, | 158 | ;; Skeletons: skeletons are provided for simple inserting of things like class, |
| 159 | ;; def, for, if, try and while. These skeletons are integrated with | 159 | ;; def, for, import, if, try, and while. These skeletons are |
| 160 | ;; abbrev. If you have `abbrev-mode' activated and | 160 | ;; integrated with abbrev. If you have `abbrev-mode' activated and |
| 161 | ;; `python-skeleton-autoinsert' is set to t, then whenever you type | 161 | ;; `python-skeleton-autoinsert' is set to t, then whenever you type |
| 162 | ;; the name of any of those defined and hit SPC, they will be | 162 | ;; the name of any of those defined and hit SPC, they will be |
| 163 | ;; automatically expanded. As an alternative you can use the defined | 163 | ;; automatically expanded. As an alternative you can use the defined |
| 164 | ;; skeleton commands: `python-skeleton-class', `python-skeleton-def' | 164 | ;; skeleton commands: `python-skeleton-<foo>'. |
| 165 | ;; `python-skeleton-for', `python-skeleton-if', `python-skeleton-try' | ||
| 166 | ;; and `python-skeleton-while'. | ||
| 167 | 165 | ||
| 168 | ;; FFAP: You can find the filename for a given module when using ffap | 166 | ;; FFAP: You can find the filename for a given module when using ffap |
| 169 | ;; out of the box. This feature needs an inferior python shell | 167 | ;; out of the box. This feature needs an inferior python shell |
| @@ -253,6 +251,7 @@ | |||
| 253 | (define-key map "\C-c\C-td" 'python-skeleton-def) | 251 | (define-key map "\C-c\C-td" 'python-skeleton-def) |
| 254 | (define-key map "\C-c\C-tf" 'python-skeleton-for) | 252 | (define-key map "\C-c\C-tf" 'python-skeleton-for) |
| 255 | (define-key map "\C-c\C-ti" 'python-skeleton-if) | 253 | (define-key map "\C-c\C-ti" 'python-skeleton-if) |
| 254 | (define-key map "\C-c\C-tm" 'python-skeleton-import) | ||
| 256 | (define-key map "\C-c\C-tt" 'python-skeleton-try) | 255 | (define-key map "\C-c\C-tt" 'python-skeleton-try) |
| 257 | (define-key map "\C-c\C-tw" 'python-skeleton-while) | 256 | (define-key map "\C-c\C-tw" 'python-skeleton-while) |
| 258 | ;; Shell interaction | 257 | ;; Shell interaction |
| @@ -2005,7 +2004,7 @@ process buffer for a list of commands.)" | |||
| 2005 | (interactive | 2004 | (interactive |
| 2006 | (if current-prefix-arg | 2005 | (if current-prefix-arg |
| 2007 | (list | 2006 | (list |
| 2008 | (read-string "Run Python: " (python-shell-parse-command)) | 2007 | (read-shell-command "Run Python: " (python-shell-parse-command)) |
| 2009 | (y-or-n-p "Make dedicated process? ") | 2008 | (y-or-n-p "Make dedicated process? ") |
| 2010 | (= (prefix-numeric-value current-prefix-arg) 4)) | 2009 | (= (prefix-numeric-value current-prefix-arg) 4)) |
| 2011 | (list (python-shell-parse-command) nil t))) | 2010 | (list (python-shell-parse-command) nil t))) |
| @@ -2462,8 +2461,10 @@ LINE is used to detect the context on how to complete given INPUT." | |||
| 2462 | (and completion-code | 2461 | (and completion-code |
| 2463 | (> (length input) 0) | 2462 | (> (length input) 0) |
| 2464 | (with-current-buffer (process-buffer process) | 2463 | (with-current-buffer (process-buffer process) |
| 2465 | (let ((completions (python-shell-send-string-no-output | 2464 | (let ((completions |
| 2466 | (format completion-code input) process))) | 2465 | (python-util-strip-string |
| 2466 | (python-shell-send-string-no-output | ||
| 2467 | (format completion-code input) process)))) | ||
| 2467 | (and (> (length completions) 2) | 2468 | (and (> (length completions) 2) |
| 2468 | (split-string completions | 2469 | (split-string completions |
| 2469 | "^'\\|^\"\\|;\\|'$\\|\"$" t))))))) | 2470 | "^'\\|^\"\\|;\\|'$\\|\"$" t))))))) |
| @@ -2957,6 +2958,12 @@ The skeleton will be bound to python-skeleton-NAME." | |||
| 2957 | > _ \n | 2958 | > _ \n |
| 2958 | '(python-skeleton--else) | ^) | 2959 | '(python-skeleton--else) | ^) |
| 2959 | 2960 | ||
| 2961 | (python-skeleton-define import nil | ||
| 2962 | "Import from module: " | ||
| 2963 | "from " str & " " | -5 | ||
| 2964 | "import " | ||
| 2965 | ("Identifier: " str ", ") -2 \n _) | ||
| 2966 | |||
| 2960 | (python-skeleton-define try nil | 2967 | (python-skeleton-define try nil |
| 2961 | nil | 2968 | nil |
| 2962 | "try:" \n | 2969 | "try:" \n |
| @@ -2983,7 +2990,7 @@ The skeleton will be bound to python-skeleton-NAME." | |||
| 2983 | "class " str "(" ("Inheritance, %s: " | 2990 | "class " str "(" ("Inheritance, %s: " |
| 2984 | (unless (equal ?\( (char-before)) ", ") | 2991 | (unless (equal ?\( (char-before)) ", ") |
| 2985 | str) | 2992 | str) |
| 2986 | & ")" | -2 | 2993 | & ")" | -1 |
| 2987 | ":" \n | 2994 | ":" \n |
| 2988 | "\"\"\"" - "\"\"\"" \n | 2995 | "\"\"\"" - "\"\"\"" \n |
| 2989 | > _ \n) | 2996 | > _ \n) |
| @@ -3643,6 +3650,14 @@ returned as is." | |||
| 3643 | n (1- n))) | 3650 | n (1- n))) |
| 3644 | (reverse acc)))) | 3651 | (reverse acc)))) |
| 3645 | 3652 | ||
| 3653 | (defun python-util-strip-string (string) | ||
| 3654 | "Strip STRING whitespace and newlines from end and beginning." | ||
| 3655 | (replace-regexp-in-string | ||
| 3656 | (rx (or (: string-start (* (any whitespace ?\r ?\n))) | ||
| 3657 | (: (* (any whitespace ?\r ?\n)) string-end))) | ||
| 3658 | "" | ||
| 3659 | string)) | ||
| 3660 | |||
| 3646 | 3661 | ||
| 3647 | (defun python-electric-pair-string-delimiter () | 3662 | (defun python-electric-pair-string-delimiter () |
| 3648 | (when (and electric-pair-mode | 3663 | (when (and electric-pair-mode |
| @@ -3731,7 +3746,7 @@ returned as is." | |||
| 3731 | 3746 | ||
| 3732 | (set (make-local-variable 'outline-regexp) | 3747 | (set (make-local-variable 'outline-regexp) |
| 3733 | (python-rx (* space) block-start)) | 3748 | (python-rx (* space) block-start)) |
| 3734 | (set (make-local-variable 'outline-heading-end-regexp) ":\\s-*\n") | 3749 | (set (make-local-variable 'outline-heading-end-regexp) ":[^\n]*\n") |
| 3735 | (set (make-local-variable 'outline-level) | 3750 | (set (make-local-variable 'outline-level) |
| 3736 | #'(lambda () | 3751 | #'(lambda () |
| 3737 | "`outline-level' function for Python mode." | 3752 | "`outline-level' function for Python mode." |