srecode.el 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. ;;; ede/srecode.el --- EDE utilities on top of SRecoder
  2. ;; Copyright (C) 2008-2012 Free Software Foundation, Inc.
  3. ;; Author: Eric M. Ludlam <eric@siege-engine.com>
  4. ;; This file is part of GNU Emacs.
  5. ;; GNU Emacs 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. ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;;
  17. ;; EDE utilities for using SRecode to generate project files, such as
  18. ;; Makefiles.
  19. (require 'srecode)
  20. (declare-function srecode-create-dictionary "srecode/dictionary")
  21. (declare-function srecode-dictionary-set-value "srecode/dictionary")
  22. (declare-function srecode-load-tables-for-mode "srecode/find")
  23. (declare-function srecode-table "srecode/find")
  24. (declare-function srecode-template-get-table "srecode/find")
  25. (declare-function srecode-insert-fcn "srecode/insert")
  26. (declare-function srecode-resolve-arguments "srecode/insert")
  27. (declare-function srecode-map-update-map "srecode/map")
  28. ;;; Code:
  29. (defun ede-srecode-setup ()
  30. "Initialize Srecode for EDE."
  31. (require 'srecode/map)
  32. (require 'srecode/find)
  33. (srecode-map-update-map t)
  34. ;; We don't call this unless we need it. Load in the templates.
  35. (srecode-load-tables-for-mode 'makefile-mode)
  36. (srecode-load-tables-for-mode 'makefile-mode 'ede)
  37. (srecode-load-tables-for-mode 'autoconf-mode)
  38. (srecode-load-tables-for-mode 'autoconf-mode 'ede))
  39. (defmacro ede-srecode-insert-with-dictionary (template &rest forms)
  40. "Insert TEMPLATE after executing FORMS with a dictionary.
  41. TEMPLATE should specify a context by using a string format of:
  42. context:templatename
  43. Locally binds the variable DICT to a dictionary which can be
  44. updated in FORMS."
  45. `(let* ((dict (srecode-create-dictionary))
  46. (temp (srecode-template-get-table (srecode-table)
  47. ,template
  48. nil
  49. 'ede))
  50. )
  51. (when (not temp)
  52. (error "EDE template %s for %s not found!"
  53. ,template major-mode))
  54. (srecode-resolve-arguments temp dict)
  55. ;; Now execute forms for updating DICT.
  56. (progn ,@forms)
  57. (srecode-insert-fcn temp dict)
  58. ))
  59. (defun ede-srecode-insert (template &rest dictionary-entries)
  60. "Insert at the current point TEMPLATE.
  61. TEMPLATE should specify a context by using a string format of:
  62. context:templatename
  63. Add DICTIONARY-ENTRIES into the dictionary before insertion.
  64. Note: Just like `srecode-insert', but templates found in 'ede app."
  65. (require 'srecode/insert)
  66. (ede-srecode-insert-with-dictionary template
  67. ;; Add in optional dictionary entries.
  68. (while dictionary-entries
  69. (srecode-dictionary-set-value dict
  70. (car dictionary-entries)
  71. (car (cdr dictionary-entries)))
  72. (setq dictionary-entries
  73. (cdr (cdr dictionary-entries))))
  74. ))
  75. (provide 'ede/srecode)
  76. ;;; ede/srecode.el ends here