util.el 3.5 KB

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