|
1 | 1 | ;;; org-fs-tree.el --- converts filesystem trees to org trees
|
2 | 2 |
|
3 |
| -;; Copyright (C) 2015 Ashok Gautham Jadatharan |
| 3 | +;; Copyright (C) 2020 Ashok Gautham Jadatharan |
4 | 4 |
|
5 | 5 | ;; Author: Ashok Gautham Jadatharan <[email protected]>
|
6 |
| -;; Version: 0.1.0 |
| 6 | +;; Version: 0.2.0 |
7 | 7 | ;; Package-Requires: ((f "0") (names "0"))
|
8 | 8 | ;; Keywords: org-mode
|
9 | 9 |
|
|
38 | 38 | (defun -make-heading (s level)
|
39 | 39 | (concat (make-string level ?*) " " s "\n"))
|
40 | 40 |
|
41 |
| -(defun -create-tree (base-dir level) |
| 41 | +(defun -create-tree (base-dir level limit-level) |
42 | 42 | (let* ((full-path (f-full base-dir))
|
43 | 43 | (short-name (if (f-dir? base-dir)
|
44 | 44 | (concat (f-filename base-dir) "/")
|
45 | 45 | (f-filename base-dir)))
|
46 | 46 | (link (-make-link short-name full-path))
|
47 | 47 | (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) |
56 | 58 | "Dump the file system tree rooted at DIRNAME as an org tree.
|
57 | 59 | 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. |
59 | 64 | "
|
60 | 65 |
|
61 |
| - (interactive "DDirectory to dump: ") |
62 |
| - (insert (-create-tree dirname 1))) |
| 66 | + (interactive "P\nDDirectory to dump: ") |
| 67 | + (insert (-create-tree dirname 1 arg))) |
63 | 68 | )
|
64 | 69 |
|
65 | 70 | (provide 'org-fs-tree)
|
0 commit comments