ein-node.el 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. ;;; ein-node.el --- Structure to hold data in ewoc node
  2. ;; Copyright (C) 2012- Takafumi Arakaki
  3. ;; Author: Takafumi Arakaki <aka.tkf at gmail.com>
  4. ;; This file is NOT part of GNU Emacs.
  5. ;; ein-node.el is free software: you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; ein-node.el is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with ein-node.el. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;;
  17. ;;; Code:
  18. (eval-when-compile (require 'cl))
  19. (require 'ewoc)
  20. (require 'ein-core)
  21. (defstruct ein:$node
  22. path ; list of path
  23. data ; actual data
  24. class ; list
  25. )
  26. (defun ein:node-new (path data &optional class &rest args)
  27. (apply #'make-ein:$node :path path :data data :class class args))
  28. (defun ein:node-add-class (node &rest classes)
  29. (mapc (lambda (c) (add-to-list (ein:$node-class node) c)) classes))
  30. (defun ein:node-remove-class (node &rest classes)
  31. (let ((node-class (ein:$node-class node)))
  32. (mapc (lambda (c) (setq node-class (delq c node-class))) classes)
  33. (setf (ein:$node-class node) node-class)))
  34. (defun ein:node-has-class (node class)
  35. (memq class (ein:$node-class node)))
  36. (defun ein:node-filter (ewoc-node-list &rest args)
  37. (loop for (key . class) in (ein:plist-iter args)
  38. do (setq ewoc-node-list
  39. (loop for ewoc-node in ewoc-node-list
  40. for node = (ewoc-data ewoc-node)
  41. when (case key
  42. (:is (ein:node-has-class node class))
  43. (:not (not (ein:node-has-class node class)))
  44. (t (error "%s is not supported" key)))
  45. collect ewoc-node)))
  46. ewoc-node-list)
  47. (provide 'ein-node)
  48. ;;; ein-node.el ends here