* puresize.h (BASE_PURESIZE): Increase to 1470000.
[bpt/emacs.git] / lisp / cedet / ede / util.el
CommitLineData
acc33231
CY
1;;; ede/util.el --- EDE utilities
2
cb758101 3;; Copyright (C) 2000, 2005, 2009 Free Software Foundation, Inc.
acc33231
CY
4
5;; Author: Eric M. Ludlam <zappo@gnu.org>
6;; Keywords: project, make
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software: you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23;;; Commentary:
24;;
0b253b12 25;; Utilities that may not require project specific help, and operate
acc33231
CY
26;; on generic EDE structures. Provide user level commands for activities
27;; not directly related to source code organization or makefile generation.
28
29(require 'ede)
30
31;;; Code:
32
33;;; Updating the version of a project.
34;;;###autoload
35(defun ede-update-version (newversion)
36 "Update the current projects main version number.
37Argument NEWVERSION is the version number to use in the current project."
38 (interactive (list (let* ((o (ede-toplevel))
39 (v (oref o version)))
40 (read-string (format "Update Version (was %s): " v)
41 v nil v))))
42 (let ((ede-object (ede-toplevel)))
43 ;; Don't update anything if there was no change.
44 (unless (string= (oref ede-object :version) newversion)
45 (oset ede-object :version newversion)
46 (project-update-version ede-object)
47 (ede-update-version-in-source ede-object newversion))))
48
49(defmethod project-update-version ((ot ede-project))
50 "The :version of the project OT has been updated.
51Handle saving, or other detail."
52 (error "project-update-version not supported by %s" (object-name ot)))
53
54(defmethod ede-update-version-in-source ((this ede-project) version)
55 "Change occurrences of a version string in sources.
56In project THIS, cycle over all targets to give them a chance to set
57their sources to VERSION."
58 (ede-map-targets this (lambda (targ)
59 (ede-update-version-in-source targ version))))
60
61(defmethod ede-update-version-in-source ((this ede-target) version)
62 "In sources for THIS, change version numbers to VERSION."
63 (if (and (slot-boundp this 'versionsource)
64 (oref this versionsource))
65 (let ((vs (oref this versionsource)))
66 (while vs
67 (save-excursion
68 (set-buffer (find-file-noselect
69 (ede-expand-filename this (car vs))))
70 (goto-char (point-min))
71 (let ((case-fold-search t))
72 (if (re-search-forward "version:\\s-*\\([^ \t\n]+\\)" nil t)
73 (progn
74 (save-match-data
75 (ede-make-buffer-writable))
76 (delete-region (match-beginning 1)
77 (match-end 1))
78 (goto-char (match-beginning 1))
79 (insert version)))))
80 (setq vs (cdr vs))))))
81
82;;; Writable files
83;;
84;; Utils for EDE when it needs to write a file that could be covered by a
85;; version control system.
86(defun ede-make-buffer-writable (&optional buffer)
87 "Make sure that BUFFER is writable.
88If BUFFER isn't specified, use the current buffer."
89 (save-excursion
90 (if buffer (set-buffer buffer))
91 (if buffer-read-only
92 (if (and vc-mode
93 (y-or-n-p (format "Check out %s? " (buffer-file-name))))
94 (vc-toggle-read-only)
95 (if (not vc-mode)
96 (toggle-read-only -1))))))
97
98(provide 'ede/util)
99
100;; Local variables:
101;; generated-autoload-file: "loaddefs.el"
102;; generated-autoload-feature: ede/loaddefs
103;; generated-autoload-load-name: "ede/util"
104;; End:
105
3999968a 106;; arch-tag: 3cddf449-7f6a-4c76-86dd-04142c60eba2
acc33231 107;;; ede/util.el ends here