Personal emacs config
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.1 KiB

  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. (require 'ewoc)
  19. (require 'ein-core)
  20. (cl-defstruct ein:$node
  21. path ; list of path
  22. data ; actual data
  23. class ; list
  24. )
  25. (defun ein:node-new (path data &optional class &rest args)
  26. (apply #'make-ein:$node :path path :data data :class class args))
  27. (defun ein:node-add-class (node &rest classes)
  28. (mapc (lambda (c) (add-to-list (ein:$node-class node) c)) classes))
  29. (defun ein:node-remove-class (node &rest classes)
  30. (let ((node-class (ein:$node-class node)))
  31. (mapc (lambda (c) (setq node-class (delq c node-class))) classes)
  32. (setf (ein:$node-class node) node-class)))
  33. (defun ein:node-has-class (node class)
  34. (memq class (ein:$node-class node)))
  35. (defun ein:node-filter (ewoc-node-list &rest args)
  36. (cl-loop for (key . class) in (ein:plist-iter args)
  37. do (setq ewoc-node-list
  38. (cl-loop for ewoc-node in ewoc-node-list
  39. for node = (ewoc-data ewoc-node)
  40. when (cl-case key
  41. (:is (ein:node-has-class node class))
  42. (:not (not (ein:node-has-class node class)))
  43. (t (error "%s is not supported" key)))
  44. collect ewoc-node)))
  45. ewoc-node-list)
  46. (provide 'ein-node)
  47. ;;; ein-node.el ends here