|
| 1 | +;;; dashboard-ls.el --- Display files/directories in current directory on Dashboard -*- lexical-binding: t; -*- |
| 2 | + |
| 3 | +;; Copyright (C) 2020 Shen, Jen-Chieh |
| 4 | +;; Created date 2020-03-24 17:49:59 |
| 5 | + |
| 6 | +;; Author: Shen, Jen-Chieh <[email protected]> |
| 7 | +;; Description: Display files/directories in current directory on Dashboard. |
| 8 | +;; Keyword: directory file show dashboard |
| 9 | +;; Version: 0.1.0 |
| 10 | +;; Package-Requires: ((emacs "24.3") (dashboard "1.2.5") (f "0.20.0")) |
| 11 | +;; URL: https://github.com/jcs090218/dashboard-ls |
| 12 | + |
| 13 | +;; This file is NOT part of GNU Emacs. |
| 14 | + |
| 15 | +;; This program is free software; you can redistribute it and/or modify |
| 16 | +;; it under the terms of the GNU General Public License as published by |
| 17 | +;; the Free Software Foundation, either version 3 of the License, or |
| 18 | +;; (at your option) any later version. |
| 19 | + |
| 20 | +;; This program is distributed in the hope that it will be useful, |
| 21 | +;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | +;; GNU General Public License for more details. |
| 24 | + |
| 25 | +;; You should have received a copy of the GNU General Public License |
| 26 | +;; along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 27 | + |
| 28 | +;;; Commentary: |
| 29 | +;; |
| 30 | +;; Display files/directories in current directory on Dashboard. |
| 31 | +;; |
| 32 | + |
| 33 | +;;; Code: |
| 34 | + |
| 35 | +(require 'f) |
| 36 | + |
| 37 | +(require 'dashboard) |
| 38 | +(require 'dashboard-widgets) |
| 39 | + |
| 40 | +(add-to-list 'dashboard-item-generators '(ls-directories . dashboard-ls--insert-file)) |
| 41 | +(add-to-list 'dashboard-item-generators '(ls-files . dashboard-ls--insert-dir)) |
| 42 | + |
| 43 | +(defvar dashboard-ls-path nil |
| 44 | + "Update to date current path. |
| 45 | +Use this variable when you don't have the `default-directory' up to date.") |
| 46 | + |
| 47 | +(defun dashboard-ls--insert-dir (list-size) |
| 48 | + "Add the list of LIST-SIZE items from current directory." |
| 49 | + (dashboard-insert-section |
| 50 | + "Current Directories:" |
| 51 | + (let* ((current-dir (if dashboard-ls-path |
| 52 | + dashboard-ls-path |
| 53 | + default-directory)) |
| 54 | + (dir-lst (f-directories current-dir)) |
| 55 | + (opt-dir-lst '())) |
| 56 | + (dolist (dir dir-lst) |
| 57 | + (push (concat dir "/") opt-dir-lst)) |
| 58 | + (reverse opt-dir-lst)) |
| 59 | + list-size |
| 60 | + "d" |
| 61 | + `(lambda (&rest ignore) (find-file-existing ,el)) |
| 62 | + (abbreviate-file-name el))) |
| 63 | + |
| 64 | +(defun dashboard-ls--insert-file (list-size) |
| 65 | + "Add the list of LIST-SIZE items from current files." |
| 66 | + (dashboard-insert-section |
| 67 | + "Current Files:" |
| 68 | + (let ((current-dir (if dashboard-ls-path |
| 69 | + dashboard-ls-path |
| 70 | + default-directory))) |
| 71 | + (f-files current-dir)) |
| 72 | + list-size |
| 73 | + "f" |
| 74 | + `(lambda (&rest ignore) (find-file-existing ,el)) |
| 75 | + (abbreviate-file-name el))) |
| 76 | + |
| 77 | +(provide 'dashboard-ls) |
| 78 | +;;; dashboard-ls.el ends here |
0 commit comments