diff options
| author | Ken Manheimer | 2008-02-22 17:49:48 +0000 |
|---|---|---|
| committer | Ken Manheimer | 2008-02-22 17:49:48 +0000 |
| commit | f7aa70c758c188e700ac303518f48f116e3e40c9 (patch) | |
| tree | 52206bc630e395d2ecadee478d68d7f35d57bd61 /lisp/progmodes/python.el | |
| parent | 6087292e62fe822459b8cdb863e10d686a53a937 (diff) | |
| download | emacs-f7aa70c758c188e700ac303518f48f116e3e40c9.tar.gz emacs-f7aa70c758c188e700ac303518f48f116e3e40c9.zip | |
Finish pdbtrack integration cleanup, settling missing-functions
byte compiler warnings appropriately.
* progmodes/python.el (python-point): Remove this - beginning-of-line was
all that was necessary for `python-pdbtrack-overlay-arrow'.
(python-end-of-def-or-class, python-beginning-of-def-or-class)
(python-goto-initial-line): Drop these - they were only needed for
python-point.
(python-comint-output-filter-function): Use condition-case and
beginning-of-line directly, instead of python-mode.el functions
which require all sorts of baggage.
(point-safe): Unnecessary - we're using condition-case directly,
instead.
(python-execute-file): Include for python-shell, which i'm leaving
in keeping despite it being unnecessary for pdb tracking.
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 183 |
1 files changed, 25 insertions, 158 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 1b6632e0c29..e9f3dafa2f0 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -2547,162 +2547,6 @@ Runs `jython-mode-hook' after `python-mode-hook'." | |||
| 2547 | 2547 | ||
| 2548 | ;; pdbtrack features | 2548 | ;; pdbtrack features |
| 2549 | 2549 | ||
| 2550 | (defsubst python-point (position) | ||
| 2551 | "Returns the value of point at certain commonly referenced POSITIONs. | ||
| 2552 | POSITION can be one of the following symbols: | ||
| 2553 | |||
| 2554 | bol -- beginning of line | ||
| 2555 | eol -- end of line | ||
| 2556 | bod -- beginning of def or class | ||
| 2557 | eod -- end of def or class | ||
| 2558 | bob -- beginning of buffer | ||
| 2559 | eob -- end of buffer | ||
| 2560 | boi -- back to indentation | ||
| 2561 | bos -- beginning of statement | ||
| 2562 | |||
| 2563 | This function does not modify point or mark." | ||
| 2564 | (let ((here (point))) | ||
| 2565 | (cond | ||
| 2566 | ((eq position 'bol) (beginning-of-line)) | ||
| 2567 | ((eq position 'eol) (end-of-line)) | ||
| 2568 | ((eq position 'bod) (python-beginning-of-def-or-class)) | ||
| 2569 | ((eq position 'eod) (python-end-of-def-or-class)) | ||
| 2570 | ;; Kind of funny, I know, but useful for python-up-exception. | ||
| 2571 | ((eq position 'bob) (goto-char (point-min))) | ||
| 2572 | ((eq position 'eob) (goto-char (point-max))) | ||
| 2573 | ((eq position 'boi) (back-to-indentation)) | ||
| 2574 | ((eq position 'bos) (python-goto-initial-line)) | ||
| 2575 | (t (error "Unknown buffer position requested: %s" position))) | ||
| 2576 | (prog1 | ||
| 2577 | (point) | ||
| 2578 | (goto-char here)))) | ||
| 2579 | |||
| 2580 | (defun python-end-of-def-or-class (&optional class count) | ||
| 2581 | "Move point beyond end of `def' or `class' body. | ||
| 2582 | |||
| 2583 | By default, looks for an appropriate `def'. If you supply a prefix | ||
| 2584 | arg, looks for a `class' instead. The docs below assume the `def' | ||
| 2585 | case; just substitute `class' for `def' for the other case. | ||
| 2586 | Programmatically, if CLASS is `either', then moves to either `class' | ||
| 2587 | or `def'. | ||
| 2588 | |||
| 2589 | When second optional argument is given programmatically, move to the | ||
| 2590 | COUNTth end of `def'. | ||
| 2591 | |||
| 2592 | If point is in a `def' statement already, this is the `def' we use. | ||
| 2593 | |||
| 2594 | Else, if the `def' found by `\\[python-beginning-of-def-or-class]' | ||
| 2595 | contains the statement you started on, that's the `def' we use. | ||
| 2596 | |||
| 2597 | Otherwise, we search forward for the closest following `def', and use that. | ||
| 2598 | |||
| 2599 | If a `def' can be found by these rules, point is moved to the start of | ||
| 2600 | the line immediately following the `def' block, and the position of the | ||
| 2601 | start of the `def' is returned. | ||
| 2602 | |||
| 2603 | Else point is moved to the end of the buffer, and nil is returned. | ||
| 2604 | |||
| 2605 | Note that doing this command repeatedly will take you closer to the | ||
| 2606 | end of the buffer each time. | ||
| 2607 | |||
| 2608 | To mark the current `def', see `\\[python-mark-def-or-class]'." | ||
| 2609 | (interactive "P") ; raw prefix arg | ||
| 2610 | (if (and count (/= count 1)) | ||
| 2611 | (python-beginning-of-def-or-class (- 1 count))) | ||
| 2612 | (let ((start (progn (python-goto-initial-line) (point))) | ||
| 2613 | (which (cond ((eq class 'either) "\\(class\\|def\\)") | ||
| 2614 | (class "class") | ||
| 2615 | (t "def"))) | ||
| 2616 | (state 'not-found)) | ||
| 2617 | ;; move point to start of appropriate def/class | ||
| 2618 | (if (looking-at (concat "[ \t]*" which "\\>")) ; already on one | ||
| 2619 | (setq state 'at-beginning) | ||
| 2620 | ;; else see if python-beginning-of-def-or-class hits container | ||
| 2621 | (if (and (python-beginning-of-def-or-class class) | ||
| 2622 | (progn (python-goto-beyond-block) | ||
| 2623 | (> (point) start))) | ||
| 2624 | (setq state 'at-end) | ||
| 2625 | ;; else search forward | ||
| 2626 | (goto-char start) | ||
| 2627 | (if (re-search-forward (concat "^[ \t]*" which "\\>") nil 'move) | ||
| 2628 | (progn (setq state 'at-beginning) | ||
| 2629 | (beginning-of-line))))) | ||
| 2630 | (cond | ||
| 2631 | ((eq state 'at-beginning) (python-goto-beyond-block) t) | ||
| 2632 | ((eq state 'at-end) t) | ||
| 2633 | ((eq state 'not-found) nil) | ||
| 2634 | (t (error "Internal error in `python-end-of-def-or-class'"))))) | ||
| 2635 | |||
| 2636 | (defun python-beginning-of-def-or-class (&optional class count) | ||
| 2637 | "Move point to start of `def' or `class'. | ||
| 2638 | |||
| 2639 | Searches back for the closest preceding `def'. If you supply a prefix | ||
| 2640 | arg, looks for a `class' instead. The docs below assume the `def' | ||
| 2641 | case; just substitute `class' for `def' for the other case. | ||
| 2642 | Programmatically, if CLASS is `either', then moves to either `class' | ||
| 2643 | or `def'. | ||
| 2644 | |||
| 2645 | When second optional argument is given programmatically, move to the | ||
| 2646 | COUNTth start of `def'. | ||
| 2647 | |||
| 2648 | If point is in a `def' statement already, and after the `d', simply | ||
| 2649 | moves point to the start of the statement. | ||
| 2650 | |||
| 2651 | Otherwise (i.e. when point is not in a `def' statement, or at or | ||
| 2652 | before the `d' of a `def' statement), searches for the closest | ||
| 2653 | preceding `def' statement, and leaves point at its start. If no such | ||
| 2654 | statement can be found, leaves point at the start of the buffer. | ||
| 2655 | |||
| 2656 | Returns t iff a `def' statement is found by these rules. | ||
| 2657 | |||
| 2658 | Note that doing this command repeatedly will take you closer to the | ||
| 2659 | start of the buffer each time. | ||
| 2660 | |||
| 2661 | To mark the current `def', see `\\[python-mark-def-or-class]'." | ||
| 2662 | (interactive "P") ; raw prefix arg | ||
| 2663 | (setq count (or count 1)) | ||
| 2664 | (let ((at-or-before-p (<= (current-column) (current-indentation))) | ||
| 2665 | (start-of-line (goto-char (python-point 'bol))) | ||
| 2666 | (start-of-stmt (goto-char (python-point 'bos))) | ||
| 2667 | (start-re (cond ((eq class 'either) "^[ \t]*\\(class\\|def\\)\\>") | ||
| 2668 | (class "^[ \t]*class\\>") | ||
| 2669 | (t "^[ \t]*def\\>")))) | ||
| 2670 | ;; searching backward | ||
| 2671 | (if (and (< 0 count) | ||
| 2672 | (or (/= start-of-stmt start-of-line) | ||
| 2673 | (not at-or-before-p))) | ||
| 2674 | (end-of-line)) | ||
| 2675 | ;; search forward | ||
| 2676 | (if (and (> 0 count) | ||
| 2677 | (zerop (current-column)) | ||
| 2678 | (looking-at start-re)) | ||
| 2679 | (end-of-line)) | ||
| 2680 | (if (re-search-backward start-re nil 'move count) | ||
| 2681 | (goto-char (match-beginning 0))))) | ||
| 2682 | |||
| 2683 | (defun python-goto-initial-line () | ||
| 2684 | "Go to the initial line of the current statement. | ||
| 2685 | Usually this is the line we're on, but if we're on the 2nd or | ||
| 2686 | following lines of a continuation block, we need to go up to the first | ||
| 2687 | line of the block." | ||
| 2688 | ;; Tricky: We want to avoid quadratic-time behavior for long | ||
| 2689 | ;; continued blocks, whether of the backslash or open-bracket | ||
| 2690 | ;; varieties, or a mix of the two. The following manages to do that | ||
| 2691 | ;; in the usual cases. | ||
| 2692 | ;; | ||
| 2693 | ;; Also, if we're sitting inside a triple quoted string, this will | ||
| 2694 | ;; drop us at the line that begins the string. | ||
| 2695 | (let (open-bracket-pos) | ||
| 2696 | (while (python-continuation-line-p) | ||
| 2697 | (beginning-of-line) | ||
| 2698 | (if (python-backslash-continuation-line-p) | ||
| 2699 | (while (python-backslash-continuation-line-p) | ||
| 2700 | (forward-line -1)) | ||
| 2701 | ;; else zip out of nested brackets/braces/parens | ||
| 2702 | (while (setq open-bracket-pos (python-nesting-level)) | ||
| 2703 | (goto-char open-bracket-pos))))) | ||
| 2704 | (beginning-of-line)) | ||
| 2705 | |||
| 2706 | (defun python-comint-output-filter-function (string) | 2550 | (defun python-comint-output-filter-function (string) |
| 2707 | "Watch output for Python prompt and exec next file waiting in queue. | 2551 | "Watch output for Python prompt and exec next file waiting in queue. |
| 2708 | This function is appropriate for `comint-output-filter-functions'." | 2552 | This function is appropriate for `comint-output-filter-functions'." |
| @@ -2711,7 +2555,9 @@ This function is appropriate for `comint-output-filter-functions'." | |||
| 2711 | (and (>= (length string) 5) | 2555 | (and (>= (length string) 5) |
| 2712 | (string-equal (substring string -5) "\n>>> "))) | 2556 | (string-equal (substring string -5) "\n>>> "))) |
| 2713 | python-file-queue) | 2557 | python-file-queue) |
| 2714 | (python-safe (delete-file (car python-file-queue))) | 2558 | (condition-case nil |
| 2559 | (delete-file (car python-file-queue)) | ||
| 2560 | (error nil)) | ||
| 2715 | (setq python-file-queue (cdr python-file-queue)) | 2561 | (setq python-file-queue (cdr python-file-queue)) |
| 2716 | (if python-file-queue | 2562 | (if python-file-queue |
| 2717 | (let ((pyproc (get-buffer-process (current-buffer)))) | 2563 | (let ((pyproc (get-buffer-process (current-buffer)))) |
| @@ -2725,7 +2571,8 @@ This function is appropriate for `comint-output-filter-functions'." | |||
| 2725 | overlay-arrow-string "=>" | 2571 | overlay-arrow-string "=>" |
| 2726 | python-pdbtrack-is-tracking-p t) | 2572 | python-pdbtrack-is-tracking-p t) |
| 2727 | (set-marker overlay-arrow-position | 2573 | (set-marker overlay-arrow-position |
| 2728 | (python-point 'bol) (current-buffer))) | 2574 | (save-excursion (beginning-of-line) (point)) |
| 2575 | (current-buffer))) | ||
| 2729 | (setq overlay-arrow-position nil | 2576 | (setq overlay-arrow-position nil |
| 2730 | python-pdbtrack-is-tracking-p nil))) | 2577 | python-pdbtrack-is-tracking-p nil))) |
| 2731 | 2578 | ||
| @@ -2900,6 +2747,26 @@ Programmatically, ARG can also be one of the symbols `cpython' or | |||
| 2900 | mode-name "JPython"))) | 2747 | mode-name "JPython"))) |
| 2901 | (message "Using the %s shell" msg))) | 2748 | (message "Using the %s shell" msg))) |
| 2902 | 2749 | ||
| 2750 | ;; Python subprocess utilities and filters | ||
| 2751 | (defun python-execute-file (proc filename) | ||
| 2752 | "Send to Python interpreter process PROC \"execfile('FILENAME')\". | ||
| 2753 | Make that process's buffer visible and force display. Also make | ||
| 2754 | comint believe the user typed this string so that | ||
| 2755 | `kill-output-from-shell' does The Right Thing." | ||
| 2756 | (let ((curbuf (current-buffer)) | ||
| 2757 | (procbuf (process-buffer proc)) | ||
| 2758 | ; (comint-scroll-to-bottom-on-output t) | ||
| 2759 | (msg (format "## working on region in file %s...\n" filename)) | ||
| 2760 | ;; add some comment, so that we can filter it out of history | ||
| 2761 | (cmd (format "execfile(r'%s') # PYTHON-MODE\n" filename))) | ||
| 2762 | (unwind-protect | ||
| 2763 | (save-excursion | ||
| 2764 | (set-buffer procbuf) | ||
| 2765 | (goto-char (point-max)) | ||
| 2766 | (move-marker (process-mark proc) (point)) | ||
| 2767 | (funcall (process-filter proc) proc msg)) | ||
| 2768 | (set-buffer curbuf)) | ||
| 2769 | (process-send-string proc cmd))) | ||
| 2903 | ;;;###autoload | 2770 | ;;;###autoload |
| 2904 | (defun python-shell (&optional argprompt) | 2771 | (defun python-shell (&optional argprompt) |
| 2905 | "Start an interactive Python interpreter in another window. | 2772 | "Start an interactive Python interpreter in another window. |