custom.el 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. ;;; ede/custom.el --- customization of EDE projects.
  2. ;; Copyright (C) 2010-2012 Free Software Foundation, Inc.
  3. ;; Author: Eric M. Ludlam <zappo@gnu.org>
  4. ;; This file is part of GNU Emacs.
  5. ;; GNU Emacs is free software: you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; GNU Emacs is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;;
  17. ;; Customization commands/hooks for EDE.
  18. ;;
  19. ;; EIEIO supports customizing objects, and EDE uses this to allow
  20. ;; users to change basic settings in their projects.
  21. ;;
  22. ;;; Code:
  23. ;;; Customization
  24. ;;
  25. ;; Routines for customizing projects and targets.
  26. (require 'ede)
  27. (eval-when-compile (require 'eieio-custom))
  28. (defvar eieio-ede-old-variables nil
  29. "The old variables for a project.")
  30. ;;; Customization Commands
  31. ;;
  32. ;; These commands initialize customization of EDE control objects.
  33. ;;;###autoload
  34. (defun ede-customize-project ()
  35. "Edit fields of the current project through EIEIO & Custom."
  36. (interactive)
  37. (require 'eieio-custom)
  38. (let* ((ov (oref (ede-current-project) local-variables))
  39. (cp (ede-current-project)))
  40. (ede-customize cp)
  41. (make-local-variable 'eieio-ede-old-variables)
  42. (setq eieio-ede-old-variables ov)))
  43. ;;;###autoload
  44. (defalias 'customize-project 'ede-customize-project)
  45. ;;;###autoload
  46. (defun ede-customize-current-target()
  47. "Edit fields of the current target through EIEIO & Custom."
  48. (interactive)
  49. (require 'eieio-custom)
  50. (if (not (obj-of-class-p ede-object ede-target))
  51. (error "Current file is not part of a target"))
  52. (ede-customize-target ede-object))
  53. ;;;###autoload
  54. (defalias 'customize-target 'ede-customize-current-target)
  55. (defun ede-customize-target (obj)
  56. "Edit fields of the current target through EIEIO & Custom.
  57. OBJ is the target object to customize."
  58. (require 'eieio-custom)
  59. (if (and obj (not (obj-of-class-p obj ede-target)))
  60. (error "No logical target to customize"))
  61. (ede-customize obj))
  62. (defmethod ede-customize ((proj ede-project))
  63. "Customize the EDE project PROJ."
  64. (eieio-customize-object proj 'default))
  65. (defmethod ede-customize ((target ede-target))
  66. "Customize the EDE TARGET."
  67. (eieio-customize-object target 'default))
  68. ;;; Target Sorting
  69. ;;
  70. ;; Target order can be important, but custom doesn't support a way
  71. ;; to resort items in a list. This function by David Engster allows
  72. ;; targets to be re-arranged.
  73. (defvar ede-project-sort-targets-order nil
  74. "Variable for tracking target order in `ede-project-sort-targets'.")
  75. ;;;###autoload
  76. (defun ede-project-sort-targets ()
  77. "Create a custom-like buffer for sorting targets of current project."
  78. (interactive)
  79. (let ((proj (ede-current-project))
  80. (count 1)
  81. current order)
  82. (switch-to-buffer (get-buffer-create "*EDE sort targets*"))
  83. (erase-buffer)
  84. (setq ede-object-project proj)
  85. (widget-create 'push-button
  86. :notify (lambda (&rest ignore)
  87. (let ((targets (oref ede-object-project targets))
  88. cur newtargets)
  89. (while (setq cur (pop ede-project-sort-targets-order))
  90. (setq newtargets (append newtargets
  91. (list (nth cur targets)))))
  92. (oset ede-object-project targets newtargets))
  93. (ede-commit-project ede-object-project)
  94. (kill-buffer))
  95. " Accept ")
  96. (widget-insert " ")
  97. (widget-create 'push-button
  98. :notify (lambda (&rest ignore)
  99. (kill-buffer))
  100. " Cancel ")
  101. (widget-insert "\n\n")
  102. (setq ede-project-sort-targets-order nil)
  103. (mapc (lambda (x)
  104. (add-to-ordered-list
  105. 'ede-project-sort-targets-order
  106. x x))
  107. (number-sequence 0 (1- (length (oref proj targets)))))
  108. (ede-project-sort-targets-list)
  109. (use-local-map widget-keymap)
  110. (widget-setup)
  111. (goto-char (point-min))))
  112. (defun ede-project-sort-targets-list ()
  113. "Sort the target list while using `ede-project-sort-targets'."
  114. (save-excursion
  115. (let ((count 0)
  116. (targets (oref ede-object-project targets))
  117. (inhibit-read-only t)
  118. (inhibit-modification-hooks t))
  119. (goto-char (point-min))
  120. (forward-line 2)
  121. (delete-region (point) (point-max))
  122. (while (< count (length targets))
  123. (if (> count 0)
  124. (widget-create 'push-button
  125. :notify `(lambda (&rest ignore)
  126. (let ((cur ede-project-sort-targets-order))
  127. (add-to-ordered-list
  128. 'ede-project-sort-targets-order
  129. (nth ,count cur)
  130. (1- ,count))
  131. (add-to-ordered-list
  132. 'ede-project-sort-targets-order
  133. (nth (1- ,count) cur) ,count))
  134. (ede-project-sort-targets-list))
  135. " Up ")
  136. (widget-insert " "))
  137. (if (< count (1- (length targets)))
  138. (widget-create 'push-button
  139. :notify `(lambda (&rest ignore)
  140. (let ((cur ede-project-sort-targets-order))
  141. (add-to-ordered-list
  142. 'ede-project-sort-targets-order
  143. (nth ,count cur) (1+ ,count))
  144. (add-to-ordered-list
  145. 'ede-project-sort-targets-order
  146. (nth (1+ ,count) cur) ,count))
  147. (ede-project-sort-targets-list))
  148. " Down ")
  149. (widget-insert " "))
  150. (widget-insert (concat " " (number-to-string (1+ count)) ".: "
  151. (oref (nth (nth count ede-project-sort-targets-order)
  152. targets) name) "\n"))
  153. (setq count (1+ count))))))
  154. ;;; Customization hooks
  155. ;;
  156. ;; These hooks are used when finishing up a customization.
  157. (defmethod eieio-done-customizing ((proj ede-project))
  158. "Call this when a user finishes customizing PROJ."
  159. (let ((ov eieio-ede-old-variables)
  160. (nv (oref proj local-variables)))
  161. (setq eieio-ede-old-variables nil)
  162. (while ov
  163. (if (not (assoc (car (car ov)) nv))
  164. (save-excursion
  165. (mapc (lambda (b)
  166. (set-buffer b)
  167. (kill-local-variable (car (car ov))))
  168. (ede-project-buffers proj))))
  169. (setq ov (cdr ov)))
  170. (mapc (lambda (b) (ede-set-project-variables proj b))
  171. (ede-project-buffers proj))))
  172. ;; These two methods should be implemented by subclasses of
  173. ;; project and targets in order to account for user specified
  174. ;; changes.
  175. (defmethod eieio-done-customizing ((target ede-target))
  176. "Call this when a user finishes customizing TARGET."
  177. nil)
  178. (defmethod ede-commit-project ((proj ede-project))
  179. "Commit any change to PROJ to its file."
  180. nil
  181. )
  182. (provide 'ede/custom)
  183. ;; Local variables:
  184. ;; generated-autoload-file: "loaddefs.el"
  185. ;; generated-autoload-load-name: "ede/custom"
  186. ;; End:
  187. ;;; ede/custom.el ends here