Configure Emacs on Windows to develop Python and use Python to expand Emacs and emacspython

Source: Internet
Author: User

Configure Emacs on Windows to develop Python and use Python to expand Emacs and emacspython

Configure Emacs in Windows to develop Python
Last year, I happened to have a chance to know the existence of Emacs. When the elders around me praised Sublime for its ease of use, I liked to turn back to the public. I suddenly felt that if I could use Emacs to compile code, it may be a good skill.
However, after reading Tutorial, I gave up this idea because of the complicated shortcut keys and Operations different from the general editor.
After I started my work this year, the company hasn't provided me with a configuration item, so I have time to get started with Python. When looking for a suitable editor, the Emacs, which had been put aside for a long time, was suddenly released.
Start the tutorial again, read it patiently, and remember a few shortcut keys to finally be able to use it.
Then, when looking for the Python Method on Emacs, we found that the plug-in configuration of the original Emacs is so tricky for new users. There are few Chinese documents, and most of them are on Linux/Mac systems. It seems difficult for us to get started with the "minority" of Emacs in Windows.

Today, I spent an afternoon at the company, searching, trying, and tossing, finally enabling Emacs to use the Python-mode plug-in. Although iPython plug-in seems to be the most widely used and more fully functional, I haven't figured it out yet. I will have the opportunity to update the subsequent content later. Today, we will record the method for configuring the Python-mode plug-in Emacs in the Window environment.

Download and install Emacs
Download
Official Address of Emacs
Http://www.gnu.org/software/emacs/

(Windows Version)
Http://ftp.gnu.org/gnu/emacs/windows/
Download the latest zip package.

Install
After the download is decompressed, go to the binfolder in the root directory and run addpm.exe. After installation, add the GNU Emacs item to the Start Menu.
You can also choose not to install emacs.exe or runemacs.exe to open Emacs directly.

Getting started
After running Emacs, click "Emacs Tutorial" under the Help menu to go To the tutorials provided by Emacs. (The Tutorial documents are of high quality and we would like to pay tribute to the document creators and translators). You can also click "Emacs Tutorial (choose language)" to select different languages.
After reading the tutorial, we can help beginners get started quickly and understand the most basic concepts of Emacs. We can also use Emacs in a simple way.
Emacs is very powerful, and more applications need to be learned continuously in the future.

Python Installation
For Python installation, refer to other documents. For the editing speed, describe the Emacs configuration first.

Use Python-mode for Emacs Configuration
Emacs Configuration
In many documents about Emacs configuration, we will mention "~ /. Emacs. d/"path and" ~ /. Emacs file, which I have been tossing for a long time and cannot be found. Later I found out that "~" In the window system, the HOME path is C: \ Users \ (username) \ AppData \ Roaming:

C: \ Users \ (username) \ AppData \ Roaming is too deep and the AppData directory is hidden by default, the most important thing is: if there is a problem with the system disk. emacs configuration file and. el extensions must be reconfigured and downloaded. Next, I will teach you how to change the HOME directory to make it easier to use. But in fact, if users who use Emacs for the first time do not need to change the configuration file frequently, it is enough to use the original directory. If your computer has set to show hidden files, this directory is not particularly difficult to find.

~ The/. emacs file does not exist at the beginning. Set any item in the Options menu of Emacs. For example, click Highlight Matching Parenthesis and select Save Options. The mini buffer will display "Wrote c:/Users/(username) /AppData/Roaming /. emacs "is displayed in the HOME directory. emacs file and. emacs. d directory.

Python-mode
Python-mode download:
Https://launchpad.net/python-mode
Download and decompress the package and run it in Python shell.

>python setup.py install
Install. Python shell installation methods are available in python installation materials.
Then copy the unzipped python-mode.el file to the HOME directory. emacs. d folder.
Open the. emacs file and add the following content:
(require 'python-mode)(add-to-list 'auto-mode-alist '("\\.py'" . python-mode))

Run Emacs and configure python-mode on your own.

Run
After configuring python-mode, use emacs to open any. py file and enter M-x py-execute-buffer to run python code.
Using the shortcut key C-c is also the same effect.

Emacs extension using python
Pymacs enables emacs to interact with python programs, and allows emacs plug-in developers to use python for development whenever possible. Here is an example. In lisp, the python function is called and the file name of the current buffer is passed to python, And the python function return value is output in emacs.

Install
First install python package Pymacs. Install pymacs In ubuntu.

Install the emacs plug-in pymacs, el-get-install, or package-install.

Write a python Module
The directory structure is as follows:

├── sample│  └── __init__.py└── setup.py

Content of _ init _. py:

from Pymacs import lisp interactions = {} def hello_word(filename):  return 'Hello from python, file name is %s' % filename  interactions[hello_word] = ''

Content of setup. py:

from setuptools import setup, find_packages setup(  name = "sample-pymacs",  version = "0.1",  packages = find_packages())

Install this module

python setup.py install

If everything works properly, you can import the sample in python.

Call the python module in lisp
Create a lisp file:

(pymacs-load "sample")(message (sample-hello-word buffer-file-name))

Move the cursor to each row and run the lisp code of the row using C-M-x. The output is displayed on emacs.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.