emacs - How to easily outline arbitrary (data) structures in text? -


so came across this:

mysite/     manage.py     mysite/         __init__.py         settings.py         urls.py         wsgi.py 

and this:

root --+---> child1        +---> child2 --+--> subchild1        |              +--> subchild2        +---> child3 

and wondering tool(editor packages/bundle etc) 1 use in order outline , edit such structures easily/programmatically.

ps: preference towards emacs sake of completeness appreciate if other editors/tools included in answer.

the second example more complex, , i'm not going address it, outline-mode/minor-mode going work nicely indentation-based tree, here's approach that, outline headings based on arbitrary repeated prefix string (four spaces in example, configurable required).

if load/evaluate code below, , load data file (with local variables included), can hide/show branches shift+tab , promote/demote branches shift+left , shift+right (cursor keys). other outline-minor-mode functionality 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 single outline level `my-outline-minor-mode'.")  (defvar my-outline-max-level 20   "maximum number of levels `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 @ start of line."   (let* ((data (match-data))          (start (car data))          (end (cadr data))          (indent (- end start)))     (/ indent (length my-outline-prefix)))) 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -