emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] 208/255: support for viewing lists in a buffer


From: Eric Schulte
Subject: [elpa] 208/255: support for viewing lists in a buffer
Date: Sun, 16 Mar 2014 01:02:49 +0000

eschulte pushed a commit to branch go
in repository elpa.

commit 389a9b0b80ee3fbbc081692b95bf76718d2da689
Author: Eric Schulte <address@hidden>
Date:   Tue Aug 6 00:33:56 2013 -0600

    support for viewing lists in a buffer
---
 list-buffer.el |   74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 74 insertions(+), 0 deletions(-)

diff --git a/list-buffer.el b/list-buffer.el
new file mode 100644
index 0000000..416fda5
--- /dev/null
+++ b/list-buffer.el
@@ -0,0 +1,74 @@
+;;; list-buffer.el --- view a list as a table in a buffer
+
+;; Copyright (C) 2013 Eric Schulte <address@hidden>
+
+;; Author: Eric Schulte <address@hidden>
+;; Created: 2013-08-02
+;; Version: 0.1
+;; Keywords: list buffer cl
+
+;; This file is not (yet) part of GNU Emacs.
+;; However, it is distributed under the same license.
+
+;; GNU Emacs 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, or (at your option)
+;; any later version.
+
+;; GNU Emacs 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 GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
+
+;;; Code:
+(eval-when-compile (require 'cl))
+
+(defvar *buffer-list* nil
+  "List associated with the current list buffer.")
+
+(defvar *buffer-headers* nil
+  "Headers associated with the current list buffer.")
+
+(defun list-buffer-create (buffer list &optional headers)
+  (pop-to-buffer buffer)
+  (set (make-local-variable '*buffer-list*) list)
+  (set (make-local-variable '*buffer-headers*) headers)
+  ;; set commands at the bottom
+  (list-buffer-refresh))
+
+(defun list-format-row (widths row)
+  (apply #'concat
+         (cl-mapcar
+          (lambda (width cell)
+            (if (< (length cell) width)
+                (concat cell (make-list (- width (length cell)) ?\ ))
+              (concat (subseq cell 0 (- width 4)) "... ")))
+          widths row)))
+
+(defun list-buffer-refresh ()
+  (let* ((strings (mapcar (lambda (row)
+                            (mapcar (lambda (cell) (format "%s" cell)) row))
+                          *buffer-list*))
+         (lengths (mapcar (lambda (row) (mapcar #'length row)) strings))
+         (widths (apply #'cl-mapcar #'max lengths)))
+    ;; write headers
+    (when *buffer-headers*
+      (set (make-local-variable 'header-line-format)
+           (list-format-row widths *buffer-headers*)))
+    ;; write rows
+    (delete (point-min) (point-max))
+    (insert (mapconcat (lambda (row) (list-format-row widths row))
+                       strings "\n"))))
+
+(defun list-buffer-sort (key predicate)
+  (set *buffer-list* (cl-sort *buffer-list* predicate :key key)))
+
+(defun list-buffer-filter (key filter)
+  (set *buffer-list* (cl-remove-if-not *buffer-list* filter :key key)))
+
+(provide 'list-buffer)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]