-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathREADME.org
More file actions
128 lines (95 loc) · 3.74 KB
/
Copy pathREADME.org
File metadata and controls
128 lines (95 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#+title: org-fs-tree
* Why?
I created it because I wanted to make notes under various file names
as I walked through the source dirs of a project I was to contribute
to at work.
Soon, I found creating headings manually painful especially when
similar file names occur in multiple subdirectories.
My first reaction was to use the following snippet to generate a org
skeleton.
#+begin_src
$ cd /base/of/src/dir
$ find . -type f | sed 's/^/* /'
#+end_src
which in turn generated a new top-level heading for file in the
tree. This turned out to be very cumbersome as well since there was no
way to fold subtrees which I wasn't interested in looking at immediately
Half-way creating new headings from common directory names and moving
files to second-level headings etc. I noticed that I had lost a way to
visit the files. With the full names, at least ~find-file-at-point~
worked. Now even that only the filenames were in the leaf, navigation
became painful again. The other alternative (retaining full path names
in 2nd/3rd level headings) looked very ugly.
It was time to slip on some elisp gloves.
* How does org-fs-tree help?
- Takes a directory name from the user and creates a org-mode tree
corresponding to the tree rooted at the directory.
- All the tree-folding goodness and short headings shall serve you
well.
- Each heading is an org-mode link as well. ~C-c C-o~
(~org-open-at-point) should serve you well for opening the files.
- Since even file names are headings, you can make notes under the
file name
** Example
#+begin_src
$ tree ~/test/
/home/scriptdevil/test/
|-- doc
| |-- boo
| |-- build-instructions.md
| `-- running-tests.md
|-- include
| |-- bar.h
| `-- foo.h
|-- README
`-- src
|-- bar.c
`-- foo.c
4 directories, 7 files
#+end_src
would in turn generate
#+begin_src
* [[/home/scriptdevil/test/][test/]]
** [[/home/scriptdevil/test/README][README]]
** [[/home/scriptdevil/test/doc/][doc/]]
*** [[/home/scriptdevil/test/doc/boo/][boo/]]
*** [[/home/scriptdevil/test/doc/build-instructions.md][build-instructions.md]]
*** [[/home/scriptdevil/test/doc/running-tests.md][running-tests.md]]
** [[/home/scriptdevil/test/include/][include/]]
*** [[/home/scriptdevil/test/include/bar.h][bar.h]]
*** [[/home/scriptdevil/test/include/foo.h][foo.h]]
** [[/home/scriptdevil/test/src/][src/]]
*** [[/home/scriptdevil/test/src/bar.c][bar.c]]
*** [[/home/scriptdevil/test/src/foo.c][foo.c]]
#+end_src
I used this on the emacs source tree to generate
[[examples/emacs-src.org]]
*Note:* This was just a dump of the entire tree, in reality, you may
not care about some directories like ~nextstep/~ or ~msdos/~. In that
case, you can delete the entire subtree with the regular org-mode
operations. Also, this looks really ugly online because github doesn't
let you fold subtrees. View this in emacs and you will see what I mean
Lastly, the links in this tree are rooted at /scratch/ because that is
where I keep my emacs sources. Keeping full paths in all links lets
you open the files with ~C-c C-o~ without having to consider what
~$PWD~ is.
* Usage
In any org-mode buffer:
#+begin_src
M-x package-install ⏎ f
M-x package-install ⏎ names
M-x load-library ⏎ org-fs-tree
# To dump entire FS hierarchy rooted at /path/to/directory
M-x org-fs-tree-dump ⏎ /path/to/directory
# To restrict to say 3 levels of the FS hierarchy rooted at /path/to/directory
C-u 3 M-x org-fs-tree-dump ⏎ /path/to/directory
#+end_src
* Dependencies
- [[https://github.com/Malabarba/names][names]] for providing a namespace for the functions defined
- [[https://github.com/rejeep/f.el][f]] for a really neat API to work with files and directories
* doom emacs
Add to your packages.el
#+begin_src elisp
(package! org-fs-tree
:recipe (:host github :repo "ScriptDevil/org-fs-tree"))
#+end_src