* lisp/calc-store.el (calc-insert-permanent-variable): Heed case.
[emacs.git] / lisp / version.el
blobc0b975ed31ba381844b0404b1d91c64d6733b517
1 ;;; version.el --- record version number of Emacs
3 ;; Copyright (C) 1985, 1992, 1994-1995, 1999-2015 Free Software
4 ;; Foundation, Inc.
6 ;; Maintainer: emacs-devel@gnu.org
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)
50 (defvar cairo-version-string)
52 (defun emacs-version (&optional here)
53 "Return string describing the version of Emacs that is running.
54 If optional argument HERE is non-nil, insert string at point.
55 Don't use this function in programs to choose actions according
56 to the system configuration; look at `system-configuration' instead."
57 (interactive "P")
58 (let ((version-string
59 (format (if (not (called-interactively-p 'interactive))
60 "GNU Emacs %s (%s%s%s%s)\n of %s on %s"
61 "GNU Emacs %s (%s%s%s%s) of %s on %s")
62 emacs-version
63 system-configuration
64 (cond ((featurep 'motif)
65 (concat ", " (substring motif-version-string 4)))
66 ((featurep 'gtk)
67 (concat ", GTK+ Version " gtk-version-string))
68 ((featurep 'x-toolkit) ", X toolkit")
69 ((featurep 'ns)
70 (format ", NS %s" ns-version-string))
71 (t ""))
72 (if (featurep 'cairo)
73 (format ", cairo version %s" cairo-version-string)
74 "")
75 (if (and (boundp 'x-toolkit-scroll-bars)
76 (memq x-toolkit-scroll-bars '(xaw xaw3d)))
77 (format ", %s scroll bars"
78 (capitalize (symbol-name x-toolkit-scroll-bars)))
79 "")
80 (format-time-string "%Y-%m-%d" emacs-build-time)
81 emacs-build-system)))
82 (if here
83 (insert version-string)
84 (if (called-interactively-p 'interactive)
85 (message "%s" version-string)
86 version-string))))
88 ;; We hope that this alias is easier for people to find.
89 (defalias 'version 'emacs-version)
91 ;; Set during dumping, this is a defvar so that it can be setq'd.
92 (defvar emacs-repository-version nil
93 "String giving the repository revision from which this Emacs was built.
94 Value is nil if Emacs was not built from a repository checkout,
95 or if we could not determine the revision.")
97 (define-obsolete-variable-alias 'emacs-bzr-version
98 'emacs-repository-version "24.4")
100 (define-obsolete-function-alias 'emacs-bzr-get-version
101 'emacs-repository-get-version "24.4")
103 (defun emacs-repository-version-git (dir)
104 "Ask git itself for the version information for directory DIR."
105 (message "Waiting for git...")
106 (with-temp-buffer
107 (let ((default-directory (file-name-as-directory dir)))
108 (and (eq 0
109 (with-demoted-errors "Error running git rev-parse: %S"
110 (call-process "git" nil '(t nil) nil "rev-parse" "HEAD")))
111 (progn (goto-char (point-min))
112 (looking-at "[0-9a-fA-F]\\{40\\}"))
113 (match-string 0)))))
115 (defun emacs-repository--version-git-1 (file)
116 "Internal subroutine of `emacs-repository-get-version'."
117 (when (file-readable-p file)
118 (erase-buffer)
119 (insert-file-contents file)
120 (cond ((looking-at "[0-9a-fA-F]\\{40\\}")
121 (match-string 0))
122 ((looking-at "ref: \\(.*\\)")
123 (emacs-repository--version-git-1
124 (expand-file-name (match-string 1)
125 (file-name-directory file)))))))
127 (defun emacs-repository-get-version (&optional dir external)
128 "Try to return as a string the repository revision of the Emacs sources.
129 The format of the returned string is dependent on the VCS in use.
130 Value is nil if the sources do not seem to be under version
131 control, or if we could not determine the revision. Note that
132 this reports on the current state of the sources, which may not
133 correspond to the running Emacs.
135 Optional argument DIR is a directory to use instead of `source-directory'.
136 Optional argument EXTERNAL non-nil means to just ask the VCS itself,
137 if the sources appear to be under version control. Otherwise only ask
138 the VCS if we cannot find any information ourselves."
139 (or dir (setq dir source-directory))
140 (when (file-directory-p (expand-file-name ".git" dir))
141 (if external
142 (emacs-repository-version-git dir)
143 (or (let ((files '("HEAD" "refs/heads/master"))
144 file rev)
145 (with-temp-buffer
146 (while (and (not rev)
147 (setq file (car files)))
148 (setq file (expand-file-name (format ".git/%s" file) dir)
149 files (cdr files)
150 rev (emacs-repository--version-git-1 file))))
151 rev)
152 ;; AFAICS this doesn't work during dumping (bug#20799).
153 (emacs-repository-version-git dir)))))
155 ;; We put version info into the executable in the form that `ident' uses.
156 (purecopy (concat "\n$Id: " (subst-char-in-string ?\n ?\s (emacs-version))
157 " $\n"))
159 ;;; version.el ends here