Update copyright year to 2014 by running admin/update-copyright.
[emacs.git] / lisp / cedet / ede / util.el
blob434c28a5a3411becc968a4cd17e132744ba73e56
1 ;;; ede/util.el --- EDE utilities
3 ;; Copyright (C) 2000, 2005, 2009-2014 Free Software Foundation, Inc.
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
6 ;; Keywords: project, make
8 ;; This file is part of GNU Emacs.
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.
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.
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/>.
23 ;;; Commentary:
25 ;; Utilities that may not require project specific help, and operate
26 ;; on generic EDE structures. Provide user level commands for activities
27 ;; not directly related to source code organization or makefile generation.
29 (require 'ede)
31 ;;; Code:
33 ;;; Updating the version of a project.
34 ;;;###autoload
35 (defun ede-update-version (newversion)
36 "Update the current projects main version number.
37 Argument 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))))
49 (defmethod project-update-version ((ot ede-project))
50 "The :version of the project OT has been updated.
51 Handle saving, or other detail."
52 (error "project-update-version not supported by %s" (eieio-object-name ot)))
54 (defmethod ede-update-version-in-source ((this ede-project) version)
55 "Change occurrences of a version string in sources.
56 In project THIS, cycle over all targets to give them a chance to set
57 their sources to VERSION."
58 (ede-map-targets this (lambda (targ)
59 (ede-update-version-in-source targ version))))
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 (with-current-buffer (find-file-noselect
68 (ede-expand-filename this (car vs)))
69 (goto-char (point-min))
70 (let ((case-fold-search t))
71 (if (re-search-forward "version:\\s-*\\([^ \t\n]+\\)" nil t)
72 (progn
73 (save-match-data
74 (ede-make-buffer-writable))
75 (delete-region (match-beginning 1)
76 (match-end 1))
77 (goto-char (match-beginning 1))
78 (insert version)))))
79 (setq vs (cdr vs))))))
81 ;;; Writable files
83 ;; Utils for EDE when it needs to write a file that could be covered by a
84 ;; version control system.
85 (defun ede-make-buffer-writable (&optional buffer)
86 "Make sure that BUFFER is writable.
87 If BUFFER isn't specified, use the current buffer."
88 (save-excursion
89 (if buffer (set-buffer buffer))
90 (setq buffer-read-only nil)))
92 (provide 'ede/util)
94 ;; Local variables:
95 ;; generated-autoload-file: "loaddefs.el"
96 ;; generated-autoload-load-name: "ede/util"
97 ;; End:
99 ;;; ede/util.el ends here