Emacs持续折叠模式 [英] Emacs persistent folding mode

查看:129
本文介绍了Emacs持续折叠模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



但是,我有一种方法可以在Emacs中折叠代码。当我关闭并重新打开文件时,真的希望我的折叠被保留。让我重新启动Emacs后,将折叠设置成档案非常令人沮丧。



有没有人找到一种方法来保持文件的折叠状态持续?

解决方案

编辑:现在我明白了这个问题...



像下面的代码片段一样。这似乎对我来说是有效的,虽然我没有想到如何避免每次都提示输入文件局部变量。

 (defvar omm-state nil 
文件局部变量存储大纲叠加)
(defun omm-state-mode(& optional arg)
穷人的次要模式重新应用大纲覆盖
(interactive)
(omm-re-enable-outline-state)
(add-hook'before-save-hook'omm-state-save))
(defun omm-get-all-overlays()
返回所有当前缓冲区的大纲信息列表
(save-excursion
(let((all-overlays (point-min)(point-max)))
(map(lambda(o))
(list(overlay-start o)(overlay-end o) '不可见)))
(反向全覆盖))))
(defun omm-re-enable-outline-state(&可选参数)
打开轮廓 - 次要模式并重新应用大纲信息
(outline-minor-mode 1)
(wh en(listp omm-state)
(mapcar(lambda(p)
(apply'outline-flag-region p))
omm-state))
(defun omm -state-save()
将文件中的大纲状态保存在本地变量中
注意:这只是替换现有的值,你需要通过添加这样的东西来启动
文件:

#本地变量:
#omm-state :()
#模式:omm状态
#结束:

(忽略错误
(save-excursion
(goto-char(point-max))
(when(search-backwardomm-state:nil t)
(goto-char(match-end 0))
(kill-sexp)
(princ(omm-get-all-overlays)(current-buffer)))))
nil)

此解决方案需要您的文件种子,例如:

 #本地变量:
#omm-state :()
#模式:omm状态
#结束:


There are plenty of ways to fold code in Emacs and I've settled in on using the outline minor mode... it works great!

However, I really want my folding to be persisted when I close and re-open files. It is quite frustrating to have folding set up in a file the way I like it, only to have that lost when I restart Emacs.

Has anyone found a way to keep the folding state of a file persistent?

解决方案

Edit: Now that I understand the question...

How about something like the following nippet of code. It seems to work for me, though I haven't figured out how to avoid being prompted for the file local variable every time.

(defvar omm-state nil
  "file local variable storing outline overlays")
(defun omm-state-mode (&optional arg)
  "poor man's minor mode to re-apply the outline overlays "
  (interactive)
  (omm-re-enable-outline-state)
  (add-hook 'before-save-hook 'omm-state-save))
(defun omm-get-all-overlays ()
  "return a list of outline information for all the current buffer"
  (save-excursion
    (let ((all-overlays (overlays-in (point-min) (point-max))))
      (mapcar (lambda (o)
                (list (overlay-start o) (overlay-end o) (overlay-get o 'invisible)))
              (reverse all-overlays)))))
(defun omm-re-enable-outline-state (&optional arg)
  "turn on outline-minor-mode and re-apply the outline information"
  (outline-minor-mode 1)
  (when (listp omm-state)
    (mapcar (lambda (p)
              (apply 'outline-flag-region p))
            omm-state)))
(defun omm-state-save ()
  "save the outline state in a file local variable
Note: this just replaces the existing value, you need to start
it off by adding something like this to your file:

# Local Variables:
# omm-state:()
# mode:omm-state
# End:            
"
  (ignore-errors
    (save-excursion
      (goto-char (point-max))
      (when (search-backward "omm-state:" nil t)
        (goto-char (match-end 0))
        (kill-sexp)
        (princ (omm-get-all-overlays) (current-buffer)))))
  nil)

This solution requires you "seeding" your file with something like:

# Local Variables:
# omm-state:()
# mode:omm-state
# End:            

这篇关于Emacs持续折叠模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆