lisp/progmodes/python.el: Updated Copyright years.
[emacs.git] / lisp / version.el
blobe63c51d0d26a2dd52bcc8442e61cc94b2ea3d5ed
1 ;;; version.el --- record version number of Emacs
3 ;; Copyright (C) 1985, 1992, 1994-1995, 1999-2012
4 ;; Free Software Foundation, Inc.
6 ;; Maintainer: FSF
7 ;; Keywords: internal
8 ;; Package: emacs
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;; Commentary:
27 ;;; Code:
29 (defconst emacs-major-version
30 (progn (string-match "^[0-9]+" emacs-version)
31 (string-to-number (match-string 0 emacs-version)))
32 "Major version number of this version of Emacs.
33 This variable first existed in version 19.23.")
35 (defconst emacs-minor-version
36 (progn (string-match "^[0-9]+\\.\\([0-9]+\\)" emacs-version)
37 (string-to-number (match-string 1 emacs-version)))
38 "Minor version number of this version of Emacs.
39 This variable first existed in version 19.23.")
41 (defconst emacs-build-time (current-time)
42 "Time at which Emacs was dumped out.")
44 (defconst emacs-build-system (system-name)
45 "Name of the system on which Emacs was built.")
47 (defvar motif-version-string)
48 (defvar gtk-version-string)
49 (defvar ns-version-string)
51 (defun emacs-version (&optional here)
52 "Return string describing the version of Emacs that is running.
53 If optional argument HERE is non-nil, insert string at point.
54 Don't use this function in programs to choose actions according
55 to the system configuration; look at `system-configuration' instead."
56 (interactive "P")
57 (let ((version-string
58 (format (if (not (called-interactively-p 'interactive))
59 "GNU Emacs %s (%s%s%s)\n of %s on %s"
60 "GNU Emacs %s (%s%s%s) of %s on %s")
61 emacs-version
62 system-configuration
63 (cond ((featurep 'motif)
64 (concat ", " (substring motif-version-string 4)))
65 ((featurep 'gtk)
66 (concat ", GTK+ Version " gtk-version-string))
67 ((featurep 'x-toolkit) ", X toolkit")
68 ((featurep 'ns)
69 (format ", NS %s" ns-version-string))
70 (t ""))
71 (if (and (boundp 'x-toolkit-scroll-bars)
72 (memq x-toolkit-scroll-bars '(xaw xaw3d)))
73 (format ", %s scroll bars"
74 (capitalize (symbol-name x-toolkit-scroll-bars)))
75 "")
76 (format-time-string "%Y-%m-%d" emacs-build-time)
77 emacs-build-system)))
78 (if here
79 (insert version-string)
80 (if (called-interactively-p 'interactive)
81 (message "%s" version-string)
82 version-string))))
84 ;; We hope that this alias is easier for people to find.
85 (defalias 'version 'emacs-version)
87 ;; Set during dumping, this is a defvar so that it can be setq'd.
88 (defvar emacs-bzr-version nil
89 "String giving the bzr revision from which this Emacs was built.
90 Value is the bzr revision number and a revision ID separated by a blank.
91 Value is nil if Emacs was not built from a bzr checkout, or if we could
92 not determine the revision.")
94 (defun emacs-bzr-get-version (&optional dir)
95 "Try to return as a string the bzr revision number of the Emacs sources.
96 Value is the bzr revision number and a revision ID separated by a blank.
97 Value is nil if the sources do not seem to be under bzr, or if we could
98 not determine the revision. Note that this reports on the current state
99 of the sources, which may not correspond to the running Emacs.
101 Optional argument DIR is a directory to use instead of `source-directory'."
102 (or dir (setq dir source-directory))
103 (when (file-directory-p (setq dir (expand-file-name ".bzr/branch" dir)))
104 (let (file loc)
105 (cond ((file-readable-p
106 (setq file (expand-file-name "last-revision" dir)))
107 (with-temp-buffer
108 (insert-file-contents file)
109 (goto-char (point-max))
110 (if (looking-back "\n")
111 (delete-char -1))
112 (buffer-string)))
113 ;; OK, no last-revision. Is it a lightweight checkout?
114 ((file-readable-p
115 (setq file (expand-file-name "location" dir)))
116 ;; If the parent branch is local, try looking there for the revid.
117 (if (setq loc (with-temp-buffer
118 (insert-file-contents file)
119 (if (looking-at "file://\\(.*\\)")
120 (match-string 1))))
121 (emacs-bzr-get-version loc)))
122 ;; Could fall back to eg `bzr testament' at this point.
123 ))))
125 ;; We put version info into the executable in the form that `ident' uses.
126 (purecopy (concat "\n$Id: " (subst-char-in-string ?\n ?\s (emacs-version))
127 " $\n"))
129 ;;; version.el ends here