35
Pymacs 初體驗 PyConTW 2013 Superbil <[email protected] > 0.0.1 13530星期四

Pymacs 初體驗

Embed Size (px)

DESCRIPTION

PyCon Taiwan 2013

Citation preview

Page 1: Pymacs 初體驗

Pymacs 初體驗PyConTW 2013

Superbil <[email protected]>

0.0.1

13年5月30⽇日星期四

Page 2: Pymacs 初體驗

About Me

•軟體⼯工程師、Mobile App 開發

•Emacs 使⽤用經驗⼤大約 1 年

•Python 使⽤用經驗⼤大約 1 年

•PyHUG 主持⼈人

•about.me/superbil

• freenode #python.tw #emacs.twon RPi

13年5月30⽇日星期四

Page 3: Pymacs 初體驗

什麼是 Emacs ?

13年5月30⽇日星期四

Page 4: Pymacs 初體驗

編輯器

13年5月30⽇日星期四

Page 5: Pymacs 初體驗

編輯器學習曲線

13年5月30⽇日星期四

Page 6: Pymacs 初體驗

為什麼要⽤用 Emacs ?!

13年5月30⽇日星期四

Page 7: Pymacs 初體驗

You can hack it !你不⽤用把⼿手從鍵盤上移開

13年5月30⽇日星期四

Page 8: Pymacs 初體驗

What is a hacker ?

• hacker 是那些勇於挑戰既有體制,改變系統讓世界更進步的玩家,決定⼀一個⼈人是否為 hacker 的關鍵在於思維。hacker 其實是⼀一種思考模式

羅根.拉普蘭特:⽤用駭客思維學習 Logan LaPlante: Hackschooling Makes Me Happy

13年5月30⽇日星期四

Page 9: Pymacs 初體驗

Emacs 基本介紹

• Ctrl + h t // emacs tutorial

• Ctrl + {b,n,p,f} // h j k l

• Ctrl + x b // 切換 buffer

• Ctrl + x Ctrl + e // 執⾏行 ( ) 中的 elisp

• Ctrl + h m // 查詢當下 mode 的⽂文件

13年5月30⽇日星期四

Page 10: Pymacs 初體驗

Emacs 的熱鍵很難按

13年5月30⽇日星期四

Page 11: Pymacs 初體驗

更換你的 Ctrl 鍵位置

• 你記得你上次⽤用到 Caps Lock 是什麼時候嗎?

• Ctrl 在下⾯面的位置其實是⾮非常難按的

巨⼈人出現了阿!!!

13年5月30⽇日星期四

Page 12: Pymacs 初體驗

Emacs vs Vim

13年5月30⽇日星期四

Page 13: Pymacs 初體驗

Emacs vs Vim vs Sublime Text

13年5月30⽇日星期四

Page 14: Pymacs 初體驗

Emacs vs Vim vs Sublime Text

vs More...

13年5月30⽇日星期四

Page 15: Pymacs 初體驗

Emacs vs Vim

• 其實這是個陳年⽼老問題…

• 沒有好或不好,只有合不合⽤用

13年5月30⽇日星期四

Page 16: Pymacs 初體驗

為何不同時使⽤用Emacs 和 Vim ?

by 程序员时髦值指南

同时⽤用 Vim 和 Emacs,这⼈人早被烧死了

13年5月30⽇日星期四

Page 17: Pymacs 初體驗

Install Emacs on Server ?

13年5月30⽇日星期四

Page 18: Pymacs 初體驗

為什麼要⽤用 Pymacs ?

13年5月30⽇日星期四

Page 19: Pymacs 初體驗

因為沒有⼈人會寫 lispemacs lisp

13年5月30⽇日星期四

Page 20: Pymacs 初體驗

因為沒有⼈人會寫 lisp

• 想要 hack Emacs ⼜又不想學 lisp 你就可以⽤用 Pymacs

13年5月30⽇日星期四

Page 21: Pymacs 初體驗

How to install Pymacs

• Python side

• make install

• Emacs side

• M-x package-install RET pymacs RET

Emacs 24.x +

13年5月30⽇日星期四

Page 22: Pymacs 初體驗

Pymacs Debug

要切換到 *Pymacs* 這個 Buffer

13年5月30⽇日星期四

Page 23: Pymacs 初體驗

Pymacs 運作原理

• 建⽴立 server process 跑到 loop 等待

• 當接收到指令之後執⾏行,並回傳到 emacs

• 實際上是遞迴

13年5月30⽇日星期四

Page 24: Pymacs 初體驗

Pymacs 的簡單應⽤用

• pymacs-exec

• (pymacs-exec "print 'Hello PyConTw'")

• 在 Python 的執⾏行環境裡⾯面執⾏行程式碼 執⾏行 python 的 statement,回傳值永遠都是 nil

13年5月30⽇日星期四

Page 25: Pymacs 初體驗

Hello WorldPython side

from Pymacs import lispinteractions = {}

def hello_world(): "Hello world' from Python." lisp.insert("Hello from Python!")interactions[hello_world] = ''

13年5月30⽇日星期四

Page 26: Pymacs 初體驗

Hello WorldEmacs side

• 讀取⼀一個名為 helloEmacs 的套件,並使⽤用 hm- 來當作前綴詞

(pymacs-load "helloEmacs" "hm-")

13年5月30⽇日星期四

Page 27: Pymacs 初體驗

產⽣生出 lisp function

• (hm-hello-world)hm-hello-world is an interactive Lisp function.

(hm-hello-world &rest ARGUMENTS)

It interfaces to a Python function.

Hello world' from Python.

13年5月30⽇日星期四

Page 28: Pymacs 初體驗

M-x hm-hello-world

(hm-hello-world) Hello from Python!

13年5月30⽇日星期四

Page 29: Pymacs 初體驗

Sample - winkler

from Pymacs import lispinteractions = {}

def break_on_whitespace(): start, end = lisp.point(), lisp.mark(True) words = lisp.buffer_substring(start, end).split() lisp.delete_region(start, end) lisp.insert('\n'.join(words))

interactions[break_on_whitespace] = ''

13年5月30⽇日星期四

Page 30: Pymacs 初體驗

Sample - winkler result

Hello PyCon Taiwan

M-x winkler-break-on-whitespace

HelloPyConTaiwan

Marked

from Pymacs import lispinteractions = {}

def break_on_whitespace(): start, end = lisp.point(), lisp.mark(True) words = lisp.buffer_substring(start, end).split() lisp.delete_region(start, end) lisp.insert('\n'.join(words))

interactions[break_on_whitespace] = ''

13年5月30⽇日星期四

Page 31: Pymacs 初體驗

Live Demo

13年5月30⽇日星期四

Page 33: Pymacs 初體驗

13年5月30⽇日星期四

Page 34: Pymacs 初體驗

Happy HackingKeyboard

13年5月30⽇日星期四

Page 35: Pymacs 初體驗

Thank you

13年5月30⽇日星期四