简体   繁体   English

如何为Emacs安装python-mode.el?

[英]How do I install python-mode.el for Emacs?

I am using Ubuntu 10.10 (Maverick Meerkat). 我正在使用Ubuntu 10.10(Maverick Meerkat)。 I have downloaded python-mode.el from Launchpad and placed it in emacs.d/plugins/ . 我从Launchpad下载了python-mode.el并将其放在emacs.d/plugins/

Now how do I install python-mode.el ? 现在我如何安装python-mode.el

Try this 尝试这个

(add-to-list 'load-path "~/.emacs.d/plugins")
(require 'python-mode)

I find it more convenient to have the appropriate editing mode auto-load based on the type of file edited. 我发现根据编辑的文件类型自动加载适当的编辑模式会更方便。 There are lots of ways to do this, but I usually add an entry to autoload-alist: 有很多方法可以做到这一点,但我通常会在autoload-alist中添加一个条目:

(and (library-loadable-p "python-mode")
     (setq auto-mode-alist (append '(
                     ("\\.py\\'"       . python-mode)
                     )
                   auto-mode-alist)))

I have a long list of these for the various modes I like to use. 对于我喜欢使用的各种模式,我有很长的列表。 It fails silently if python-mode (or any other mode) is not installed. 如果未安装python-mode(或任何其他模式),它将无提示失败。 If I'm running on an ISP sever that doesn't have a mode installed, I add ~/lib/elisp to the load-path and put the missing .el files in there. 如果我在没有安装模式的ISP服务器上运行,我将〜/ lib / elisp添加到加载路径并将丢失的.el文件放在那里。

library-loadable-p came from a friend and simply tests whether the file is somewhere in the load path: library-loadable-p来自朋友,只是测试文件是否在加载路径中的某个位置:

(defun library-loadable-p (lib &optional nosuffix)
  "Return t if library LIB is found in load-path.
Optional NOSUFFIX means don't try appending standard .elc and .el suffixes."
  (let ((path load-path)
    elt)
    (catch 'lib-found
      (while (car path)
    (setq elt (car path))
    (and
     (if nosuffix
         (file-exists-p (concat elt "/" lib))
       (or (file-exists-p (concat elt "/" lib ".elc"))
           (file-exists-p (concat elt "/" lib ".el"))
           (file-exists-p (concat elt "/" lib))))
     (throw 'lib-found t))
    (setq path (cdr path))))))

I'd suggest cloning the latest snapshot: 我建议克隆最新的快照:

cd ~/.emacs.d/site-lisp/python-mode
bzr branch lp:python-mode

Then add to .emacs : 然后添加到.emacs

(add-to-list 'load-path "~/.emacs.d/site-lisp/python-mode")
(setq py-install-directory "~/.emacs.d/site-lisp/python-mode")
(require 'python-mode)

You can later update the to the latest version with: 您可以稍后使用以下命令更新到最新版本:

bzr update

But don't forget to re-compile: 但是别忘了重新编译:

(byte-recompile-directory (expand-file-name "~/.emacs.d/site-lisp/python-mode") 0)

In emacs 25, you can install python mode using melpa, so just add this to your .emacs file: 在emacs 25中,您可以使用melpa安装python模式,因此只需将其添加到.emacs文件中:

(require 'package)
(add-to-list 'package-archives
             '("melpa-stable" . "https://stable.melpa.org/packages/"))

Reload the file, then type, 重新加载文件,然后键入,

Alt+x list-packages

Move to the package you want, 移动到你想要的包裹,

python-mode

Then hit "enter", and in the new buffer that opens move to Install and press enter. 然后点击“enter”,在打开的新缓冲区中移动到Install并按Enter键。

This causes python-mode to be installed in ~/.emacs.d/elpa 这会导致python-mode安装在~/.emacs.d/elpa

Now in a new buffer with python-mode on, write your code and type Cu Cc Cc to evaluate and display output. 现在在一个打开python-mode的新缓冲区中,编写代码并输入Cu Cc Cc来评估和显示输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM