comparison lisp/cedet/ede/srecode.el @ 104502:cdbbb89893d5

lisp/cedet/ede/pmake.el (ede-proj-makefile-create): Require ede/srecode. lisp/cedet/ede/srecode.el: New file.
author Chong Yidong <cyd@stupidchicken.com>
date Sun, 20 Sep 2009 22:05:17 +0000
parents
children bde759149ba1
comparison
equal deleted inserted replaced
104501:b5dbdf25d1c5 104502:cdbbb89893d5
1 ;;; ede-srecode.el --- EDE utilities on top of SRecoder
2
3 ;; Copyright (C) 2008 Free Software Foundation, Inc.
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")
35 (declare-function srecode-resolve-arguments "srecode/map")
36 (declare-function srecode-map-update-map "srecode/map")
37
38 ;;; Code:
39 (defun ede-srecode-setup ()
40 "Update various paths to get SRecode to identify our macros."
41 (let* ((lib (locate-library "ede.el" t))
42 (ededir (file-name-directory lib))
43 (tmpdir (file-name-as-directory
44 (expand-file-name "templates" ededir))))
45 (when (not tmpdir)
46 (error "Unable to location EDE Templates directory"))
47
48 ;; Rig up the map.
49 (require 'srecode/map)
50 (require 'srecode/find)
51 (add-to-list 'srecode-map-load-path tmpdir)
52 (srecode-map-update-map t)
53
54 ;; We don't call this unless we need it. Load in the templates.
55 (srecode-load-tables-for-mode 'makefile-mode)
56 (srecode-load-tables-for-mode 'makefile-mode 'ede)
57
58 ;; @todo - autoconf files.
59
60 ))
61
62 (defmacro ede-srecode-insert-with-dictionary (template &rest forms)
63 "Insert TEMPLATE after executing FORMS with a dictionary.
64 TEMPLATE should specify a context by using a string format of:
65 context:templatename
66 Locally binds the variable DICT to a dictionary which can be
67 updated in FORMS."
68 `(let* ((dict (srecode-create-dictionary))
69 (temp (srecode-template-get-table (srecode-table)
70 ,template
71 nil
72 'ede))
73 )
74 (when (not temp)
75 (error "EDE template %s for %s not found!"
76 ,template major-mode))
77 (srecode-resolve-arguments temp dict)
78
79 ;; Now execute forms for updating DICT.
80 (progn ,@forms)
81
82 (srecode-insert-fcn temp dict)
83 ))
84
85 (defun ede-srecode-insert (template &rest dictionary-entries)
86 "Insert at the current point TEMPLATE.
87 TEMPLATE should specify a context by using a string format of:
88 context:templatename
89 Add DICTIONARY-ENTRIES into the dictionary before insertion.
90 Note: Just like `srecode-insert', but templates found in 'ede app."
91 (require 'srecode/insert)
92 (ede-srecode-insert-with-dictionary template
93
94 ;; Add in optional dictionary entries.
95 (while dictionary-entries
96 (srecode-dictionary-set-value dict
97 (car dictionary-entries)
98 (car (cdr dictionary-entries)))
99 (setq dictionary-entries
100 (cdr (cdr dictionary-entries))))
101
102 ))
103
104 (provide 'ede-srecode)
105
106 ;;; ede-srecode.el ends here