0

When I call run-python from the package python.el Emacs displays me the following error:

error in process filter: Wrong type argument: number-or-marker-p, nil

To investigate further I called toggle-debug-on-error. This is the output that Emacs gives me when I call run-python:

Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
  ad-Advice-comint-output-filter(#f(compiled-function (process string) #<bytecode 0x4225bda9>) #<process Python> "Python 3.6.5 (default, Mar 30 2018, 06:41:53) \n[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n")
  apply(ad-Advice-comint-output-filter #f(compiled-function (process string) #<bytecode 0x4225bda9>) (#<process Python> "Python 3.6.5 (default, Mar 30 2018, 06:41:53) \n[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n"))
  comint-output-filter(#<process Python> "Python 3.6.5 (default, Mar 30 2018, 06:41:53) \n[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n")

This is my Python configuration. Have you got an idea of what the problem could be? Thank you!

(require 'python)
(setq python-indent-offset 4)
(add-hook 'python-mode-hook
      (lambda ()
        (setq indent-tabs-mode t)
        (setq tab-width 4)
        (setq python-indent 4)))

(setq scroll-down-aggressively 1)

(setq py-split-window-on-execute nil)
(define-key python-mode-map (kbd "C-c C-c")
  (lambda () (interactive) (python-shell-send-buffer t)))

(defun python-shell-parse-command ()
  "Return the string used to execute the inferior Python process."
  "/usr/bin/python3 -i")

(setq py-python-command "python3")
(setq py-shell-name "python3")
(setq python-shell-interpreter "python3")
(global-set-key (kbd "C-c C-<backspace>") '(lambda () (interactive) (kill-process "*Python*")))

(with-eval-after-load 'python
  (defun python-shell-completion-native-try ()
    "Return non-nil if can trigger native completion."
    (let ((python-shell-completion-native-enable t)
          (python-shell-completion-native-output-timeout
           python-shell-completion-native-try-output-timeout))
      (python-shell-completion-native-get-completions
       (get-buffer-process (current-buffer))
       nil "_"))))

UPDATE 1:

Actually, I think that the problem is hidden in this function that I have in my configuration file:

(defun visit-shell2 ()
  "Create or visit a `shell' buffer."
  (interactive)
  (if (not (get-buffer "*shell*<2>"))
      (progn
        (split-window-sensibly (selected-window))
        (other-window 1)
        (lambda () (interactive) (switch-to-buffer "*shell*<2>")))
    (switch-to-buffer-other-window "*shell*<2>")))
(global-set-key (kbd "C-c s") 'shell)
;(global-set-key (kbd "C-c d") #'(lambda () (interactive) (switch-to-buffer "*shell*<2>")))
(global-set-key (kbd "C-c d") #'(lambda () (interactive) (visit-shell2)))
;; (setq comint-prompt-read-only t)
(use-package comint
  :demand t
  :config
  ;; Make processes’ outputs read-only. The prompt is easy.
  (setq comint-prompt-read-only t)
  ;; Outputs. Now you cannot delete them, but they still can be interleaved with some other text.
  (add-hook 'comint-preoutput-filter-functions
            (lambda (text)
              (propertize text 'read-only t)))
  ;; So we need tackle rear-nonsticky:
  (defadvice comint-output-filter (after michalrus/comint-output-read-only activate)
    (let* ((start-marker comint-last-output-start)
           (proc (get-buffer-process (current-buffer)))
           (end-marker (if proc (process-mark proc) (point-max-marker))))
      (when (< start-marker end-marker) ;; Account for some of the IELM’s wilderness.
        (let ((inhibit-read-only t))
          ;; Disallow interleaving.
          (remove-text-properties start-marker (1- end-marker) '(rear-nonsticky))
          ;; Make sure that at `max-point' you can always append.
          ;; Important for bad REPLs that keep writing after giving us prompt (e.g. sbt).
          (add-text-properties (1- end-marker) end-marker '(rear-nonsticky t))
          ;; Protect fence (newline of input, just before output).
          (when (eq (char-before start-marker) ?\n)
            (remove-text-properties (1- start-marker) start-marker '(rear-nonsticky))
            (add-text-properties    (1- start-marker) start-marker '(read-only t))))))
    ;; What’s left is some initial welcome `insert's and process exit messages, but whatever.
    ))

UPDATE 2: commenting everything from (use-package comint... to the end of the code I gave you is making the problem disappear. It would be interesting to understand which part of the code was giving me troubles. The code I sent you is used in order to make the shell read-only, which now is not read only anymore.

  • Presumably one of comint-last-output-start or (process-mark proc) are giving nil. – npostavs Aug 25 '18 at 16:24

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.