Add 2012 to FSF copyright years for Emacs files (do not merge to trunk)
[bpt/emacs.git] / lisp / cedet / ede / srecode.el
CommitLineData
722ff82f 1;;; ede/srecode.el --- EDE utilities on top of SRecoder
447a30f3 2
49f70d46 3;; Copyright (C) 2008, 2009, 2010, 2011, 2012 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)
cb85c0d8
EL
46 (srecode-load-tables-for-mode 'makefile-mode 'ede)
47 (srecode-load-tables-for-mode 'autoconf-mode)
48 (srecode-load-tables-for-mode 'autoconf-mode 'ede))
447a30f3
CY
49
50(defmacro ede-srecode-insert-with-dictionary (template &rest forms)
51 "Insert TEMPLATE after executing FORMS with a dictionary.
52TEMPLATE should specify a context by using a string format of:
53 context:templatename
54Locally binds the variable DICT to a dictionary which can be
55updated in FORMS."
56 `(let* ((dict (srecode-create-dictionary))
57 (temp (srecode-template-get-table (srecode-table)
58 ,template
59 nil
60 'ede))
61 )
62 (when (not temp)
63 (error "EDE template %s for %s not found!"
64 ,template major-mode))
65 (srecode-resolve-arguments temp dict)
66
67 ;; Now execute forms for updating DICT.
68 (progn ,@forms)
69
70 (srecode-insert-fcn temp dict)
71 ))
72
73(defun ede-srecode-insert (template &rest dictionary-entries)
74 "Insert at the current point TEMPLATE.
75TEMPLATE should specify a context by using a string format of:
76 context:templatename
77Add DICTIONARY-ENTRIES into the dictionary before insertion.
78Note: Just like `srecode-insert', but templates found in 'ede app."
79 (require 'srecode/insert)
80 (ede-srecode-insert-with-dictionary template
81
82 ;; Add in optional dictionary entries.
83 (while dictionary-entries
84 (srecode-dictionary-set-value dict
85 (car dictionary-entries)
86 (car (cdr dictionary-entries)))
87 (setq dictionary-entries
88 (cdr (cdr dictionary-entries))))
89
90 ))
91
722ff82f 92(provide 'ede/srecode)
447a30f3 93
3999968a 94;; arch-tag: 75bec542-7cc8-41a4-b5a0-8fb247609f03
722ff82f 95;;; ede/srecode.el ends here