生活随笔
收集整理的這篇文章主要介紹了
[emacs] python代码折叠
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
水木某大牛寫的emacs python代碼折疊代碼, 試了下, 非常好用. ?感謝作者:?jcjbrian
http://www.newsmth.net/nForum/#!article/Emacs/81688?
代碼如下:
發(fā)信人: jcjbrian (Brian Jiang), 信區(qū): Emacs?
標(biāo)??題: Re: python代碼怎么折疊啊??
發(fā)信站: 水木社區(qū) (Sun Sep??6 16:59:38 2009), 轉(zhuǎn)信?
??
最近剛好寫了一個python的折疊功能。 能簡單。 是基于emacs自帶的python mode。可以支持各種類型的block (如if, for等)。??
關(guān)鍵是: mypython-fold/unfold-block。 我把它綁到了F10. 可以自己改。 其他都只是些支持代碼。?
??
-------?
??
(defface codepilot-folding-overlay '((default (:inherit region :box (:line-width 1 :color "DarkSeaGreen1" :style released-button))) (((class color)) (:background "DarkSeaGreen2" :foreground "black"))) "*Font used by folding overlay." :group 'codepilot) (defun cptree-ov-delete () (interactive) (dolist (o (overlays-at (point))) (cptree-delete-overlay o 'cptree))) (defvar cptree--overlay-keymap nil "keymap for folding overlay") (unless cptree--overlay-keymap (let ((map (make-sparse-keymap))) (define-key map [mouse-1] 'cptree-ov-delete) (define-key map "\r" 'cptree-ov-delete) (setq cptree--overlay-keymap map))) (defun cptree-delete-overlay(o prop) (when (eq (overlay-get o 'cptree-tag) prop) (delete-overlay o) t)) (defun cptree-hide-region (from to prop) "Hides a region by making an invisible overlay over it and save the
overlay on the hide-region-overlays \"ring\"" (interactive) (let ((new-overlay (make-overlay from to))) ;;(overlay-put new-overlay 'invisible nil) (overlay-put new-overlay 'cptree-tag prop) (overlay-put new-overlay 'face 'codepilot-folding-overlay) (overlay-put new-overlay 'display (propertize (format "...<%d lines>..." (1- (count-lines (overlay-start new-overlay) (overlay-end new-overlay)))))) (overlay-put new-overlay 'priority (- 0 from)) (overlay-put new-overlay 'keymap cptree--overlay-keymap) (overlay-put new-overlay 'pointer 'hand))) (require 'python) (defun mypython-fold/unfold-block () "fold the block" (interactive) (let (ret b e) (dolist (o (overlays-at (if (python-open-block-statement-p) (save-excursion (python-end-of-statement) (point) ) (point)))) (when (cptree-delete-overlay o 'cptree) (setq ret t))) (unless ret (save-excursion (unless (python-open-block-statement-p) (python-beginning-of-block)) (python-end-of-statement) (setq b (point)) (python-end-of-block) (setq e (1- (point))) (cptree-hide-region b e 'cptree))))) (define-key python-mode-map [(f10)] 'mypython-fold/unfold-block)
轉(zhuǎn)載于:https://www.cnblogs.com/foreveryl/archive/2012/08/23/2652469.html
總結(jié)
以上是生活随笔為你收集整理的[emacs] python代码折叠的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。