Update copyright year to 2015
[emacs.git] / lisp / cedet / ede / custom.el
blob3cc3a48c27a5af703e8db546400d55f221bbac6c
1 ;;; ede/custom.el --- customization of EDE projects.
3 ;; Copyright (C) 2010-2015 Free Software Foundation, Inc.
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
7 ;; This file is part of GNU Emacs.
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.
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.
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/>.
22 ;;; Commentary:
24 ;; Customization commands/hooks for EDE.
26 ;; EIEIO supports customizing objects, and EDE uses this to allow
27 ;; users to change basic settings in their projects.
30 ;;; Code:
31 ;;; Customization
33 ;; Routines for customizing projects and targets.
35 (require 'ede)
36 (eval-when-compile (require 'eieio-custom))
38 (defvar eieio-ede-old-variables nil
39 "The old variables for a project.")
41 ;;; Customization Commands
43 ;; These commands initialize customization of EDE control objects.
45 ;;;###autoload
46 (defun ede-customize-project ()
47 "Edit fields of the current project through EIEIO & Custom."
48 (interactive)
49 (require 'eieio-custom)
50 (let* ((ov (oref (ede-current-project) local-variables))
51 (cp (ede-current-project)))
52 (ede-customize cp)
53 (make-local-variable 'eieio-ede-old-variables)
54 (setq eieio-ede-old-variables ov)))
56 ;;;###autoload
57 (defalias 'customize-project 'ede-customize-project)
59 ;;;###autoload
60 (defun ede-customize-current-target()
61 "Edit fields of the current target through EIEIO & Custom."
62 (interactive)
63 (require 'eieio-custom)
64 (if (not (obj-of-class-p ede-object ede-target))
65 (error "Current file is not part of a target"))
66 (ede-customize-target ede-object))
68 ;;;###autoload
69 (defalias 'customize-target 'ede-customize-current-target)
71 (defun ede-customize-target (obj)
72 "Edit fields of the current target through EIEIO & Custom.
73 OBJ is the target object to customize."
74 (require 'eieio-custom)
75 (if (and obj (not (obj-of-class-p obj ede-target)))
76 (error "No logical target to customize"))
77 (ede-customize obj))
79 (defmethod ede-customize ((proj ede-project))
80 "Customize the EDE project PROJ."
81 (eieio-customize-object proj 'default))
83 (defmethod ede-customize ((target ede-target))
84 "Customize the EDE TARGET."
85 (eieio-customize-object target 'default))
87 ;;; Target Sorting
89 ;; Target order can be important, but custom doesn't support a way
90 ;; to resort items in a list. This function by David Engster allows
91 ;; targets to be re-arranged.
93 (defvar ede-project-sort-targets-order nil
94 "Variable for tracking target order in `ede-project-sort-targets'.")
96 ;;;###autoload
97 (defun ede-project-sort-targets ()
98 "Create a custom-like buffer for sorting targets of current project."
99 (interactive)
100 (let ((proj (ede-current-project))
101 (count 1)
102 current order)
103 (switch-to-buffer (get-buffer-create "*EDE sort targets*"))
104 (erase-buffer)
105 (setq ede-object-project proj)
106 (widget-create 'push-button
107 :notify (lambda (&rest ignore)
108 (let ((targets (oref ede-object-project targets))
109 cur newtargets)
110 (while (setq cur (pop ede-project-sort-targets-order))
111 (setq newtargets (append newtargets
112 (list (nth cur targets)))))
113 (oset ede-object-project targets newtargets))
114 (ede-commit-project ede-object-project)
115 (kill-buffer))
116 " Accept ")
117 (widget-insert " ")
118 (widget-create 'push-button
119 :notify (lambda (&rest ignore)
120 (kill-buffer))
121 " Cancel ")
122 (widget-insert "\n\n")
123 (setq ede-project-sort-targets-order nil)
124 (mapc (lambda (x)
125 (add-to-ordered-list
126 'ede-project-sort-targets-order
127 x x))
128 (number-sequence 0 (1- (length (oref proj targets)))))
129 (ede-project-sort-targets-list)
130 (use-local-map widget-keymap)
131 (widget-setup)
132 (goto-char (point-min))))
134 (defun ede-project-sort-targets-list ()
135 "Sort the target list while using `ede-project-sort-targets'."
136 (save-excursion
137 (let ((count 0)
138 (targets (oref ede-object-project targets))
139 (inhibit-read-only t)
140 (inhibit-modification-hooks t))
141 (goto-char (point-min))
142 (forward-line 2)
143 (delete-region (point) (point-max))
144 (while (< count (length targets))
145 (if (> count 0)
146 (widget-create 'push-button
147 :notify `(lambda (&rest ignore)
148 (let ((cur ede-project-sort-targets-order))
149 (add-to-ordered-list
150 'ede-project-sort-targets-order
151 (nth ,count cur)
152 (1- ,count))
153 (add-to-ordered-list
154 'ede-project-sort-targets-order
155 (nth (1- ,count) cur) ,count))
156 (ede-project-sort-targets-list))
157 " Up ")
158 (widget-insert " "))
159 (if (< count (1- (length targets)))
160 (widget-create 'push-button
161 :notify `(lambda (&rest ignore)
162 (let ((cur ede-project-sort-targets-order))
163 (add-to-ordered-list
164 'ede-project-sort-targets-order
165 (nth ,count cur) (1+ ,count))
166 (add-to-ordered-list
167 'ede-project-sort-targets-order
168 (nth (1+ ,count) cur) ,count))
169 (ede-project-sort-targets-list))
170 " Down ")
171 (widget-insert " "))
172 (widget-insert (concat " " (number-to-string (1+ count)) ".: "
173 (oref (nth (nth count ede-project-sort-targets-order)
174 targets) name) "\n"))
175 (setq count (1+ count))))))
177 ;;; Customization hooks
179 ;; These hooks are used when finishing up a customization.
180 (defmethod eieio-done-customizing ((proj ede-project))
181 "Call this when a user finishes customizing PROJ."
182 (let ((ov eieio-ede-old-variables)
183 (nv (oref proj local-variables)))
184 (setq eieio-ede-old-variables nil)
185 (while ov
186 (if (not (assoc (car (car ov)) nv))
187 (save-excursion
188 (mapc (lambda (b)
189 (set-buffer b)
190 (kill-local-variable (car (car ov))))
191 (ede-project-buffers proj))))
192 (setq ov (cdr ov)))
193 (mapc (lambda (b) (ede-set-project-variables proj b))
194 (ede-project-buffers proj))))
196 ;; These two methods should be implemented by subclasses of
197 ;; project and targets in order to account for user specified
198 ;; changes.
199 (defmethod eieio-done-customizing ((target ede-target))
200 "Call this when a user finishes customizing TARGET."
201 nil)
203 (defmethod ede-commit-project ((proj ede-project))
204 "Commit any change to PROJ to its file."
208 (provide 'ede/custom)
210 ;; Local variables:
211 ;; generated-autoload-file: "loaddefs.el"
212 ;; generated-autoload-load-name: "ede/custom"
213 ;; End:
215 ;;; ede/custom.el ends here