Skip to content

Commit 0dd7087

Browse files
committed
Support limiting the number of levels using prefix arguments
1 parent 5fb254b commit 0dd7087

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

README.org

+7
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,16 @@ you open the files with ~C-c C-o~ without having to consider what
104104
In any org-mode buffer:
105105

106106
#+begin_src
107+
M-x package-install ⏎ f
108+
M-x package-install ⏎ names
107109
M-x load-library ⏎ org-fs-tree
108110

111+
# To dump entire FS hierarchy rooted at /path/to/directory
109112
M-x org-fs-tree-dump ⏎ /path/to/directory
113+
114+
# To restrict to say 3 levels of the FS hierarchy rooted at /path/to/directory
115+
116+
C-u 3 M-x org-fs-tree-dump ⏎ /path/to/directory
110117
#+end_src
111118

112119
* Dependencies

org-fs-tree.el

+19-14
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
;;; org-fs-tree.el --- converts filesystem trees to org trees
22

3-
;; Copyright (C) 2015 Ashok Gautham Jadatharan
3+
;; Copyright (C) 2020 Ashok Gautham Jadatharan
44

55
;; Author: Ashok Gautham Jadatharan <[email protected]>
6-
;; Version: 0.1.0
6+
;; Version: 0.2.0
77
;; Package-Requires: ((f "0") (names "0"))
88
;; Keywords: org-mode
99

@@ -38,28 +38,33 @@
3838
(defun -make-heading (s level)
3939
(concat (make-string level ?*) " " s "\n"))
4040

41-
(defun -create-tree (base-dir level)
41+
(defun -create-tree (base-dir level limit-level)
4242
(let* ((full-path (f-full base-dir))
4343
(short-name (if (f-dir? base-dir)
4444
(concat (f-filename base-dir) "/")
4545
(f-filename base-dir)))
4646
(link (-make-link short-name full-path))
4747
(heading (-make-heading link level)))
48-
(if (f-directory? base-dir)
49-
(concat heading
50-
(apply 'concat (mapcar
51-
(lambda (d) (-create-tree d (+ 1 level)))
52-
(f-entries base-dir))))
53-
heading)))
54-
55-
(defun dump (dirname)
48+
(if (or (null limit-level) (< level limit-level))
49+
(if (f-directory? base-dir)
50+
(concat heading
51+
(apply 'concat (mapcar
52+
(lambda (d) (-create-tree d (+ 1 level) limit-level))
53+
(f-entries base-dir))))
54+
heading)
55+
heading)))
56+
57+
(defun dump (arg dirname)
5658
"Dump the file system tree rooted at DIRNAME as an org tree.
5759
Each heading in the org-tree will be a link to the corresponding
58-
file or directory that can be opened using org-open-at-point
60+
file or directory that can be opened using org-open-at-point.
61+
62+
Optional prefix argument can be used to limit the number of
63+
levels.
5964
"
6065

61-
(interactive "DDirectory to dump: ")
62-
(insert (-create-tree dirname 1)))
66+
(interactive "P\nDDirectory to dump: ")
67+
(insert (-create-tree dirname 1 arg)))
6368
)
6469

6570
(provide 'org-fs-tree)

0 commit comments

Comments
 (0)