[Python-checkins] python/dist/src/Misc python-mode.el,4.8,4.9

bwarsaw@sourceforge.net bwarsaw@sourceforge.net
Mon, 22 Apr 2002 08:29:31 -0700


Update of /cvsroot/python/python/dist/src/Misc
In directory usw-pr-cvs1:/tmp/cvs-serv3651

Modified Files:
	python-mode.el 
Log Message:
(py-execute-region): If you ran this without having visited a
python-mode file, py-which-shell would have been nil and the command
to use would not get set correctly.  This changes things so that 1)
the temporary file has a .py extension, 2) the temporary file is put
into python-mode, and 3) the temporary file's py-which-shell is
captured in a local `shell' variable, which is used to calculate the
command to use.  Closes SF bug #545436.

(py-parse-state): Rip out the XEmacs-specific calls to
buffer-syntactic-context, which can get quite confused if there's an
open paren in column zero say, embedded in a triple quoted string.
This was always a performance hack anyway, and computers are fast
enough now that we should be able to get away with the slower, more
portable, full-parse branch.  Closes SF bug #451841.

Update the comments at the top of the file.


Index: python-mode.el
===================================================================
RCS file: /cvsroot/python/python/dist/src/Misc/python-mode.el,v
retrieving revision 4.8
retrieving revision 4.9
diff -C2 -d -r4.8 -r4.9
*** python-mode.el	18 Mar 2002 18:53:56 -0000	4.8
--- python-mode.el	22 Apr 2002 15:29:27 -0000	4.9
***************
*** 3,7 ****
  ;; Copyright (C) 1992,1993,1994  Tim Peters
  
! ;; Author: 1995-2001 Barry A. Warsaw
  ;;         1992-1994 Tim Peters
  ;; Maintainer: python-mode@python.org
--- 3,7 ----
  ;; Copyright (C) 1992,1993,1994  Tim Peters
  
! ;; Author: 1995-2002 Barry A. Warsaw
  ;;         1992-1994 Tim Peters
  ;; Maintainer: python-mode@python.org
***************
*** 28,37 ****
  ;; pdbtrack support contributed by Ken Manheimer, April 2001.
  
! ;; This version of python-mode.el has only been tested with XEmacs
! ;; 21.1.14 and Emacs 20.7 as these are the latest versions of these
! ;; Emacsen as of this writing (11-Apr-2001).  I have no intent to test
! ;; it with earlier Emacsen, but I will accept patches if they are
! ;; small and reasonable.  Please use the SourceForge Python project to
! ;; submit bugs or patches:
  ;;
  ;;     http://sourceforge.net/projects/python
--- 28,33 ----
  ;; pdbtrack support contributed by Ken Manheimer, April 2001.
  
! ;; Please use the SourceForge Python project to submit bugs or
! ;; patches:
  ;;
  ;;     http://sourceforge.net/projects/python
***************
*** 43,50 ****
  ;;     http://www.python.org/emacs/python-mode/
  ;;
! ;; but this link is fairly out of date, due to the current difficulty
! ;; in updating that site. It does contain links to other packages that
! ;; you might find useful, such as pdb interfaces, OO-Browser links,
! ;; etc.  Eventually, we'll be able to update it much more easily.
  
  ;; BUG REPORTING:
--- 39,44 ----
  ;;     http://www.python.org/emacs/python-mode/
  ;;
! ;; It does contain links to other packages that you might find useful,
! ;; such as pdb interfaces, OO-Browser links, etc.
  
  ;; BUG REPORTING:
***************
*** 1356,1362 ****
  		       (format "python-%d" sn)))
  		 (make-temp-name "python-")))
! 	 (file (expand-file-name temp py-temp-directory))
  	 (cur (current-buffer))
! 	 (buf (get-buffer-create file)))
      ;; Write the contents of the buffer, watching out for indented regions.
      (save-excursion
--- 1350,1357 ----
  		       (format "python-%d" sn)))
  		 (make-temp-name "python-")))
! 	 (file (concat (expand-file-name temp py-temp-directory) ".py"))
  	 (cur (current-buffer))
! 	 (buf (get-buffer-create file))
! 	 shell)
      ;; Write the contents of the buffer, watching out for indented regions.
      (save-excursion
***************
*** 1364,1367 ****
--- 1359,1364 ----
        (let ((needs-if (/= (py-point 'bol) (py-point 'boi))))
  	(set-buffer buf)
+ 	(python-mode)
+ 	(setq shell py-which-shell)
  	(when needs-if
  	  (insert "if 1:\n"))
***************
*** 1378,1382 ****
  	     (arg (if (string-equal py-which-bufname "Python")
  		      "-u" "")))
! 	(start-process py-which-bufname buf py-which-shell arg file)
  	(pop-to-buffer buf)
  	(py-postprocess-output-buffer buf)
--- 1375,1379 ----
  	     (arg (if (string-equal py-which-bufname "Python")
  		      "-u" "")))
! 	(start-process py-which-bufname buf shell arg file)
  	(pop-to-buffer buf)
  	(py-postprocess-output-buffer buf)
***************
*** 1397,1401 ****
       (t
        ;; TBD: a horrible hack, buy why create new Custom variables?
!       (let ((cmd (concat py-which-shell
  			 (if (string-equal py-which-bufname "JPython")
  			     " -" ""))))
--- 1394,1398 ----
       (t
        ;; TBD: a horrible hack, buy why create new Custom variables?
!       (let ((cmd (concat shell
  			 (if (string-equal py-which-bufname "JPython")
  			     " -" ""))))
***************
*** 2910,2914 ****
    (save-excursion
      (let ((here (point))
! 	  in-listcomp pps done)
        (while (not done)
  	;; back up to the first preceding line (if any; else start of
--- 2907,2911 ----
    (save-excursion
      (let ((here (point))
! 	  pps done)
        (while (not done)
  	;; back up to the first preceding line (if any; else start of
***************
*** 2919,2929 ****
  	;; write huge code blocks or huge lists ... tough beans.
  	(re-search-backward py-parse-state-re nil 'move)
- 	;; Watch out for landing inside a list comprehension
- 	(save-excursion
- 	  (if (and (looking-at "[ \t]*\\<\\(if\\|for\\)\\>")
- 		   (py-safe (progn (up-list -1) t))
- 		   (eq (char-after) ?\[))
- 	      (setq in-listcomp (point))
- 	    (setq in-listcomp nil)))
  	(beginning-of-line)
  	;; In XEmacs, we have a much better way to test for whether
--- 2916,2919 ----
***************
*** 2932,2957 ****
  	;; without scanning from the beginning of the buffer, there's
  	;; no accurate way to determine this otherwise.
! 	(if (not (fboundp 'buffer-syntactic-context))
! 	    ;; Emacs
! 	    (progn
! 	      (save-excursion (setq pps (parse-partial-sexp (point) here)))
! 	      ;; make sure we don't land inside a triple-quoted string
! 	      (setq done (or (not (nth 3 pps))
! 			     (bobp)))
! 	      ;; Just go ahead and short circuit the test back to the
! 	      ;; beginning of the buffer.  This will be slow, but not
! 	      ;; nearly as slow as looping through many
! 	      ;; re-search-backwards.
! 	      (if (not done)
! 		  (goto-char (point-min))))
! 	  ;; XEmacs
! 	  (setq done (or (not (buffer-syntactic-context))
! 			 (bobp)))
! 	  (when in-listcomp
! 	    (goto-char in-listcomp)
! 	    (setq done nil))
! 	  (when done
! 	    (setq pps (parse-partial-sexp (point) here)))
! 	  ))
        pps)))
  
--- 2922,2935 ----
  	;; without scanning from the beginning of the buffer, there's
  	;; no accurate way to determine this otherwise.
! 	(save-excursion (setq pps (parse-partial-sexp (point) here)))
! 	;; make sure we don't land inside a triple-quoted string
! 	(setq done (or (not (nth 3 pps))
! 		       (bobp)))
! 	;; Just go ahead and short circuit the test back to the
! 	;; beginning of the buffer.  This will be slow, but not
! 	;; nearly as slow as looping through many
! 	;; re-search-backwards.
! 	(if (not done)
! 	    (goto-char (point-min))))
        pps)))