Skip to content

Commit f35bf9a

Browse files
committed
Add php-mode-version-id and make obsolete php-mode-version-number
1 parent 865bc84 commit f35bf9a

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
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

lisp/php-mode.el

Lines changed: 30 additions & 11 deletions
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)