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/>.
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.
33 ;; Routines for customizing projects and targets.
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.
46 (defun ede-customize-project ()
47 "Edit fields of the current project through EIEIO & Custom."
49 (require 'eieio-custom
)
50 (let* ((ov (oref (ede-current-project) local-variables
))
51 (cp (ede-current-project)))
53 (make-local-variable 'eieio-ede-old-variables
)
54 (setq eieio-ede-old-variables ov
)))
57 (defalias 'customize-project
'ede-customize-project
)
60 (defun ede-customize-current-target()
61 "Edit fields of the current target through EIEIO & Custom."
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
))
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"))
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
))
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'.")
97 (defun ede-project-sort-targets ()
98 "Create a custom-like buffer for sorting targets of current project."
100 (let ((proj (ede-current-project))
103 (switch-to-buffer (get-buffer-create "*EDE sort targets*"))
105 (setq ede-object-project proj
)
106 (widget-create 'push-button
107 :notify
(lambda (&rest ignore
)
108 (let ((targets (oref ede-object-project targets
))
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
)
118 (widget-create 'push-button
119 :notify
(lambda (&rest ignore
)
122 (widget-insert "\n\n")
123 (setq ede-project-sort-targets-order nil
)
126 'ede-project-sort-targets-order
128 (number-sequence 0 (1- (length (oref proj targets
)))))
129 (ede-project-sort-targets-list)
130 (use-local-map widget-keymap
)
132 (goto-char (point-min))))
134 (defun ede-project-sort-targets-list ()
135 "Sort the target list while using `ede-project-sort-targets'."
138 (targets (oref ede-object-project targets
))
139 (inhibit-read-only t
)
140 (inhibit-modification-hooks t
))
141 (goto-char (point-min))
143 (delete-region (point) (point-max))
144 (while (< count
(length targets
))
146 (widget-create 'push-button
147 :notify
`(lambda (&rest ignore
)
148 (let ((cur ede-project-sort-targets-order
))
150 'ede-project-sort-targets-order
154 'ede-project-sort-targets-order
155 (nth (1- ,count
) cur
) ,count
))
156 (ede-project-sort-targets-list))
159 (if (< count
(1- (length targets
)))
160 (widget-create 'push-button
161 :notify
`(lambda (&rest ignore
)
162 (let ((cur ede-project-sort-targets-order
))
164 'ede-project-sort-targets-order
165 (nth ,count cur
) (1+ ,count
))
167 'ede-project-sort-targets-order
168 (nth (1+ ,count
) cur
) ,count
))
169 (ede-project-sort-targets-list))
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
)
186 (if (not (assoc (car (car ov
)) nv
))
190 (kill-local-variable (car (car ov
))))
191 (ede-project-buffers proj
))))
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
199 (defmethod eieio-done-customizing ((target ede-target
))
200 "Call this when a user finishes customizing TARGET."
203 (defmethod ede-commit-project ((proj ede-project
))
204 "Commit any change to PROJ to its file."
208 (provide 'ede
/custom
)
211 ;; generated-autoload-file: "loaddefs.el"
212 ;; generated-autoload-load-name: "ede/custom"
215 ;;; ede/custom.el ends here