博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[emacs] python代码折叠
阅读量:5066 次
发布时间:2019-06-12

本文共 2813 字,大约阅读时间需要 9 分钟。

水木某大牛写的emacs python代码折叠代码, 试了下, 非常好用.  感谢作者: 

 

代码如下:

发信人: jcjbrian (Brian Jiang), 信区: Emacs 

标  题: Re: python代码怎么折叠啊? 
发信站: 水木社区 (Sun Sep  6 16:59:38 2009), 转信 
  
最近刚好写了一个python的折叠功能。 能简单。 是基于emacs自带的python mode。可以支持各种类型的block (如if, for等)。  
关键是: 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)

  

转载于:https://www.cnblogs.com/foreveryl/archive/2012/08/23/2652469.html

你可能感兴趣的文章
模板统计LA 4670 Dominating Patterns
查看>>
泛型第23条:请不要在新代码中使用原生态类型
查看>>
团队项目开发客户端——登录子系统的设计
查看>>
【AppScan心得】IBM Rational AppScan 无法记录登录序列
查看>>
[翻译] USING GIT IN XCODE [4] 在XCODE中使用GIT[4]
查看>>
简化通知中心的使用
查看>>
IO—》Properties类&序列化流与反序列化流
查看>>
html 简介
查看>>
session如何保存在专门的StateServer服务器中
查看>>
react展示数据
查看>>
测试计划
查看>>
选择器
查看>>
Mysql与Oracle 的对比
查看>>
idea的maven项目无法引入junit
查看>>
jquery实现限制textarea输入字数
查看>>
thinkphp5 csv格式导入导出(多数据处理)
查看>>
fur168.com 改成5917电影
查看>>
PHP上传RAR压缩包并解压目录
查看>>
Codeforces 719B Anatoly and Cockroaches
查看>>
jenkins常用插件汇总
查看>>