From f35bf9a28cd1353595d9149427ba33ef4201cbc1 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Sat, 29 Oct 2022 16:05:14 +0900 Subject: [PATCH 1/4] Add php-mode-version-id and make obsolete php-mode-version-number --- CHANGELOG.md | 8 ++++++++ lisp/php-mode.el | 41 ++++++++++++++++++++++++++++++----------- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cccfd13..3276c010 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,8 +21,15 @@ All notable changes of the PHP Mode 1.19.1 release series are documented in this * Make continued expressions inside lists (arguments and arrays, etc.) have the same indent width as outside the list ([#703]) * (internal) Improved readability of test failures about indentation ([#707]) * `php-doc-annotation-tag` inherits `font-lock-doc-markup-face` if defined in Emacs 28 ([#711]) + * Make `php-mode-version` function include a Git tag and revision ([#713]) + * Like `"1.23.4-56-xxxxxx"` for example. * Change `php-phpdoc-type-keywords` to `php-phpdoc-type-names` to avoid confusion ([#717]) +### Deprecated + + * Make obsolete `php-mode-version-number` contstant variable ([#712]) + * `(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. + ### Fixed * 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 [#708]: https://github.com/emacs-php/php-mode/pull/708 [#710]: https://github.com/emacs-php/php-mode/pull/710 [#711]: https://github.com/emacs-php/php-mode/pull/711 +[#713]: https://github.com/emacs-php/php-mode/pull/713 [#715]: https://github.com/emacs-php/php-mode/pull/715 [#716]: https://github.com/emacs-php/php-mode/pull/716 [#717]: https://github.com/emacs-php/php-mode/pull/717 diff --git a/lisp/php-mode.el b/lisp/php-mode.el index 5e5b66e7..24932bf2 100644 --- a/lisp/php-mode.el +++ b/lisp/php-mode.el @@ -13,8 +13,10 @@ ;; Package-Requires: ((emacs "25.2")) ;; License: GPL-3.0-or-later -(defconst php-mode-version-number "1.24.1" - "PHP Mode version number.") +(eval-and-compile + (make-obsolete-variable + (defconst php-mode-version-number "1.24.1" "PHP Mode version number.") + "Please call (php-mode-version :as-number t) for compatibility." "1.24.2")) ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by @@ -86,6 +88,20 @@ (defvar c-vsemi-status-unknown-p) (defvar syntax-propertize-via-font-lock)) +(defconst php-mode-version-id + (eval-when-compile + (let* ((fallback-version (format "%s-non-vcs" (with-no-warnings php-mode-version-number)))) + (if (locate-dominating-file default-directory ".git") + (string-trim-left (string-trim-right (shell-command-to-string "git describe --tags")) "v") + fallback-version))) + "PHP Mode build ID. + +The format is follows: + +\"1.23.4\": Tagged revision, compiled under Git VCS. +\"1.23.4-56-xxxxxx\": 56 commits after the last tag release, compiled under Git. +\"1.23.4-non-vcs\": Compiled in an environment not managed by Git VCS.") + (autoload 'php-mode-debug "php-mode-debug" "Display informations useful for debugging PHP Mode." t) @@ -288,17 +304,20 @@ In that case set to `NIL'." (defconst php-mode-cc-vertion (eval-when-compile c-version)) -(defun php-mode-version () - "Display string describing the version of PHP Mode." - (interactive) - (let ((fmt (eval-when-compile (let ((id "$Id$")) - (concat "PHP Mode %s" - (if (string= id (concat [?$ ?I ?d ?$])) - "" - (concat " " id))))))) +(cl-defun php-mode-version (&key as-number) + "Display string describing the version of PHP Mode. + +Although this is an interactive command, it returns a string when called +as a function. Call with AS-NUMBER keyword to compare by `version<'. + +\(version<= \"1.24.1\" (php-mode-version :as-number t))" + (interactive (list :as-number nil)) + (if as-number + (save-match-data (and (string-match (rx (group (+ (in ".0-9")))) php-mode-version-id) + (match-string 0 php-mode-version-id))) (funcall (if (called-interactively-p 'interactive) #'message #'format) - fmt php-mode-version-number))) + "PHP Mode v%s" php-mode-version-id))) ;;;###autoload (define-obsolete-variable-alias 'php-available-project-root-files 'php-project-available-root-files "1.19.0") From cf10f7c217bcf876c67957df852a10d2293fffae Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Sun, 30 Oct 2022 01:53:11 +0900 Subject: [PATCH 2/4] Use compat-string-trim-* functions for compatibility --- Cask | 1 + Makefile | 5 ++++- lisp/php-mode.el | 9 +++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Cask b/Cask index e8474685..527f7edd 100644 --- a/Cask +++ b/Cask @@ -1,4 +1,5 @@ (package "php-mode" "1.24.1" "Major mode for editing PHP code") +(source gnu) (source melpa) (package-file "lisp/php-mode.el") diff --git a/Makefile b/Makefile index 97922d2a..883ec9f8 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,10 @@ AUTOLOADS = php-mode-autoloads.el ELCS = $(ELS:.el=.elc) %.elc: %.el - $(EMACS) --batch -L lisp/ -f batch-byte-compile $< + $(EMACS) --batch -L lisp/ --eval \ + "(let ((default-directory (expand-file-name \".cask\" default-directory))) \ + (normal-top-level-add-subdirs-to-load-path))" \ + -f batch-byte-compile $< all: autoloads $(ELCS) authors diff --git a/lisp/php-mode.el b/lisp/php-mode.el index 24932bf2..461b73ce 100644 --- a/lisp/php-mode.el +++ b/lisp/php-mode.el @@ -10,7 +10,7 @@ ;; URL: https://github.com/emacs-php/php-mode ;; Keywords: languages php ;; Version: 1.24.1 -;; Package-Requires: ((emacs "25.2")) +;; Package-Requires: ((emacs "25.2") (compat "28.1.1.0")) ;; License: GPL-3.0-or-later (eval-and-compile @@ -82,6 +82,7 @@ (require 'rx) (require 'cl-lib) (require 'regexp-opt) + (require 'compat-26 nil t) (defvar add-log-current-defun-header-regexp) (defvar add-log-current-defun-function) (defvar c-syntactic-context) @@ -92,7 +93,11 @@ (eval-when-compile (let* ((fallback-version (format "%s-non-vcs" (with-no-warnings php-mode-version-number)))) (if (locate-dominating-file default-directory ".git") - (string-trim-left (string-trim-right (shell-command-to-string "git describe --tags")) "v") + (funcall + (if (and (boundp 'string-trim-left) (boundp 'string-trim-right)) + (lambda (s) (string-trim-left (string-trim-right s) "v")) + (lambda (s) (compat-string-trim-left (compat-string-trim-right s) "v"))) + (shell-command-to-string "git describe --tags")) fallback-version))) "PHP Mode build ID. From 08ef915dc3b7567ea0994ca26097bdb866c42fdf Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Sun, 30 Oct 2022 03:48:56 +0900 Subject: [PATCH 3/4] Revert "Use compat-string-trim-* functions for compatibility" This reverts commit b6382f414126536f46d7d9f976c79b7babec1460. --- Cask | 1 - Makefile | 5 +---- lisp/php-mode.el | 9 ++------- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/Cask b/Cask index 527f7edd..e8474685 100644 --- a/Cask +++ b/Cask @@ -1,5 +1,4 @@ (package "php-mode" "1.24.1" "Major mode for editing PHP code") -(source gnu) (source melpa) (package-file "lisp/php-mode.el") diff --git a/Makefile b/Makefile index 883ec9f8..97922d2a 100644 --- a/Makefile +++ b/Makefile @@ -5,10 +5,7 @@ AUTOLOADS = php-mode-autoloads.el ELCS = $(ELS:.el=.elc) %.elc: %.el - $(EMACS) --batch -L lisp/ --eval \ - "(let ((default-directory (expand-file-name \".cask\" default-directory))) \ - (normal-top-level-add-subdirs-to-load-path))" \ - -f batch-byte-compile $< + $(EMACS) --batch -L lisp/ -f batch-byte-compile $< all: autoloads $(ELCS) authors diff --git a/lisp/php-mode.el b/lisp/php-mode.el index 461b73ce..24932bf2 100644 --- a/lisp/php-mode.el +++ b/lisp/php-mode.el @@ -10,7 +10,7 @@ ;; URL: https://github.com/emacs-php/php-mode ;; Keywords: languages php ;; Version: 1.24.1 -;; Package-Requires: ((emacs "25.2") (compat "28.1.1.0")) +;; Package-Requires: ((emacs "25.2")) ;; License: GPL-3.0-or-later (eval-and-compile @@ -82,7 +82,6 @@ (require 'rx) (require 'cl-lib) (require 'regexp-opt) - (require 'compat-26 nil t) (defvar add-log-current-defun-header-regexp) (defvar add-log-current-defun-function) (defvar c-syntactic-context) @@ -93,11 +92,7 @@ (eval-when-compile (let* ((fallback-version (format "%s-non-vcs" (with-no-warnings php-mode-version-number)))) (if (locate-dominating-file default-directory ".git") - (funcall - (if (and (boundp 'string-trim-left) (boundp 'string-trim-right)) - (lambda (s) (string-trim-left (string-trim-right s) "v")) - (lambda (s) (compat-string-trim-left (compat-string-trim-right s) "v"))) - (shell-command-to-string "git describe --tags")) + (string-trim-left (string-trim-right (shell-command-to-string "git describe --tags")) "v") fallback-version))) "PHP Mode build ID. From 9603a4f54f90fa5cde253e6c9fb9470aacaca33c Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Sun, 30 Oct 2022 03:50:47 +0900 Subject: [PATCH 4/4] Revert string-trim-right --- lisp/php-mode.el | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lisp/php-mode.el b/lisp/php-mode.el index 24932bf2..6843b3a7 100644 --- a/lisp/php-mode.el +++ b/lisp/php-mode.el @@ -90,9 +90,16 @@ (defconst php-mode-version-id (eval-when-compile - (let* ((fallback-version (format "%s-non-vcs" (with-no-warnings php-mode-version-number)))) + (let ((fallback-version (format "%s-non-vcs" (with-no-warnings php-mode-version-number)))) (if (locate-dominating-file default-directory ".git") - (string-trim-left (string-trim-right (shell-command-to-string "git describe --tags")) "v") + (save-match-data + (let ((tag (replace-regexp-in-string + (rx bos "v") "" + (shell-command-to-string "git describe --tags"))) + (pattern (rx (group (+ any)) eol))) + (if (string-match pattern tag) + (match-string 0 tag) + (error "Faild to obtain git tag")))) fallback-version))) "PHP Mode build ID.