Emacs24 + Pymacs -f switch with pymacs-load-path redundant?
Question: I've upgraded to Emacs24 and, when launching Pymacs it would break because of
timeout.

Below is the backtrace:

    
    
    Debugger entered--Lisp error: (error "Pymacs helper did not start within 30 seconds")
      signal(error ("Pymacs helper did not start within 30 seconds"))
      pymacs-report-error("Pymacs helper did not start within %d seconds" 30)
      (if (accept-process-output process pymacs-timeout-at-start) nil (pymacs-report-error "Pymacs helper did not start within %d seconds" pymacs-timeout-at-start))
      (unless (accept-process-output process pymacs-timeout-at-start) (pymacs-report-error "Pymacs helper did not start within %d seconds" pymacs-timeout-at-start))
      (while (progn (goto-char (point-min)) (not (re-search-forward "<\\([0-9]+\\)  " nil t))) (unless (accept-process-output process pymacs-timeout-at-start) (pymacs-report-error "Pymacs helper did not start within %d seconds" pymacs-timeout-at-start)))
      (let ((process (apply (quote start-process) "pymacs" buffer (let ((python (getenv "PYMACS_PYTHON"))) (if (or (null python) (equal python "")) "python" python)) "-c" (concat "import sys;" " from Pymacs.pymacs import main;" " main(*sys.argv[1:])") (append (and (>= emacs-major-version 24) (quote ("-f"))) (mapcar (quote expand-file-name) pymacs-load-path))))) (pymacs-kill-without-query process) (while (progn (goto-char (point-min)) (not (re-search-forward "<\\([0-9]+\\)    " nil t))) (unless (accept-process-output process pymacs-timeout-at-start) (pymacs-report-error "Pymacs helper did not start within %d seconds" pymacs-timeout-at-start))) (let ((marker (process-mark process)) (limit-position (+ (match-end 0) (string-to-number (match-string 1))))) (while (< (marker-position marker) limit-position) (unless (accept-process-output process pymacs-timeout-at-start) (pymacs-report-error "Pymacs helper probably was interrupted at start")))))
      (progn (let ((process (apply (quote start-process) "pymacs" buffer (let ((python ...)) (if (or ... ...) "python" python)) "-c" (concat "import sys;" " from Pymacs.pymacs import main;" " main(*sys.argv[1:])") (append (and (>= emacs-major-version 24) (quote ...)) (mapcar (quote expand-file-name) pymacs-load-path))))) (pymacs-kill-without-query process) (while (progn (goto-char (point-min)) (not (re-search-forward "<\\([0-9]+\\) " nil t))) (unless (accept-process-output process pymacs-timeout-at-start) (pymacs-report-error "Pymacs helper did not start within %d seconds" pymacs-timeout-at-start))) (let ((marker (process-mark process)) (limit-position (+ (match-end 0) (string-to-number (match-string 1))))) (while (< (marker-position marker) limit-position) (unless (accept-process-output process pymacs-timeout-at-start) (pymacs-report-error "Pymacs helper probably was interrupted at start"))))) (goto-char (match-end 0)) (let ((reply (read (current-buffer)))) (if (and (pymacs-proper-list-p reply) (= (length reply) 2) (eq (car reply) (quote version))) (unless (string-equal (cadr reply) "0.24-beta2") (pymacs-report-error "Pymacs Lisp version is 0.24-beta2, Python is %s" (cadr reply))) (pymacs-report-error "Pymacs got an invalid initial reply"))))
      (unwind-protect (progn (let ((process (apply (quote start-process) "pymacs" buffer (let (...) (if ... "python" python)) "-c" (concat "import sys;" " from Pymacs.pymacs import main;" " main(*sys.argv[1:])") (append (and ... ...) (mapcar ... pymacs-load-path))))) (pymacs-kill-without-query process) (while (progn (goto-char (point-min)) (not (re-search-forward "<\\([0-9]+\\)    " nil t))) (unless (accept-process-output process pymacs-timeout-at-start) (pymacs-report-error "Pymacs helper did not start within %d seconds" pymacs-timeout-at-start))) (let ((marker (process-mark process)) (limit-position (+ (match-end 0) (string-to-number ...)))) (while (< (marker-position marker) limit-position) (unless (accept-process-output process pymacs-timeout-at-start) (pymacs-report-error "Pymacs helper probably was interrupted at start"))))) (goto-char (match-end 0)) (let ((reply (read (current-buffer)))) (if (and (pymacs-proper-list-p reply) (= (length reply) 2) (eq (car reply) (quote version))) (unless (string-equal (cadr reply) "0.24-beta2") (pymacs-report-error "Pymacs Lisp version is 0.24-beta2, Python is %s" (cadr reply))) (pymacs-report-error "Pymacs got an invalid initial reply")))) (set-match-data save-match-data-internal (quote evaporate)))
      (let ((save-match-data-internal (match-data))) (unwind-protect (progn (let ((process (apply (quote start-process) "pymacs" buffer (let ... ...) "-c" (concat "import sys;" " from Pymacs.pymacs import main;" " main(*sys.argv[1:])") (append ... ...)))) (pymacs-kill-without-query process) (while (progn (goto-char (point-min)) (not (re-search-forward "<\\([0-9]+\\)    " nil t))) (unless (accept-process-output process pymacs-timeout-at-start) (pymacs-report-error "Pymacs helper did not start within %d seconds" pymacs-timeout-at-start))) (let ((marker (process-mark process)) (limit-position (+ ... ...))) (while (< (marker-position marker) limit-position) (unless (accept-process-output process pymacs-timeout-at-start) (pymacs-report-error "Pymacs helper probably was interrupted at start"))))) (goto-char (match-end 0)) (let ((reply (read (current-buffer)))) (if (and (pymacs-proper-list-p reply) (= (length reply) 2) (eq (car reply) (quote version))) (unless (string-equal (cadr reply) "0.24-beta2") (pymacs-report-error "Pymacs Lisp version is 0.24-beta2, Python is %s" (cadr reply))) (pymacs-report-error "Pymacs got an invalid initial reply")))) (set-match-data save-match-data-internal (quote evaporate))))
      (save-match-data (let ((process (apply (quote start-process) "pymacs" buffer (let ((python ...)) (if (or ... ...) "python" python)) "-c" (concat "import sys;" " from Pymacs.pymacs import main;" " main(*sys.argv[1:])") (append (and (>= emacs-major-version 24) (quote ...)) (mapcar (quote expand-file-name) pymacs-load-path))))) (pymacs-kill-without-query process) (while (progn (goto-char (point-min)) (not (re-search-forward "<\\([0-9]+\\)   " nil t))) (unless (accept-process-output process pymacs-timeout-at-start) (pymacs-report-error "Pymacs helper did not start within %d seconds" pymacs-timeout-at-start))) (let ((marker (process-mark process)) (limit-position (+ (match-end 0) (string-to-number (match-string 1))))) (while (< (marker-position marker) limit-position) (unless (accept-process-output process pymacs-timeout-at-start) (pymacs-report-error "Pymacs helper probably was interrupted at start"))))) (goto-char (match-end 0)) (let ((reply (read (current-buffer)))) (if (and (pymacs-proper-list-p reply) (= (length reply) 2) (eq (car reply) (quote version))) (unless (string-equal (cadr reply) "0.24-beta2") (pymacs-report-error "Pymacs Lisp version is 0.24-beta2, Python is %s" (cadr reply))) (pymacs-report-error "Pymacs got an invalid initial reply"))))
      (save-current-buffer (set-buffer buffer) (erase-buffer) (buffer-disable-undo) (pymacs-set-buffer-multibyte nil) (set-buffer-file-coding-system (quote raw-text)) (save-match-data (let ((process (apply (quote start-process) "pymacs" buffer (let (...) (if ... "python" python)) "-c" (concat "import sys;" " from Pymacs.pymacs import main;" " main(*sys.argv[1:])") (append (and ... ...) (mapcar ... pymacs-load-path))))) (pymacs-kill-without-query process) (while (progn (goto-char (point-min)) (not (re-search-forward "<\\([0-9]+\\) " nil t))) (unless (accept-process-output process pymacs-timeout-at-start) (pymacs-report-error "Pymacs helper did not start within %d seconds" pymacs-timeout-at-start))) (let ((marker (process-mark process)) (limit-position (+ (match-end 0) (string-to-number ...)))) (while (< (marker-position marker) limit-position) (unless (accept-process-output process pymacs-timeout-at-start) (pymacs-report-error "Pymacs helper probably was interrupted at start"))))) (goto-char (match-end 0)) (let ((reply (read (current-buffer)))) (if (and (pymacs-proper-list-p reply) (= (length reply) 2) (eq (car reply) (quote version))) (unless (string-equal (cadr reply) "0.24-beta2") (pymacs-report-error "Pymacs Lisp version is 0.24-beta2, Python is %s" (cadr reply))) (pymacs-report-error "Pymacs got an invalid initial reply")))))
      (with-current-buffer buffer (erase-buffer) (buffer-disable-undo) (pymacs-set-buffer-multibyte nil) (set-buffer-file-coding-system (quote raw-text)) (save-match-data (let ((process (apply (quote start-process) "pymacs" buffer (let (...) (if ... "python" python)) "-c" (concat "import sys;" " from Pymacs.pymacs import main;" " main(*sys.argv[1:])") (append (and ... ...) (mapcar ... pymacs-load-path))))) (pymacs-kill-without-query process) (while (progn (goto-char (point-min)) (not (re-search-forward "<\\([0-9]+\\)  " nil t))) (unless (accept-process-output process pymacs-timeout-at-start) (pymacs-report-error "Pymacs helper did not start within %d seconds" pymacs-timeout-at-start))) (let ((marker (process-mark process)) (limit-position (+ (match-end 0) (string-to-number ...)))) (while (< (marker-position marker) limit-position) (unless (accept-process-output process pymacs-timeout-at-start) (pymacs-report-error "Pymacs helper probably was interrupted at start"))))) (goto-char (match-end 0)) (let ((reply (read (current-buffer)))) (if (and (pymacs-proper-list-p reply) (= (length reply) 2) (eq (car reply) (quote version))) (unless (string-equal (cadr reply) "0.24-beta2") (pymacs-report-error "Pymacs Lisp version is 0.24-beta2, Python is %s" (cadr reply))) (pymacs-report-error "Pymacs got an invalid initial reply")))))
      (let ((buffer (get-buffer-create "*Pymacs*"))) (with-current-buffer buffer (erase-buffer) (buffer-disable-undo) (pymacs-set-buffer-multibyte nil) (set-buffer-file-coding-system (quote raw-text)) (save-match-data (let ((process (apply (quote start-process) "pymacs" buffer (let ... ...) "-c" (concat "import sys;" " from Pymacs.pymacs import main;" " main(*sys.argv[1:])") (append ... ...)))) (pymacs-kill-without-query process) (while (progn (goto-char (point-min)) (not (re-search-forward "<\\([0-9]+\\)  " nil t))) (unless (accept-process-output process pymacs-timeout-at-start) (pymacs-report-error "Pymacs helper did not start within %d seconds" pymacs-timeout-at-start))) (let ((marker (process-mark process)) (limit-position (+ ... ...))) (while (< (marker-position marker) limit-position) (unless (accept-process-output process pymacs-timeout-at-start) (pymacs-report-error "Pymacs helper probably was interrupted at start"))))) (goto-char (match-end 0)) (let ((reply (read (current-buffer)))) (if (and (pymacs-proper-list-p reply) (= (length reply) 2) (eq (car reply) (quote version))) (unless (string-equal (cadr reply) "0.24-beta2") (pymacs-report-error "Pymacs Lisp version is 0.24-beta2, Python is %s" (cadr reply))) (pymacs-report-error "Pymacs got an invalid initial reply"))))) (if (not pymacs-use-hash-tables) (setq pymacs-weak-hash t) (when pymacs-used-ids (let ((pymacs-transit-buffer buffer) (pymacs-forget-mutability t) (pymacs-gc-inhibit t)) (pymacs-apply "zombie_python" pymacs-used-ids)) (setq pymacs-used-ids nil)) (setq pymacs-weak-hash (make-hash-table :weakness (quote value))) (if (boundp (quote post-gc-hook)) (add-hook (quote post-gc-hook) (quote pymacs-schedule-gc)) (setq pymacs-gc-timer (run-at-time 20 20 (quote pymacs-schedule-gc))))) (setq pymacs-transit-buffer buffer))
      pymacs-start-services()
      (if (and pymacs-transit-buffer (buffer-name pymacs-transit-buffer) (get-buffer-process pymacs-transit-buffer)) nil (when pymacs-weak-hash (unless (or (eq pymacs-auto-restart t) (and (eq pymacs-auto-restart (quote ask)) (yes-or-no-p "The Pymacs helper died.  Restart it? "))) (pymacs-report-error "There is no Pymacs helper!"))) (pymacs-start-services))
      (unless (and pymacs-transit-buffer (buffer-name pymacs-transit-buffer) (get-buffer-process pymacs-transit-buffer)) (when pymacs-weak-hash (unless (or (eq pymacs-auto-restart t) (and (eq pymacs-auto-restart (quote ask)) (yes-or-no-p "The Pymacs helper died.  Restart it? "))) (pymacs-report-error "There is no Pymacs helper!"))) (pymacs-start-services))
      pymacs-serve-until-reply("eval" (pymacs-print-for-apply (quote "pymacs_load_helper") (quote ("ropemacs" "rope-"))))
      pymacs-call("pymacs_load_helper" "ropemacs" "rope-")
      (let ((lisp-code (pymacs-call "pymacs_load_helper" module prefix))) (cond (lisp-code (let ((result (eval lisp-code))) (message "Pymacs loading %s...done" module) result)) (noerror (message "Pymacs loading %s...failed" module) nil) (t (pymacs-report-error "Pymacs loading %s...failed" module))))
      pymacs-load("ropemacs" "rope-")
      eval-buffer(#<buffer  *load*> nil "/home/wvxvw/.emacs" nil t)  ; Reading at buffer position 11007
      load-with-code-conversion("/home/wvxvw/.emacs" "/home/wvxvw/.emacs" t t)
      load("~/.emacs" t t)
      #[0 "\205\262
    

I then looked into:

    
    
    (defun pymacs-start-services ()
      ;; This function gets called automatically, as needed.
      (let ((buffer (get-buffer-create "*Pymacs*")))
        (with-current-buffer buffer
          ;; Erase the buffer in case some previous incarnation of the
          ;; Pymacs helper died.  Otherwise, the "(goto-char (point-min))"
          ;; below might not find the proper synchronising reply and later
          ;; trigger a spurious "Protocol error" diagnostic.
          (erase-buffer)
          (buffer-disable-undo)
          (pymacs-set-buffer-multibyte nil)
          (set-buffer-file-coding-system 'raw-text)
          (save-match-data
            ;; Launch the Pymacs helper.
            (let ((process
                   (apply 'start-process "pymacs" buffer
                          (let ((python (getenv "PYMACS_PYTHON")))
                            (if (or (null python) (equal python ""))
                                "python"
                              python))
                          "-c" (concat "import sys;"
                                       " from Pymacs.pymacs import main;"
                                       " main(*sys.argv[1:])")
                          (append
                           (and (>= emacs-major-version 24) '("-f"))
                           (mapcar 'expand-file-name pymacs-load-path)))))
              (pymacs-kill-without-query process)
              ;; Receive the synchronising reply.
              (while (progn
                       (goto-char (point-min))
                       (not (re-search-forward "<\\([0-9]+\\)\t" nil t)))
                (unless (accept-process-output process pymacs-timeout-at-start)
                  (pymacs-report-error
                   "Pymacs helper did not start within %d seconds"
                         pymacs-timeout-at-start)))
              (let ((marker (process-mark process))
                    (limit-position (+ (match-end 0)
                                       (string-to-number (match-string 1)))))
                (while (< (marker-position marker) limit-position)
                  (unless (accept-process-output process pymacs-timeout-at-start)
                    (pymacs-report-error
                     "Pymacs helper probably was interrupted at start")))))
            ;; Check that synchronisation occurred.
            (goto-char (match-end 0))
            (let ((reply (read (current-buffer))))
              (if (and (pymacs-proper-list-p reply)
                       (= (length reply) 2)
                       (eq (car reply) 'version))
                  (unless (string-equal (cadr reply) "0.24-beta2")
                    (pymacs-report-error
                     "Pymacs Lisp version is 0.24-beta2, Python is %s"
                     (cadr reply)))
                (pymacs-report-error "Pymacs got an invalid initial reply")))))
        (if (not pymacs-use-hash-tables)
            (setq pymacs-weak-hash t)
          (when pymacs-used-ids
            ;; A previous Pymacs session occurred in this Emacs session,
            ;; some IDs hang around which do not correspond to anything on
            ;; the Python side.  Python should not recycle such IDs for
            ;; new objects.
            (let ((pymacs-transit-buffer buffer)
                  (pymacs-forget-mutability t)
                  (pymacs-gc-inhibit t))
              (pymacs-apply "zombie_python" pymacs-used-ids))
            (setq pymacs-used-ids nil))
          (setq pymacs-weak-hash (make-hash-table :weakness 'value))
          (if (boundp 'post-gc-hook)
              (add-hook 'post-gc-hook 'pymacs-schedule-gc)
            (setq pymacs-gc-timer (run-at-time 20 20 'pymacs-schedule-gc))))
        ;; If nothing failed, only then declare that Pymacs has started!
        (setq pymacs-transit-buffer buffer)))
    

The part below `;; Launch the Pymacs helper.` I then tried to reproduce it by
simply running the same command in console:

    
    
    wvxvw@wvxvw-desktop:~$ python -c 'import sys;
    from Pymacs.pymacs import main;
    main(*sys.argv[1:])' -f "/home/wvxvw/programs/pymacs/" "/home/wvxvw/programs/rope-0.9.3/" "/home/wvxvw/programs/ropemacs/" "/home/wvxvw/programs/ropemode/"
    > > Traceback (most recent call last):
      File "<string>", line 3, in <module>
      File "/usr/lib/python2.7/dist-packages/Pymacs/pymacs.py", line 57, in main
        options, arguments = getopt.getopt(arguments, 'd:s:')
      File "/usr/lib/python2.7/getopt.py", line 90, in getopt
        opts, args = do_shorts(opts, args[0][1:], shortopts, args[1:])
      File "/usr/lib/python2.7/getopt.py", line 190, in do_shorts
        if short_has_arg(opt, shortopts):
      File "/usr/lib/python2.7/getopt.py", line 206, in short_has_arg
        raise GetoptError('option -%s not recognized' % opt, opt)
    getopt.GetoptError: option -f not recognized
    

If I remove `-f` switch, it seems to work fine (as it used to!). My question
is thus: why was this switch needed? I might have done something else wrong,
if this switch was needed, but it doesn't work for me?

If I then comment out the `-f` switch, it fails on version check:

~~`Debugger entered--Lisp error: (error "Pymacs Lisp version is 0.24-beta2,
Python is 0.23")` Now, how do I get the 0.24-beta2 version of Pymacs?~~ Sorry,
that was me forgetting to remove the reference to the old epy-setup, however,
after removing it, Pymacs starts fine, with the proper version (but it doesn't
need -f switch). What am I doing wrong?


Answer: Answer is here:

<http://docs.python.org/library/sys.html#module-sys>

    
    
    The list of command line arguments passed to a Python script. argv[0] is the script name (it is operating system dependent whether this is a full pathname or not). If the command was executed using the -c command line option to the interpreter, argv[0] is set to the string '-c'. If no script name was passed to the Python interpreter, argv[0] is the empty string.
    
    To loop over the standard input, or the list of files given on the command line, see the fileinput module.
    

IMO with sys.argv[1:] you get all remaining arguments; "-f" from some shell-
script, not appropriate here

