我已经升级到Emacs24,并且在启动Pymacs时会因为超时而中断。
下面是回溯:
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
然后,我调查了:
(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)))
然后,我在
;; Launch the Pymacs helper.
下面的部分中尝试通过仅在控制台中运行同一命令来重现它: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
如果删除
-f
开关,它似乎可以正常工作(就像以前一样!)。因此,我的问题是:为什么需要此开关?如果需要此开关,我可能做错了其他东西,但这对我不起作用?如果然后我注释掉
-f
开关,则它在版本检查上失败:Debugger entered--Lisp error: (error "Pymacs Lisp version is 0.24-beta2, Python is 0.23")
现在,如何获得Pymacs的0.24-beta2版本?
抱歉,我忘了删除对旧的epy-setup的引用,但是,删除它之后,Pymacs可以正常运行,并且具有正确的版本(但不需要-f开关)。我究竟做错了什么?
最佳答案
答案在这里:
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.
带有sys.argv [1:]的IMO可以得到所有剩余的参数;一些shell脚本中的“ -f”,此处不合适
关于python - Emacs24 + Pymacs -f开关与pymacs-load-path冗余吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11717280/