Skip to content

Commit 09e1e42

Browse files
committed
Add php-mode-version-id and make obsolete php-mode-version-number
1 parent c3c442a commit 09e1e42

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ All notable changes of the PHP Mode 1.19.1 release series are documented in this
1515
* Make continued expressions inside lists (arguments and arrays, etc.) have the same indent width as outside the list ([#703])
1616
* (internal) Improved readability of test failures about indentation ([#707])
1717
* `php-doc-annotation-tag` inherits `font-lock-doc-markup-face` if defined in Emacs 28 ([#711])
18+
* Make `php-mode-version` function include a Git tag and revision ([#712])
19+
* Like `"1.23.4-56-xxxxxx"` for example.
20+
21+
### Deprecated
22+
23+
* Make obsolete `php-mode-version-number` contstant variable ([#712])
24+
* `(php-mode-version :as-number t)` is provided for use cases comparing as versions, but generally SHOULD NOT be dependent on the PHP Mode version.
1825

1926
### Fixed
2027

@@ -26,6 +33,7 @@ All notable changes of the PHP Mode 1.19.1 release series are documented in this
2633
[#708]: https://github.com/emacs-php/php-mode/pull/708
2734
[#710]: https://github.com/emacs-php/php-mode/pull/710
2835
[#711]: https://github.com/emacs-php/php-mode/pull/711
36+
[#712]: https://github.com/emacs-php/php-mode/pull/712
2937

3038
## [1.24.1] - 2022-10-08
3139

lisp/php-mode.el

+30-11
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
;; Package-Requires: ((emacs "25.2"))
1414
;; License: GPL-3.0-or-later
1515

16-
(defconst php-mode-version-number "1.24.1"
17-
"PHP Mode version number.")
16+
(eval-and-compile
17+
(make-obsolete-variable
18+
(defconst php-mode-version-number "1.24.1" "PHP Mode version number.")
19+
"Please call (php-mode-version :as-number t) for compatibility." "1.24.2"))
1820

1921
;; This program is free software; you can redistribute it and/or modify
2022
;; it under the terms of the GNU General Public License as published by
@@ -86,6 +88,20 @@
8688
(defvar c-vsemi-status-unknown-p)
8789
(defvar syntax-propertize-via-font-lock))
8890

91+
(defconst php-mode-version-id
92+
(eval-when-compile
93+
(let* ((fallback-version (format "%s-non-vcs" (with-no-warnings php-mode-version-number))))
94+
(if (locate-dominating-file default-directory ".git")
95+
(string-trim-left (string-trim-right (shell-command-to-string "git describe --tags")) "v")
96+
fallback-version)))
97+
"PHP Mode build ID.
98+
99+
The format is follows:
100+
101+
\"1.23.4\": Tagged revision, compiled under Git VCS.
102+
\"1.23.4-56-xxxxxx\": 56 commits after the last tag release, compiled under Git.
103+
\"1.23.4-non-vcs\": Compiled in an environment not managed by Git VCS.")
104+
89105
(autoload 'php-mode-debug "php-mode-debug"
90106
"Display informations useful for debugging PHP Mode." t)
91107

@@ -288,17 +304,20 @@ In that case set to `NIL'."
288304
(defconst php-mode-cc-vertion
289305
(eval-when-compile c-version))
290306

291-
(defun php-mode-version ()
292-
"Display string describing the version of PHP Mode."
293-
(interactive)
294-
(let ((fmt (eval-when-compile (let ((id "$Id$"))
295-
(concat "PHP Mode %s"
296-
(if (string= id (concat [?$ ?I ?d ?$]))
297-
""
298-
(concat " " id)))))))
307+
(cl-defun php-mode-version (&key as-number)
308+
"Display string describing the version of PHP Mode.
309+
310+
Although this is an interactive command, it returns a string when called
311+
as a function. Call with AS-NUMBER keyword to compare by `version<'.
312+
313+
\(version<= \"1.24.1\" (php-mode-version :as-number t))"
314+
(interactive (list :as-number nil))
315+
(if as-number
316+
(save-match-data (and (string-match (rx (group (+ (in ".0-9")))) php-mode-version-id)
317+
(match-string 0 php-mode-version-id)))
299318
(funcall
300319
(if (called-interactively-p 'interactive) #'message #'format)
301-
fmt php-mode-version-number)))
320+
"PHP Mode v%s" php-mode-version-id)))
302321

303322
;;;###autoload
304323
(define-obsolete-variable-alias 'php-available-project-root-files 'php-project-available-root-files "1.19.0")

0 commit comments

Comments
 (0)