 		      base-text   (py-suck-up-leading-text)
 		      base-found-p t))
 	    (error nil))
-	  (setq count (1- count))))
+	  (setq arg (1- arg))))
       (delete-char 1)			; toss the dummy character
       (delete-horizontal-space)
       (indent-to base-indent)
       (if base-found-p
 	  (message "Closes block: %s" base-text)))))
 
+
+(defun py-electric-delete (arg)
+  "Deletes preceding or following character or levels of whitespace.
+
+The behavior of this function depends on the variable
+`delete-key-deletes-forward'.  If this variable is nil (or does not
+exist, as in older Emacsen), then this function behaves identical to
+\\[c-electric-backspace].
+
+If `delete-key-deletes-forward' is non-nil and is supported in your
+Emacs, then deletion occurs in the forward direction, by calling the
+function in `py-delete-function'."
+  (interactive "*p")
+  (if (and (boundp 'delete-key-deletes-forward)
+	   delete-key-deletes-forward)
+      (funcall py-delete-function arg)
+    ;; else
+    (py-electric-backspace arg)))
+
 ;; required for pending-del and delsel modes
-(put 'py-delete-char 'delete-selection 'supersede)
-(put 'py-delete-char 'pending-delete   'supersede)
+(put 'py-electric-backspace 'delete-selection 'supersede) ;delsel
+(put 'py-electric-backspace 'pending-delete   'supersede) ;pending-del
+(put 'py-electric-delete    'delete-selection 'supersede) ;delsel
+(put 'py-electric-delete    'pending-delete   'supersede) ;pending-del
+
+
+ 
 (defun py-indent-line (&optional arg)
   "Fix the indentation of the current line according to Python rules.

  "Queue of Python temp files awaiting execution.
Currently-active file is at the head of the list.")

(defvar py-delete-function 'backward-delete-char-untabify
  "*Function called by `py-delete-char' when deleting characters.")

(defvar py-backspace-function 'backward-delete-char-untabify
  "*Function called by `py-backspace-command' when deleting characters.")


;; Constants



;; Electric deletion
(defun py-electric-backspace (arg)
  "Deletes preceding character or levels of indentation.
Deletion is performed by calling the function in `py-backspace-function'
with a single argument (the number of characters to delete).

If point is at the leftmost column, deletes the preceding newline.

Otherwise, if point is at the leftmost non-whitespace character of a
line that is neither a continuation line nor a non-indenting comment
line, or if point is at the end of a blank line, this command reduces
the indentation to match that of the line that opened the current
block of code.  The line that opened the block is displayed in the
echo area to help you keep track of where you are.  With numeric arg,
outdents that many blocks (but not past column zero).

Otherwise the preceding character is deleted, converting a tab to
spaces if needed so that only a single column position is deleted.
Numeric argument deletes that many preceding characters."
  (interactive "*p")
  (if (or (/= (current-indentation) (current-column))
	  (bolp)
	  (py-continuation-line-p)
	  (not py-honor-comment-indentation)
	  (looking-at "#[^ \t\n]"))	; non-indenting #
      (funcall py-backspace-function arg)
    ;; else indent the same as the colon line that opened the block
    ;; force non-blank so py-goto-block-up doesn't ignore it
    (insert-char ?* 1)
    (backward-char)
