Edit: Bây giờ tôi hiểu câu hỏi ...
Làm thế nào về một cái gì đó giống như nippet mã sau đây. Nó dường như làm việc cho tôi, mặc dù tôi đã không tìm ra cách để tránh bị nhắc nhở cho các biến địa phương tập tin mỗi lần.
(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)
Giải pháp này đòi hỏi bạn "gieo hạt" tập tin của bạn với một cái gì đó như:
# Local Variables:
# omm-state:()
# mode:omm-state
# End:
Nguồn
2010-03-19 19:48:53
Không phải là câu trả lời chính xác, nhưng bạn có thể sử dụng org-mode với [orgfold.el] (http://www.emacswiki.org/emacs/orgfold.el) hoặc [orgfold-individual-file.el] (http://www.emacswiki.org/emacs/orgfold-separate-file.el) - mặc dù sẽ tốt hơn nếu sau này chỉ làm việc với một bộ lưu trữ trạng thái toàn cục tệp (như trong [saveplace.el] (http://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/saveplace.el)). – Mark