[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/drupal-mode 0cb4bca4d6 216/308: Added ID suggestions for h
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/drupal-mode 0cb4bca4d6 216/308: Added ID suggestions for hook_update_N(). |
Date: |
Tue, 25 Jan 2022 10:59:49 -0500 (EST) |
branch: elpa/drupal-mode
commit 0cb4bca4d67fb94d906ba7ebf85d9eedc9cde7ef
Author: Arne Jørgensen <arne@arnested.dk>
Commit: Arne Jørgensen <arne@arnested.dk>
Added ID suggestions for hook_update_N().
When inserting a hook_update_N() with `drupal-insert-hook` an we will
suggest an ID the hook implementation based on previous update hooks and
Drupal and module major versions.
---
drupal-mode.el | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 50 insertions(+), 2 deletions(-)
diff --git a/drupal-mode.el b/drupal-mode.el
index 53dae43468..7229c12f7b 100644
--- a/drupal-mode.el
+++ b/drupal-mode.el
@@ -527,7 +527,7 @@ buffer."
nil nil "hook_"))
'(setq str v1)
'(setq v2 (let ((hook v1)
- case-fold-search form-id form-id-placeholder)
+ case-fold-search form-id form-id-placeholder upadte-id
update-id-placeholder update-next-id)
(if (string-match "\\([A-Z][A-Z_]*[A-Z]\\)" hook)
(progn
(setq form-id-placeholder (match-string 1 hook))
@@ -536,7 +536,13 @@ buffer."
nil 'drupal-form-id-history
form-id-placeholder))
(setq str (concat hook "() for " form-id))
(replace-regexp-in-string (regexp-quote
form-id-placeholder) form-id hook t))
- hook)))
+ (if (string-match "_\\(N\\)\\'" hook)
+ (progn
+ (setq update-id-placeholder (match-string 1 hook))
+ (setq update-id (read-number
+ (concat "Implements " hook "(): ")
(drupal-next-update-id)))
+ (replace-regexp-in-string (regexp-quote
update-id-placeholder) (number-to-string update-id) hook t))
+ hook))))
(drupal-ensure-newline)
"/**\n"
" * Implements " str "().\n"
@@ -545,6 +551,34 @@ buffer."
" " @ _ "\n"
"}\n")
+(defun drupal-next-update-id ()
+ "Find next update ID for hook_update_N().
+See
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_update_N/7."
+ (let (existing-ids
+ next-id
+ (current-id 0)
+ ;; Lowest possible ID based current Drupal major-version and
+ ;; current module major version.
+ (lowest-possible-id (+ (* (string-to-number (drupal-major-version))
1000)
+ (* (string-to-number
(drupal-module-major-version :default "1")) 100)
+ 1)))
+ ;; Locate existing ID's in current buffer.
+ (save-excursion
+ (goto-char (point-min))
+ (while (re-search-forward "_update_\\([0-9]+\\)(" nil t)
+ (add-to-list 'existing-ids (string-to-number
(match-string-no-properties 1)))))
+ ;; Find the largest of the existing ID's (current ID).
+ (when existing-ids
+ (setq current-id (apply 'max existing-ids)))
+ ;; Bump ID to get next update ID.
+ (setq next-id (+ 1 current-id))
+ ;; If the next ID doesn't match current Drupal major-version and
+ ;; current module major version use ID based on current versions
+ ;; instead.
+ (when (< next-id lowest-possible-id)
+ (setq next-id lowest-possible-id))
+ next-id))
+
(define-skeleton drupal-insert-function
"Insert Drupal function skeleton."
nil
@@ -765,6 +799,20 @@ Used in `drupal-insert-hook' and `drupal-insert-function'."
(insert name)
name)))
+(defun* drupal-module-major-version (&key version default)
+ "Return a modules major version number.
+If VERSION is not set derive it from the buffer local variable
+`drupal-major-version'.
+
+If VERSION (and `drupal-major-version') is nil return DEFAULT."
+ (when (null version)
+ (setq version (or drupal-module-version "")))
+ (let (major-version)
+ (if (string-match "[0-9x\\.]+-\\([0-9]+\\)\\..*" version)
+ (setq major-version (match-string-no-properties 1 version))
+ (setq major-version default))
+ major-version))
+
(defun drupal-major-version (&optional version)
"Return major version number of version string.
If major version number is 4 - return both major and minor."
- [nongnu] elpa/drupal-mode ed90b0c4d8 303/308: Bump version to 0.7.4, (continued)
- [nongnu] elpa/drupal-mode ed90b0c4d8 303/308: Bump version to 0.7.4, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 53d6809d84 304/308: Fix #84: Use cl-lib instead of deprecated cl, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 5b90a053f7 307/308: Merge pull request #86 from skangas/cl-lib, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 17927723ad 308/308: Merge pull request #85 from skangas/bump-version, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode d71bfb0362 246/308: symbol's value as variable is void: gtags-auto-update, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode eb21f8aaac 232/308: Make flycheck-phpcs-standard buffer local, as it should be., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 003953437c 067/308: Ensured blank line when `drupal-insert-hook'., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 5d4558342b 187/308: Added better paragraph filling., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 3c84493988 206/308: Added JS mode indentation., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode f5fe08ccb3 209/308: Improved `drupal-tail-drupal-debug-txt`., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 0cb4bca4d6 216/308: Added ID suggestions for hook_update_N().,
ELPA Syncer <=
- [nongnu] elpa/drupal-mode 44ea6bfd95 221/308: Merge pull request #52 from arnested/flycheck-updates, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 8a432e36cb 231/308: Missing dependency., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode bcf7a8b372 224/308: Introduce an `auto` option for drupal/flymake-phpcs-run-in-place, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 89f2043bde 227/308: Suppress byte-compile-warning., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 73a1531435 242/308: Better default for `drupal/emacs-drush-update-tags-after-save`., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode c727a18be7 226/308: Fixed bug in `drupal-search-documentation`., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 12d79f3507 250/308: Also load gtags.el with helm-gtags., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode f9d5596a57 275/308: Bump version number, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 6f40ad04b7 282/308: Remove drupal-mode-beginning-of-line, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 4f3cffa76d 302/308: Update .travis.yml, ELPA Syncer, 2022/01/25