diff options
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 67383b34154..1ca9f019638 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -261,7 +261,6 @@ | |||
| 261 | (require 'ansi-color) | 261 | (require 'ansi-color) |
| 262 | (require 'cl-lib) | 262 | (require 'cl-lib) |
| 263 | (require 'comint) | 263 | (require 'comint) |
| 264 | (require 'json) | ||
| 265 | (require 'tramp-sh) | 264 | (require 'tramp-sh) |
| 266 | 265 | ||
| 267 | ;; Avoid compiler warnings | 266 | ;; Avoid compiler warnings |
| @@ -2276,6 +2275,18 @@ Do not set this variable directly, instead use | |||
| 2276 | Do not set this variable directly, instead use | 2275 | Do not set this variable directly, instead use |
| 2277 | `python-shell-prompt-set-calculated-regexps'.") | 2276 | `python-shell-prompt-set-calculated-regexps'.") |
| 2278 | 2277 | ||
| 2278 | (defalias 'python--parse-json-array | ||
| 2279 | (if (fboundp 'json-parse-string) | ||
| 2280 | (lambda (string) | ||
| 2281 | (json-parse-string string :array-type 'list)) | ||
| 2282 | (require 'json) | ||
| 2283 | (defvar json-array-type) | ||
| 2284 | (declare-function json-read-from-string "json" (string)) | ||
| 2285 | (lambda (string) | ||
| 2286 | (let ((json-array-type 'list)) | ||
| 2287 | (json-read-from-string string)))) | ||
| 2288 | "Parse the JSON array in STRING into a Lisp list.") | ||
| 2289 | |||
| 2279 | (defun python-shell-prompt-detect () | 2290 | (defun python-shell-prompt-detect () |
| 2280 | "Detect prompts for the current `python-shell-interpreter'. | 2291 | "Detect prompts for the current `python-shell-interpreter'. |
| 2281 | When prompts can be retrieved successfully from the | 2292 | When prompts can be retrieved successfully from the |
| @@ -2324,11 +2335,11 @@ detection and just returns nil." | |||
| 2324 | (catch 'prompts | 2335 | (catch 'prompts |
| 2325 | (dolist (line (split-string output "\n" t)) | 2336 | (dolist (line (split-string output "\n" t)) |
| 2326 | (let ((res | 2337 | (let ((res |
| 2327 | ;; Check if current line is a valid JSON array | 2338 | ;; Check if current line is a valid JSON array. |
| 2328 | (and (string= (substring line 0 2) "[\"") | 2339 | (and (string-prefix-p "[\"" line) |
| 2329 | (ignore-errors | 2340 | (ignore-errors |
| 2330 | ;; Return prompts as a list, not vector | 2341 | ;; Return prompts as a list. |
| 2331 | (append (json-read-from-string line) nil))))) | 2342 | (python--parse-json-array line))))) |
| 2332 | ;; The list must contain 3 strings, where the first | 2343 | ;; The list must contain 3 strings, where the first |
| 2333 | ;; is the input prompt, the second is the block | 2344 | ;; is the input prompt, the second is the block |
| 2334 | ;; prompt and the last one is the output prompt. The | 2345 | ;; prompt and the last one is the output prompt. The |