diff options
author | Sean Allred <code@seanallred.com> | 2014-11-07 13:38:23 -0500 |
---|---|---|
committer | Sean Allred <code@seanallred.com> | 2014-11-07 13:38:23 -0500 |
commit | 87fecb1707510885b8974c8fe2d061f4b1c927d7 (patch) | |
tree | 5659c9b2cb0cdda9393107779f4075c1233a18a4 /sx.el | |
parent | 0d59cd54c84b1245d0dd0ea25ff49d7abd5e60b7 (diff) | |
parent | 70e96f5aa97eca789a307fb29302fca20c13686f (diff) |
Merge pull request #31 from vermiculus/rename
Rename files to sx prefix (and variables accordingly)
Diffstat (limited to 'sx.el')
-rw-r--r-- | sx.el | 76 |
1 files changed, 76 insertions, 0 deletions
@@ -0,0 +1,76 @@ +;;; sx.el --- core functions -*- lexical-binding: t; -*- + +;; Copyright (C) 2014 Sean Allred + +;; Author: Sean Allred <code@seanallred.com> + +;; 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 <http://www.gnu.org/licenses/>. + +;;; Commentary: + +;; This file defines basic commands used by all other parts of +;; StackMode. + +;;; Code: + + +;;; Requirements +(defun sx-message (format-string &rest args) + "Display a message" + (message "[stack] %s" (apply #'format format-string args))) + +(defun sx--thing-as-string (thing &optional sequence-sep) + "Return a string representation of THING. If THING is already +a string, just return it." + (cond + ((stringp thing) thing) + ((symbolp thing) (symbol-name thing)) + ((numberp thing) (number-to-string thing)) + ((sequencep thing) + (mapconcat #'sx--thing-as-string + thing (if sequence-sep sequence-sep ";"))))) + +(defun sx--filter-data (data desired-tree) + "Filters DATA and returns the DESIRED-TREE" + (if (vectorp data) + (apply #'vector + (mapcar (lambda (entry) + (sx--filter-data + entry desired-tree)) + data)) + (delq + nil + (mapcar (lambda (cons-cell) + ;; TODO the resolution of `f' is O(2n) in the worst + ;; case. It may be faster to implement the same + ;; functionality as a `while' loop to stop looking the + ;; list once it has found a match. Do speed tests. + ;; See edfab4443ec3d376c31a38bef12d305838d3fa2e. + (let ((f (or (memq (car cons-cell) desired-tree) + (assoc (car cons-cell) desired-tree)))) + (when f + (if (and (sequencep (cdr cons-cell)) + (sequencep (elt (cdr cons-cell) 0))) + (cons (car cons-cell) + (sx--filter-data + (cdr cons-cell) (cdr f))) + cons-cell)))) + data)))) + +(provide 'sx) +;;; sx.el ends here + +;; Local Variables: +;; indent-tabs-mode: nil +;; End: |