emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/drupal-mode 9c5f0066d5 071/308: Added function arguments o


From: ELPA Syncer
Subject: [nongnu] elpa/drupal-mode 9c5f0066d5 071/308: Added function arguments on `drupal-insert-hook'.
Date: Tue, 25 Jan 2022 10:59:30 -0500 (EST)

branch: elpa/drupal-mode
commit 9c5f0066d52994019aea77fe09888437db61b88d
Author: Arne Jørgensen <arne@arnested.dk>
Commit: Arne Jørgensen <arne@arnested.dk>

    Added function arguments on `drupal-insert-hook'.
    
    Using `drupal-insert-hook' insert the function arguments for the hook.
    
    Two functions returning these arguments are added:
    `drupal-get-function-args' and `drupal/gtags-get-function-args'.
    
    The first one is too slow for real usage. The second one is fast, but
    only enabled if you use gtags.
---
 drupal-mode.el  | 28 +++++++++++++++++++++++++++-
 drupal/gtags.el | 11 +++++++++++
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/drupal-mode.el b/drupal-mode.el
index 2f070f0208..c0cee4fe58 100644
--- a/drupal-mode.el
+++ b/drupal-mode.el
@@ -374,6 +374,18 @@ should save your files with unix style end of line."
 Used by `drupal-insert-hook' to provide completions on hooks.")
 (make-variable-buffer-local 'drupal-symbol-collection)
 
+(defvar drupal-get-function-args nil
+  "A function returning the function arguments for a Drupal function.
+Used by `drupal-insert-hook' to fill in arguments on hooks.
+
+The specified function should take two arguments: the function to
+find arguments for and the drupal major version.
+
+See `drupal-get-function-args' (slow) and
+`drupal/gtags-get-function-args' for functions returning Drupal
+function arguments.")
+(make-variable-buffer-local 'drupal-get-function-args)
+
 (define-skeleton drupal-insert-hook
   "Insert Drupal hook function skeleton."
   nil
@@ -386,7 +398,7 @@ Used by `drupal-insert-hook' to provide completions on 
hooks.")
   "/**\n"
   " * Implements " v1 "().\n"
   " */\n"
-  "function " (replace-regexp-in-string "hook" (drupal-module-name) v1) "(" @ 
- ") {\n"
+  "function " (replace-regexp-in-string "hook" (drupal-module-name) v1) "(" 
(funcall drupal-get-function-args v1 (drupal-major-version)) ") {\n"
   "  " @ _ "\n"
   "}\n")
 
@@ -414,6 +426,20 @@ Defaults to one blank line if optional argument NUM is not 
specified."
 \\{" (number-to-string var) "\\}") (line-beginning-position (- var)))
                         (setq result (+ 1 result))))))))
 
+(defun drupal-get-function-args (symbol &optional version)
+  "Get function arguments from `drupal-search-url'.
+It is really slow to download `drupal-search-url'. You should
+probably not use this. Have a look at using GNU GLOBAL / Gtags
+instead."
+  (unless version
+    (setq version (drupal-detect-drupal-version)))
+  (with-temp-buffer
+    (url-insert-file-contents (format-spec drupal-search-url `((?v . ,version)
+                                                               (?s . 
,symbol))))
+    (search-forward "<tr class=\"active\">" nil t)
+    (search-forward-regexp (concat symbol "(\\(.*\\))") nil t)
+    (match-string-no-properties 1)))
+
 
 
 ;; Detect Drupal and Drupal version
diff --git a/drupal/gtags.el b/drupal/gtags.el
index 21ad5cb536..96d9ae3e4b 100644
--- a/drupal/gtags.el
+++ b/drupal/gtags.el
@@ -38,8 +38,19 @@
     ;; `gtags-completing-gtags' so that inserting hooks will do
     ;; completion based on gtags.
     (setq drupal-symbol-collection #'(lambda() (gtags-completing-gtags "" nil 
t)))
+    (setq drupal-get-function-args #'drupal/gtags-get-function-args)
     (gtags-mode 1)))
 
+(defun drupal/gtags-get-function-args (symbol &optional version)
+  "Get function arguments from GNU GLOBAL."
+  (when (and (boundp 'drupal-rootdir)
+             (file-exists-p (concat drupal-rootdir "GTAGS")))
+    (with-temp-buffer
+      (call-process gtags-global-command nil t nil "-x" symbol)
+      (goto-char (point-min))
+      (search-forward-regexp ".*(\\(.*\\)).*" nil t)
+      (match-string 1))))
+
 (add-hook 'drupal-mode-hook #'drupal/gtags-enable)
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]