[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/taxy f0b926f 34/39: Add: Diredy example
From: |
ELPA Syncer |
Subject: |
[elpa] externals/taxy f0b926f 34/39: Add: Diredy example |
Date: |
Fri, 27 Aug 2021 10:57:36 -0400 (EDT) |
branch: externals/taxy
commit f0b926f48f5826054d3d537afe799069c3fb3c85
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>
Add: Diredy example
---
examples/README.org | 12 ++++++
examples/diredy.el | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++
images/diredy.png | Bin 0 -> 33772 bytes
3 files changed, 115 insertions(+)
diff --git a/examples/README.org b/examples/README.org
index 06d7325..1820f59 100644
--- a/examples/README.org
+++ b/examples/README.org
@@ -2,6 +2,18 @@
Some example applcations using ~taxy~.
+* Diredy
+
+[[file:diredy.el][Diredy]] rearranges a Dired buffer, grouping files and
directories by their size and MIME type. Use it like:
+
+#+BEGIN_SRC elisp
+ (require 'diredy)
+#+END_SRC
+
+Then open a Dired buffer and =M-x diredy RET=, and it will be rearranged like
so:
+
+[[../images/diredy.png]]
+
* Musicy
[[file:musicy.el][Musicy]] displays a music library in a ~magit-section~
buffer. Use it like:
diff --git a/examples/diredy.el b/examples/diredy.el
new file mode 100644
index 0000000..c951664
--- /dev/null
+++ b/examples/diredy.el
@@ -0,0 +1,103 @@
+;;; diredy.el --- Flexible grouping for files in Dired buffers -*-
lexical-binding: t; -*-
+
+;; Copyright (C) 2021 Adam Porter
+
+;; Author: Adam Porter <adam@alphapapa.net>
+;; Keywords: convenience
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This library provides a command, `diredy', that rearranges a Dired
+;; buffer into a hierarchy by file size and MIME type.
+
+;;; Code:
+
+;;;; Requirements
+
+(require 'taxy)
+(require 'taxy-magit-section)
+
+(require 'dired)
+(require 'mailcap)
+
+;;;; Variables
+
+(defvar diredy-taxy
+ (cl-labels ((file-name
+ (string) (let* ((start (text-property-not-all 0 (length string)
'dired-filename nil string))
+ (end (text-property-any start (length string)
'dired-filename nil string)))
+ (substring string start end)))
+ (file-extension
+ (filename) (file-name-extension filename))
+ (file-type (string)
+ (when-let ((extension (file-extension (file-name
string))))
+ (mailcap-extension-to-mime extension)))
+ (file-size
+ (filename) (file-attribute-size (file-attributes filename)))
+ (file-size-group
+ (string) (pcase (file-size (file-name string))
+ ('nil "No size")
+ ((pred (> 1024))
+ "< 1K")
+ ((pred (> 102400))
+ "< 100K")
+ ((pred (> 1048576))
+ "< 1M")
+ ((pred (> 10485760))
+ "< 10M")
+ (_ ">= 10M")))
+ (file-dir? (string) (if (file-directory-p (file-name string))
+ "Directory" "File")))
+ (make-taxy
+ :name "Diredy"
+ :taxys (list (make-taxy :name "Types"
+ :take (apply-partially #'taxy-take-keyed* (list
#'file-dir? #'file-size-group #'file-type)))))))
+
+(defvar dired-mode)
+
+;;;; Customization
+
+
+;;;; Commands
+
+(defun diredy ()
+ "Apply grouping to current Dired buffer."
+ (interactive)
+ (cl-assert (eq 'dired-mode major-mode))
+ (use-local-map (make-composed-keymap (list dired-mode-map
magit-section-mode-map)))
+ (save-excursion
+ (goto-char (point-min))
+ (forward-line 2)
+ (let* ((lines (save-excursion
+ (cl-loop until (eobp)
+ collect (buffer-substring (point-at-bol)
(point-at-eol))
+ do (forward-line 1))))
+ (filled-taxy (thread-last diredy-taxy
+ taxy-emptied
+ (taxy-fill lines)))
+ (inhibit-read-only t)
+ (taxy-magit-section-indent 2))
+ (delete-region (point) (point-max))
+ (taxy-magit-section-insert filled-taxy :objects 'first))))
+
+;;;; Functions
+
+
+;;;; Footer
+
+(provide 'diredy)
+
+;;; diredy.el ends here
diff --git a/images/diredy.png b/images/diredy.png
new file mode 100644
index 0000000..4e8f3e5
Binary files /dev/null and b/images/diredy.png differ
- [elpa] externals/taxy 6c5b7c7 07/39: Add: taxy-apply, (continued)
- [elpa] externals/taxy 6c5b7c7 07/39: Add: taxy-apply, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy 02217c4 11/39: Docs: Add comments, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy 408a32b 09/39: Docs: Tidy, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy 09724dd 10/39: Add: taxy-take-keyed, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy 9d44dba 13/39: Change: taxy-apply -> taxy-map, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy 6eff6ae 18/39: Docs: Put Contents first, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy 0a57638 17/39: Docs: Mention threading macros, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy 0dce844 16/39: Docs: Add example of incremental filling, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy e09dc38 32/39: Add: (taxy-mapc*) And musicy.el example, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy bd28836 24/39: Meta: Headers, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy f0b926f 34/39: Add: Diredy example,
ELPA Syncer <=
- [elpa] externals/taxy 21e6fa6 22/39: Docs: Commentary, header, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy e56ae33 26/39: Meta: .gitignore, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy 15eb9b7 31/39: Docs: Tidy, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy 01e956a 04/39: Rename function, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy 657823b 03/39: Docs: Tidy example, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy f115919 06/39: Add: taxy-copy and reverse args to taxy-fill, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy a94ab1c 05/39: Tidy, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy 751e9d7 08/39: Show reusable taxys, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy d355d3a 14/39: Docs: Add mascot, ELPA Syncer, 2021/08/27
- [elpa] externals/taxy 3b253a6 21/39: Tidy: (taxy-fill) Argument order in labeled function, ELPA Syncer, 2021/08/27