代码: 全选;;加载 fold.el 扩展;;好像需要手动加载 ;;通过 M-x load-library 命令
(load-library "folding")
;; 变量赋值 应该下面条件控制的触发,所以多半要通过手动加载的。。。不太清楚,楼主试试。。。
(declare (special fold-fold-on-startup
fold-keys-already-setup
))
;; 启动时开启 fold 模式
(setq fold-fold-on-startup t)
;; 向 fold 模式中添加 find-file 接口?
(folding-mode-add-find-file-hook)
;; 定义一个函数,如果开启了 fold 模式,设定下面的键绑定;;条件控制
(setq fold-keys-already-setup nil)
(add-hook 'folding-mode-hook
(function (lambda()
(unless fold-keys-already-setup
(setq fold-keys-already-setup t)
;;定义按键序列前缀变量 ;见下面
(define-prefix-command 'ctl-f-folding-mode-prefix)
;; 命令的键绑定;;上面定义的按键序列前缀,加双引号括起来的绑 ;一个单引号,引用的是命令
(define-key 'ctl-f-folding-mode-prefix "f" 'fold-fold-region)
(define-key 'ctl-f-folding-mode-prefix "e" 'fold-enter)
(define-key 'ctl-f-folding-mode-prefix "x" 'fold-exit)
(define-key 'ctl-f-folding-mode-prefix "b" 'fold-whole-buffer)
(define-key 'ctl-f-folding-mode-prefix "o" 'fold-open-buffer)
(define-key 'ctl-f-folding-mode-prefix "h" 'fold-hide)
(define-key 'ctl-f-folding-mode-prefix "s" 'fold-show)
(define-key 'ctl-f-folding-mode-prefix "t" 'fold-top-level)
(define-key 'ctl-f-folding-mode-prefix "f" 'fold-fold-region)
)
;;定义序列前缀使用的组合键 ;;给刚才定义的前缀变量赋值
(local-set-key "\C-f" 'ctl-f-folding-mode-prefix))))
;;不同主模式下,折叠时使用的关键词。使用 “元组”定义,第一个值是起始判断,第二个是结束判断,第三个是折叠起始点。
;;好像Html要用这种注释 才能够折叠,并与普通注释相区别……没用过,楼主自己试试吧
(fold-add-to-marks-list 'sgml-mode
"" " --> ")
(fold-add-to-marks-list 'c-mode "/* */" "*/")
(fold-add-to-marks-list 'c++-mode
"//" "")
(fold-add-to-marks-list 'LaTeX-mode "%%% {{{" "%%% }}}" " ")
(fold-add-to-marks-list 'latex2e-mode "%%% {{{" "%%% }}}" " ")
(fold-add-to-marks-list 'latex-mode "%%%% {{{" "%%%% }}}" " ")
(fold-add-to-marks-list 'BibTeX-mode "%%% {{{" "%%% }}}" " ")
(fold-add-to-marks-list 'lisp-mode ";;; {" ";;; }" "")
(fold-add-to-marks-list 'lex-mode" /* {{{ " " /* }}} */ " "*/")
(fold-add-to-marks-list 'html-mode "" "-->")
(fold-add-to-marks-list 'shell-script-mode "# {{{" "# }}}" nil)
(fold-add-to-marks-list 'sh-mode "# {{{ " "# }}}" nil)