1 ;;; ede-util.el --- EDE utilities
3 ;;; Copyright (C) 2000, 2005 Eric M. Ludlam
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
6 ;; Keywords: project, make
7 ;; RCS: $Id: ede-util.el,v 1.1 2007-11-26 15:22:12 michaels Exp $
9 ;; This software 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 2, or (at your option)
14 ;; This software 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; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
26 ;; Utilities that may not require project specific help, and oporate
27 ;; on generic EDE structures. Provide user level commands for activities
28 ;; not directly related to source code organization or makefile generation.
34 ;;; Updating the version of a project.
36 (defun ede-update-version (newversion)
37 "Update the current projects main version number.
38 Argument NEWVERSION is the version number to use in the current project."
39 (interactive (list (let* ((o (ede-toplevel))
41 (read-string (format "Update Version (was %s): " v)
43 (let ((ede-object (ede-toplevel)))
44 ;; Don't update anything if there was no change.
45 (unless (string= (oref ede-object :version) newversion)
46 (oset ede-object :version newversion)
47 (project-update-version ede-object)
48 (ede-update-version-in-source ede-object newversion))))
50 (defmethod project-update-version ((ot ede-project))
51 "The :version of the project OT has been updated.
52 Handle saving, or other detail."
53 (error "project-update-version not supported by %s" (object-name ot)))
55 (defmethod ede-update-version-in-source ((this ede-project) version)
56 "Change occurrences of a version string in sources.
57 In project THIS, cycle over all targets to give them a chance to set
58 their sources to VERSION."
59 (ede-map-targets this (lambda (targ)
60 (ede-update-version-in-source targ version))))
62 (defmethod ede-update-version-in-source ((this ede-target) version)
63 "In sources for THIS, change version numbers to VERSION."
64 (if (and (slot-boundp this 'versionsource)
65 (oref this versionsource))
66 (let ((vs (oref this versionsource)))
69 (set-buffer (find-file-noselect
70 (ede-expand-filename this (car vs))))
71 (goto-char (point-min))
72 (let ((case-fold-search t))
73 (if (re-search-forward "version:\\s-*\\([^ \t\n]+\\)" nil t)
76 (ede-make-buffer-writable))
77 (delete-region (match-beginning 1)
79 (goto-char (match-beginning 1))
81 (setq vs (cdr vs))))))
85 ;; Utils for EDE when it needs to write a file that could be covered by a
86 ;; version control system.
87 (defun ede-make-buffer-writable (&optional buffer)
88 "Make sure that BUFFER is writable.
89 If BUFFER isn't specified, use the current buffer."
91 (if buffer (set-buffer buffer))
94 (y-or-n-p (format "Check out %s? " (buffer-file-name))))
97 (toggle-read-only -1))))))
101 ;;; ede-util.el ends here