【问题标题】:pymacs: General question and Installation problempymacs:一般问题和安装问题
【发布时间】:2009-07-03 06:55:40
【问题描述】:

我正在尝试为 python 开发设置 emacs。

根据我的阅读,建议使用 python-mode.el 而不是 Emacs 22.3 中的默认 python.el。于是我开始了新的冒险。

据我了解,python-mode 有几个依赖项,所以我需要安装rope、ropemode 和ropemacs。然后最重要的是我需要安装pymacs。

问:对吗?

这是我现在的新 .emacs:

(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(inhibit-startup-screen t)
 '(tab-width 4))
(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 )

(setq emacs-config-path "~/.emacs.d/")
(setq base-lisp-path "~/.emacs.d/site-lisp/")
(setq site-lisp-path (concat emacs-config-path "/site-lisp"))
(defun add-path (p)
  (add-to-list 'load-path (concat base-lisp-path p)))

(add-path "") 
(add-to-list 'load-path "~/.emacs.d")

(require 'psvn)

;; python-mode
;;
(setq auto-mode-alist (cons '("\\.py$" . python-mode) auto-mode-alist))
(setq interpreter-mode-alist (cons '("python" . python-mode) interpreter-mode-alist))
(autoload 'python-mode "python-mode" "Python editing mode." t)


(setq pymacs-load-path '(   "~/.emacs.d/site-lisp/rope"
                            "~/.emacs.d/site-lisp/ropemode"
                            "~/.emacs.d/site-lisp/ropemacs"))


(setq interpreter-mode-alist
      (cons '("python" . python-mode)
        interpreter-mode-alist)
      python-mode-hook
      '(lambda () (progn
            (set-variable 'py-indent-offset 4)
            (set-variable 'py-smart-indentation nil)
            (set-variable 'indent-tabs-mode nil)
            ;;(highlight-beyond-fill-column)
                    (define-key python-mode-map "\C-m" 'newline-and-indent)
            (pabbrev-mode)
            (abbrev-mode)
     )
      )
)


;; pymacs
(autoload 'pymacs-apply "pymacs")
(autoload 'pymacs-call "pymacs")
(autoload 'pymacs-eval "pymacs" nil t)
(autoload 'pymacs-exec "pymacs" nil t)
(autoload 'pymacs-load "pymacs" nil t)

;; Search local path for emacs rope
;;

;; enable pymacs
;; 
(require 'pymacs)
(pymacs-load "ropemacs" "rope-")

现在,当我启动 emacs 时,我收到以下错误消息:

("C:\\opt\\emacs-22.3\\bin\\emacs.exe")
Loading encoded-kb...done
Loading regexp-opt...done
Loading easy-mmode...done
Loading wid-edit...done
Loading edmacro...done
Loading derived...done
Loading advice...done
Loading cl-macs...done
Loading byte-opt...done


An error has occurred while loading `c:/opt/cygwin/home/akong/.emacs':

File error: Cannot open load file, pymacs

To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file.  Start Emacs with
the `--debug-init' option to view a complete error backtrace.

For information about GNU Emacs and the GNU system, type C-h C-a. [2 times]

让它稍微复杂一点:

出于工作原因,我必须使用 python 2.4,但我的 PC 上安装了 python 2.6。但显然rope不喜欢2.4所以我没有运行setup.py。我解压/解压缩这些包并将这些文件放在 ~/.emacs.d/site-lisp 下。默认情况下,如果在命令提示符下调用 python,它是 python 2.4 可执行文件。

问:如何才能成功加载“pymacs”?

【问题讨论】:

    标签: python emacs rope pymacs


    【解决方案1】:

    到目前为止,我从未使用过 pymacs,但是当我看到您的 .emacs 时,引起我注意的一件事是您显然没有将 pymacs 目录添加到 emacs load-path但只给pymacs一个:

    (setq pymacs-load-path '( "~/.emacs.d/site-lisp/rope"
                              "~/.emacs.d/site-lisp/ropemode"
                              "~/.emacs.d/site-lisp/ropemacs"))
    

    你可能还需要类似的东西:

    (add-to-list 'load-path "~/.emacs.d/site-lisp/rope")
    (add-to-list 'load-path "~/.emacs.d/site-lisp/ropemode")
    (add-to-list 'load-path "~/.emacs.d/site-lisp/ropemacs")
    

    (或任何你有pymacs.el)以便emacs可以找到lisp文件。在pymacs documentation中也提到了

    2.4 正确安装 Pymacs ... 用于 Emacs 部分 ...

    现在这通常是手工完成的。 首先选择一些目录 保存在 Emacs load-path 中的列表,用于 你有写权限,然后复制 该目录中的文件 pymacs.el。

    【讨论】:

    • 唉,按照推荐添加了这些行,但没有运气。
    • 那你在哪里有 pymacs.el?
    • 还要检查你的加载路径变量是否包含这个目录(C-h v: load-path)。
    • 我认为你不需要(add-to-list 'load-path "~/.emacs.d/site-lisp/rope") 之类的,因为rope、ropemode 和ropemacs 是通过pymacs 加载的python 包,所以它们只需要在PYTHONPATH 或pymacs-load-path 中。在ropemacs 目录中没有Emacs lisp 文件。请注意没有(require 'ropemacs) 或类似的东西。
    【解决方案2】:

    原来我错过了这两个:

    (add-to-list 'load-path "~/.emacs.d/site-lisp/Pymacs-0.23")
    

    显然我需要加载 pymac 脚本。

    我已将环境变量 PYMACS_PYTHON 设置为 python 2.6,因为出于工作原因,我使用 python 2.4 作为默认 python 解释器。

    【讨论】:

      【解决方案3】:

      如果缺少路径,那么很容易在启动日志中发现,或者在 emacs 启动时获取回溯。如果有疑问 M-x load-library 是要走的路。

      在最新的 Debian 测试更新后,我也遇到 company-ropemacs 拒绝同时加载 emacs 23 和 emacs 24,这意味着由于绳索保存挂钩,您无法保存文件。我很想听听任何使用它的人的意见。 company-ropemacs 和 python 通常与 emacs 一起使用已经有一段时间了。我打算稍后再尝试调试它,然后更新这个线程。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-07-06
        • 2016-04-15
        • 1970-01-01
        • 2018-05-06
        • 1970-01-01
        • 2017-02-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多