Skip to content

Error occurred when sending an indented cell #3

Open

Description

@bamanzi

When sending an indented cell (e.g. a block in a method of a class), Python shell would throw IndentationError: unexpected indent

I figured out a hack to fix this problem( by prefixing a line 'if True:\n'):

(defun python-shell-send-cell ()
  "Send the cell the cursor is in to the inferior Python process."
  (interactive)
  (let* (
         (start (save-excursion (python-beginning-of-cell)
                               (point)))
         (end (save-excursion (python-end-of-cell)
                             (point)))
         (content  (buffer-substring start end))

         (preline "if True:\n")

         (line-num (line-number-at-pos start))
         ;; When sending a region, add blank lines for non sent code so
         ;; backtraces remain correct.         
         (postline (make-string (1- line-num) ?\n)))
    ;;(message "DEBUG: %s" (substring content 0 4))
    (python-shell-send-string (concat (if (string= (substring content 0 2) "  ")
                                          preline
                                        "")
                                      content
                                      postline))))

Activity

  1. added a commit that references this issue on Mar 15, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions