Skip to content

Commit b559c80

Browse files
authored
Merge pull request #713 from emacs-php/feature/php-mode-version
Add php-mode-version-id and make obsolete php-mode-version-number
2 parents 865bc84 + 9603a4f commit b559c80

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

Diff for: CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@ All notable changes of the PHP Mode 1.19.1 release series are documented in this
2121
* Make continued expressions inside lists (arguments and arrays, etc.) have the same indent width as outside the list ([#703])
2222
* (internal) Improved readability of test failures about indentation ([#707])
2323
* `php-doc-annotation-tag` inherits `font-lock-doc-markup-face` if defined in Emacs 28 ([#711])
24+
* Make `php-mode-version` function include a Git tag and revision ([#713])
25+
* Like `"1.23.4-56-xxxxxx"` for example.
2426
* Change `php-phpdoc-type-keywords` to `php-phpdoc-type-names` to avoid confusion ([#717])
2527

28+
### Deprecated
29+
30+
* Make obsolete `php-mode-version-number` contstant variable ([#712])
31+
* `(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.
32+
2633
### Fixed
2734

2835
* Removed invalid definitions that caused errors in some expressions ([#704])
@@ -33,6 +40,7 @@ All notable changes of the PHP Mode 1.19.1 release series are documented in this
3340
[#708]: https://github.com/emacs-php/php-mode/pull/708
3441
[#710]: https://github.com/emacs-php/php-mode/pull/710
3542
[#711]: https://github.com/emacs-php/php-mode/pull/711
43+
[#713]: https://github.com/emacs-php/php-mode/pull/713
3644
[#715]: https://github.com/emacs-php/php-mode/pull/715
3745
[#716]: https://github.com/emacs-php/php-mode/pull/716
3846
[#717]: https://github.com/emacs-php/php-mode/pull/717

Diff for: lisp/php-mode.el

+37-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,27 @@
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+
(save-match-data
96+
(let ((tag (replace-regexp-in-string
97+
(rx bos "v") ""
98+
(shell-command-to-string "git describe --tags")))
99+
(pattern (rx (group (+ any)) eol)))
100+
(if (string-match pattern tag)
101+
(match-string 0 tag)
102+
(error "Faild to obtain git tag"))))
103+
fallback-version)))
104+
"PHP Mode build ID.
105+
106+
The format is follows:
107+
108+
\"1.23.4\": Tagged revision, compiled under Git VCS.
109+
\"1.23.4-56-xxxxxx\": 56 commits after the last tag release, compiled under Git.
110+
\"1.23.4-non-vcs\": Compiled in an environment not managed by Git VCS.")
111+
89112
(autoload 'php-mode-debug "php-mode-debug"
90113
"Display informations useful for debugging PHP Mode." t)
91114

@@ -288,17 +311,20 @@ In that case set to `NIL'."
288311
(defconst php-mode-cc-vertion
289312
(eval-when-compile c-version))
290313

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)))))))
314+
(cl-defun php-mode-version (&key as-number)
315+
"Display string describing the version of PHP Mode.
316+
317+
Although this is an interactive command, it returns a string when called
318+
as a function. Call with AS-NUMBER keyword to compare by `version<'.
319+
320+
\(version<= \"1.24.1\" (php-mode-version :as-number t))"
321+
(interactive (list :as-number nil))
322+
(if as-number
323+
(save-match-data (and (string-match (rx (group (+ (in ".0-9")))) php-mode-version-id)
324+
(match-string 0 php-mode-version-id)))
299325
(funcall
300326
(if (called-interactively-p 'interactive) #'message #'format)
301-
fmt php-mode-version-number)))
327+
"PHP Mode v%s" php-mode-version-id)))
302328

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

0 commit comments

Comments
 (0)