Configure Emacs under Windows to develop Python
Last year on the internet a chance to know the existence of Emacs, in the surrounding predecessors are praised sublime good use, like with the public, I suddenly feel that if can use Emacs to code, perhaps is a very cow skills.
But after looking at a tutorial, the idea was abandoned because of the complexity of shortcut keys and the way it works differently from the general editor.
Starting work this year, the company has not sent me a project, so I have time to learn some of the python introduction. When looking for the right editor, the long-forgotten Emacs was suddenly pulled out.
Start again to open the tutorial, the patience to read, and a little to remember a few shortcuts, finally able to stumble on the use of.
Then, when we started looking for the Python approach to Emacs, I found that the plugin configuration of Emacs was so tricky for newbies. There is less information in Chinese, and most of it is on the LINUX/MAC system. It seems difficult for us to get started with the "minority population" that uses Emacs on Windows.
Today in the company, spent an afternoon of time, a variety of search, various attempts, all kinds of toss, finally let Emacs with the Python-mode plug-in. Although it seems that the most used and more functional is the Ipython plugin, it has not been understood so far today. You will have the opportunity to update the following later. Today, the Re-window environment under Emacs configuration Python-mode Plug-in method is recorded.
Emacs Download and install
Download
Emacs Official Address
http://www.gnu.org/software/emacs/
Download Address: (Windows version)
http://ftp.gnu.org/gnu/emacs/windows/
Download the latest version of the ZIP package to
Installation
After downloading the extract, go to the Bin folder in the root directory and run the Addpm.exe installation, and the GNU Emacs entry will be added to the Start menu after installation.
Of course you can also choose not to install, call Emacs.exe or Runemacs.exe to open Emacs directly.
Entry
After you run Emacs, click "Emacs Tutorial" under the Help menu to enter the tutorial documentation that comes with Emacs. (The tutorial documentation is high quality, salute to the document creation \ Dubbing) You can also click "Emacs Tutorial (Choose language)" to select a different language.
Completing the tutorials will help beginners get started quickly and understand the basic concepts of Emacs, and can easily be used for the daily use of Emacs.
Emacs is powerful, and more applications require users to learn in the future.
Installation of Python
Python installation Please refer to other materials, in order to edit the speed, here first focus on the configuration of Emacs.
Emacs Configuration Using Python-mode
Emacs Configuration
In a lot of data about Emacs configuration, will mention "~/.emacs.d/" path and "~/.emacs" file, I toss for a long time did not find. Later found, "~" refers to the home path in the window System is C:\Users\ (username) \appdata\roaming:
According to the WINDOWS7 system's home directory configuration, C:\Users\ (username) \appdata\roaming This home directory is too deep, and the default state AppData directory is hidden, the most important thing is: if the system disk once the problem , both the previous. Emacs configuration file and the. el extension have to be reconfigured and downloaded. The next lot of information will teach you how to change your home directory to make it easier to use it. But in fact, the initial use of Emacs users if not often need to change the configuration file, the use of the original directory is sufficient, if your computer has been set to display hidden files, this directory is not particularly difficult to find.
The ~/.emacs file does not exist at the beginning. In the Options menu of Emacs, just set an item, such as Click Highlight Matching parenthesis and select Save options, the mini buffer will show "wrote c:/users/(username)/ Appdata/roaming/.emacs "You can see the. emacs file and the. EMACS.D directory when you enter the home directory.
Python-mode
Python-mode Download:
Https://launchpad.net/python-mode
Download unzip, run into Python shell
>python setup.py Install
Installation. Python shell entry method in the installation of Python data will be available, we refer to their own.
Then copy the extracted Python-mode.el files to the home directory. EMACS.D folder.
Open the. emacs file and add the following:
(Require ' Python-mode) (Add-to-list ' auto-mode-alist ' ("\\.py '". Python-mode))
When you run Emacs, you'll configure your python-mode yourself.
Run
After configuring Python-mode, open any. py file with Emacs and enter M-x Py-execute-buffer to run the Python code.
Using shortcut keys C-c c-c is the same effect.
Expand emacs with Python
Pymacs can enable Emacs to interact with Python programs, allowing Emacs plug-in developers to use Python as much as possible. Here is an example of calling Python's function in Lisp and passing the file name of the current buffer to Python, outputting the return value of the Python function in Emacs
Installation
First install the Python package pymacs. Install Pymacs in Ubuntu.
Then install the Emacs plugin Pymacs, el-get-install or Package-install can
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 '%s '% file Name Interactions[hello_word] = "
Content of setup.py:
From Setuptools Import Setup, find_packages Setup ( name = "Sample-pymacs", Version = "0.1", packages = find_p Ackages ())
Install this module
Python setup.py Install
If everything works, you can import the sample in Python
Calling the Python module in Lisp
Create a Lisp file:
(pymacs-load "Sample") (Message (Sample-hello-word buffer-file-name))
Move the cursor over each line and use C-m-x to execute the line's Lisp code, which will see the output on Emacs after execution.