Commit | Line | Data |
---|---|---|
722ff82f | 1 | ;;; ede/srecode.el --- EDE utilities on top of SRecoder |
447a30f3 | 2 | |
114f9c96 | 3 | ;; Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc. |
447a30f3 CY |
4 | |
5 | ;; Author: Eric M. Ludlam <eric@siege-engine.com> | |
6 | ||
7 | ;; This file is part of GNU Emacs. | |
8 | ||
9 | ;; GNU Emacs is free software: you can redistribute it and/or modify | |
10 | ;; it under the terms of the GNU General Public License as published by | |
11 | ;; the Free Software Foundation, either version 3 of the License, or | |
12 | ;; (at your option) any later version. | |
13 | ||
14 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | ;; GNU General Public License for more details. | |
18 | ||
19 | ;; You should have received a copy of the GNU General Public License | |
20 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
21 | ||
22 | ;;; Commentary: | |
23 | ;; | |
24 | ;; EDE utilities for using SRecode to generate project files, such as | |
25 | ;; Makefiles. | |
26 | ||
27 | (require 'srecode) | |
28 | ||
29 | (declare-function srecode-create-dictionary "srecode/dictionary") | |
30 | (declare-function srecode-dictionary-set-value "srecode/dictionary") | |
31 | (declare-function srecode-load-tables-for-mode "srecode/find") | |
32 | (declare-function srecode-table "srecode/find") | |
33 | (declare-function srecode-template-get-table "srecode/find") | |
34 | (declare-function srecode-insert-fcn "srecode/insert") | |
a70eb60d | 35 | (declare-function srecode-resolve-arguments "srecode/insert") |
447a30f3 CY |
36 | (declare-function srecode-map-update-map "srecode/map") |
37 | ||
38 | ;;; Code: | |
39 | (defun ede-srecode-setup () | |
e6e267fc CY |
40 | "Initialize Srecode for EDE." |
41 | (require 'srecode/map) | |
42 | (require 'srecode/find) | |
43 | (srecode-map-update-map t) | |
44 | ;; We don't call this unless we need it. Load in the templates. | |
45 | (srecode-load-tables-for-mode 'makefile-mode) | |
46 | (srecode-load-tables-for-mode 'makefile-mode 'ede)) | |
447a30f3 CY |
47 | |
48 | (defmacro ede-srecode-insert-with-dictionary (template &rest forms) | |
49 | "Insert TEMPLATE after executing FORMS with a dictionary. | |
50 | TEMPLATE should specify a context by using a string format of: | |
51 | context:templatename | |
52 | Locally binds the variable DICT to a dictionary which can be | |
53 | updated in FORMS." | |
54 | `(let* ((dict (srecode-create-dictionary)) | |
55 | (temp (srecode-template-get-table (srecode-table) | |
56 | ,template | |
57 | nil | |
58 | 'ede)) | |
59 | ) | |
60 | (when (not temp) | |
61 | (error "EDE template %s for %s not found!" | |
62 | ,template major-mode)) | |
63 | (srecode-resolve-arguments temp dict) | |
64 | ||
65 | ;; Now execute forms for updating DICT. | |
66 | (progn ,@forms) | |
67 | ||
68 | (srecode-insert-fcn temp dict) | |
69 | )) | |
70 | ||
71 | (defun ede-srecode-insert (template &rest dictionary-entries) | |
72 | "Insert at the current point TEMPLATE. | |
73 | TEMPLATE should specify a context by using a string format of: | |
74 | context:templatename | |
75 | Add DICTIONARY-ENTRIES into the dictionary before insertion. | |
76 | Note: Just like `srecode-insert', but templates found in 'ede app." | |
77 | (require 'srecode/insert) | |
78 | (ede-srecode-insert-with-dictionary template | |
79 | ||
80 | ;; Add in optional dictionary entries. | |
81 | (while dictionary-entries | |
82 | (srecode-dictionary-set-value dict | |
83 | (car dictionary-entries) | |
84 | (car (cdr dictionary-entries))) | |
85 | (setq dictionary-entries | |
86 | (cdr (cdr dictionary-entries)))) | |
87 | ||
88 | )) | |
89 | ||
722ff82f | 90 | (provide 'ede/srecode) |
447a30f3 | 91 | |
3999968a | 92 | ;; arch-tag: 75bec542-7cc8-41a4-b5a0-8fb247609f03 |
722ff82f | 93 | ;;; ede/srecode.el ends here |