如何在文本中轻松概述任意(数据)结构? [英] How to easily outline arbitrary (data) structures in text?
问题描述
所以我发现了这个:
mysite /
manage.py
mysite /
__init__.py
设置.py
urls.py
wsgi.py
和这个:
root - + ---> child1
+ ---> child2 - + - > subchild1
| + - > subchild2
+ ---> child3
并且想知道为了勾画出什么工具(编辑器包/捆绑包等)编辑这样的结构很容易/编程。
PS:我的偏好是emacs,但是为了完整起见,如果其他编辑器/工具被包括在
第二个例子显然更复杂,我不会解决,大纲模式/次模式对于基于缩进的树将会很好地工作,所以这里是一种方法,基于任意重复的前缀字符串(在本例中为四个空格,但是可根据需要配置)的大纲标题。 / p>
如果您加载/评估下面的代码,然后加载数据文件(包含本地变量),则可以使用 SHIFT + TAB ,并使用 SHIFT + LEFT 和 SHIFT + RIGHT (光标键)来升级/降级分支。当然,所有其他 outline-minor-mode
功能也是可用的。
mysite /
manage.py
mysite /
__init__.py
settings.py
urls.py
wsgi.py
;;;本地变量:
;;; my-outline-prefix:
;;; eval:(my-outline-minor-mode 1)
;;;结束:
(global- set-key(kbd< S-tab>)'outline-toggle-children)
(global-set-key(kbd< S-left>)'outline-promotion)
(global-set-key(kbd< S-right>)'outline-demote)
(defvar my-outline-prefix
前缀字符串表示单个my-outline-minor-mode的大纲级别。)
(defvar my-outline-max-level 20
最大级别为my-outline-minor-模式'。)
(define-minor-mode my-outline-minor-mode
基于my-outline-prefix重复的大纲级别
0 nil nil
(outline-minor-mode 1)
(setq-local outline-level'my-outline-level)
(setq-local outline-regexp(format\\\ \\($)
(regexp-quote my-outline-prefix))
(setq outline-heading-alist'())
(let级别0)
(level-prefix))
(< level my-outline-max-level)
(setq outline-heading-alist(cons(cons level-prefix level)
outline-heading-alist)
level 1+级别)
级别前缀(concat level-prefix my-outline-prefix))
(setq outline-heading-alist(nreverse outline-heading-alist)))
(defun my-outline-level()
计数多少次我的大纲前缀出现在行的开头。
(let *((data(match数据))
(开始(汽车数据))
(结束(cadr数据))
(缩进( - 结束开始)))
(/ outline-prefix))))
So I came across this:
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
and this:
root --+---> child1
+---> child2 --+--> subchild1
| +--> subchild2
+---> child3
and was wondering what tool(editor packages/bundle etc) does one use in order to outline and edit such structures easily/programmatically.
PS: My preference is towards emacs but for the sake of completeness I will appreciate if other editors/tools were included in the answer.
The second example is clearly more complex, and I'm not going to address it, but outline-mode/minor-mode is going to work nicely for the indentation-based tree, so here's an approach for that, with outline headings based on an arbitrary repeated prefix string (four spaces in this example, but configurable as required).
If you load/evaluate the code below, and then load the data file (with the local variables included), then you can hide/show branches with SHIFT+TAB and promote/demote branches with SHIFT+LEFT and SHIFT+RIGHT (cursor keys). All the other outline-minor-mode
functionality is also available, of course.
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
;;; Local Variables:
;;; my-outline-prefix: " "
;;; eval: (my-outline-minor-mode 1)
;;; End:
(global-set-key (kbd "<S-tab>") 'outline-toggle-children)
(global-set-key (kbd "<S-left>") 'outline-promote)
(global-set-key (kbd "<S-right>") 'outline-demote)
(defvar my-outline-prefix " "
"Prefix string denoting a single outline level for `my-outline-minor-mode'.")
(defvar my-outline-max-level 20
"Maximum number of levels for `my-outline-minor-mode'.")
(define-minor-mode my-outline-minor-mode
"Outline levels based on repetitions of `my-outline-prefix'."
0 nil nil
(outline-minor-mode 1)
(setq-local outline-level 'my-outline-level)
(setq-local outline-regexp (format "\\(%s\\)*"
(regexp-quote my-outline-prefix)))
(setq outline-heading-alist '())
(let ((level 0)
(level-prefix ""))
(while (< level my-outline-max-level)
(setq outline-heading-alist (cons (cons level-prefix level)
outline-heading-alist)
level (1+ level)
level-prefix (concat level-prefix my-outline-prefix)))
(setq outline-heading-alist (nreverse outline-heading-alist))))
(defun my-outline-level ()
"Counts how many times `my-outline-prefix' appears at the start of the line."
(let* ((data (match-data))
(start (car data))
(end (cadr data))
(indent (- end start)))
(/ indent (length my-outline-prefix))))
这篇关于如何在文本中轻松概述任意(数据)结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!