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

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

[nongnu] elpa/drupal-mode 65efa5b78a 186/308: Removed usage of directory


From: ELPA Syncer
Subject: [nongnu] elpa/drupal-mode 65efa5b78a 186/308: Removed usage of directory local variables.
Date: Tue, 25 Jan 2022 10:59:46 -0500 (EST)

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

    Removed usage of directory local variables.
    
    Fixes #12 and #42.
---
 drupal-mode.el | 100 +++++++++++++++++++++++++++++++++------------------------
 1 file changed, 58 insertions(+), 42 deletions(-)

diff --git a/drupal-mode.el b/drupal-mode.el
index bd9d5582f1..b085286d3c 100644
--- a/drupal-mode.el
+++ b/drupal-mode.el
@@ -558,13 +558,16 @@ Heavily based on `message-beginning-of-line' from Gnus."
 
 
 
+(defvar drupal-local-variables (make-hash-table :test 'equal)
+  "Drupal local variables hash table.")
+
 ;; Detect Drupal and Drupal version
 (defun drupal-detect-drupal-version ()
   "Detect if the buffer is part of a Drupal project.
 If part of a Drupal project also detect the version of Drupal and
 the location of DRUPAL_ROOT."
   (interactive)
-  (hack-local-variables)
+  (drupal-hack-local-variables)
   (when (or (not drupal-version)
             (not drupal-rootdir))
     (dolist (file '("modules/system/system.module" "includes/bootstrap.inc" 
"core/lib/Drupal.php"))
@@ -572,55 +575,68 @@ the location of DRUPAL_ROOT."
         (when here
           (let ((dir (locate-dominating-file here file)))
             (when dir
-              (with-current-buffer (find-file-noselect (concat dir file) t)
-                (save-excursion
-                  (widen)
-                  (goto-char (point-min))
-                  (when (re-search-forward "\\(define('VERSION',\\|const 
VERSION =\\) +'\\(.+\\)'" nil t)
-                    (dir-locals-set-class-variables 'drupal-site `((nil . 
((drupal-version . ,(match-string-no-properties 2))
-                                                                           
(drupal-rootdir . ,dir)))))
-                    (dir-locals-set-directory-class dir 'drupal-site)))
-                (setq drupal-version (match-string-no-properties 2))))))))
-    (hack-local-variables))
+              (with-temp-buffer
+                (insert-file-contents-literally (concat dir file))
+                (goto-char (point-min))
+                (when (re-search-forward "\\(define('VERSION',\\|const VERSION 
=\\) +'\\(.+\\)'" nil t)
+                  (setq drupal-version (match-string-no-properties 2))
+                  (puthash (expand-file-name dir) `((drupal-version . 
,drupal-version)
+                                                    (drupal-rootdir . ,dir))
+                           drupal-local-variables)))))))))
+  (drupal-hack-local-variables)
   (let ((module (drupal-locate-dominating-module (or buffer-file-name 
default-directory) t))
         (version drupal-version)
         (module-name nil)
         (module-version nil)
         (project nil))
     (when module
-      (with-current-buffer (find-file-noselect module t)
-        (save-excursion
-          (widen)
-          (goto-char (point-min))
-          (when (and (not drupal-version)
-                     (re-search-forward "^core *=" nil t))
-            (re-search-forward " *\"?\\([^\"]+\\)\"?" (point-at-eol) t)
-            (setq version (match-string-no-properties 1)))
-          (goto-char (point-min))
-          (when (re-search-forward "^name *=" nil t)
-            (re-search-forward " *\"?\\([^\"]+\\)\"?" (point-at-eol) t)
-            (setq module-name (match-string-no-properties 1)))
-          (goto-char (point-min))
-          (when (re-search-forward "^version *=" nil t)
-            (re-search-forward " *\"?\\([^\"]+\\)\"?" (point-at-eol) t)
-            (setq module-version (match-string-no-properties 1)))
-          (goto-char (point-min))
-          (when (re-search-forward "^project *=" nil t)
-            (re-search-forward " *\"?\\([^\"]+\\)\"?" (point-at-eol) t)
-            (setq project (match-string-no-properties 1)))
-          (when (and (string= project "drupal")
-                     (string= module-version "VERSION"))
-            (setq module-version version))))
-      (dir-locals-set-class-variables 'drupal-module `((nil . ((drupal-module 
. ,(file-name-nondirectory
-                                                                               
   (file-name-sans-extension module)))
-                                                               (drupal-version 
. ,version)
-                                                               
(drupal-module-name . ,module-name)
-                                                               
(drupal-module-version . ,module-version)
-                                                               (drupal-project 
. ,project)))))
-      (dir-locals-set-directory-class (file-name-directory module) 
'drupal-module)))
-  (hack-local-variables)
+      (with-temp-buffer
+        (insert-file-contents-literally module)
+        (goto-char (point-min))
+        (when (and (not drupal-version)
+                   (re-search-forward "^core *=" nil t))
+          (re-search-forward " *\"?\\([^\"]+\\)\"?" (point-at-eol) t)
+          (setq version (match-string-no-properties 1)))
+        (goto-char (point-min))
+        (when (re-search-forward "^name *=" nil t)
+          (re-search-forward " *\"?\\([^\"]+\\)\"?" (point-at-eol) t)
+          (setq module-name (match-string-no-properties 1)))
+        (goto-char (point-min))
+        (when (re-search-forward "^version *=" nil t)
+          (re-search-forward " *\"?\\([^\"]+\\)\"?" (point-at-eol) t)
+          (setq module-version (match-string-no-properties 1)))
+        (goto-char (point-min))
+        (when (re-search-forward "^project *=" nil t)
+          (re-search-forward " *\"?\\([^\"]+\\)\"?" (point-at-eol) t)
+          (setq project (match-string-no-properties 1)))
+        (when (and (string= project "drupal")
+                   (string= module-version "VERSION"))
+          (setq module-version version))
+        (puthash (expand-file-name (file-name-directory module)) 
`((drupal-module . ,(file-name-nondirectory
+                                                                               
       (file-name-sans-extension module)))
+                                                                   
(drupal-version . ,version)
+                                                                   
(drupal-module-name . ,module-name)
+                                                                   
(drupal-module-version . ,module-version)
+                                                                   
(drupal-project . ,project))
+                 drupal-local-variables))))
+  (drupal-hack-local-variables)
   drupal-version)
 
+(defun drupal-hack-local-variables ()
+  "Drupal hack `drupal-local-variables' as buffer local variables."
+  (interactive)
+  (let ((dir (expand-file-name (or (file-name-directory buffer-file-name) 
default-directory)))
+        matches)
+    (maphash (lambda (key value)
+               (when (string-match (concat "^" (regexp-quote key)) dir)
+                 (add-to-list 'matches key)))
+             drupal-local-variables)
+    (sort matches #'(lambda (a b) (> (string-width a) (string-width b))))
+    (dolist (elem matches)
+      (let ((vars (gethash elem drupal-local-variables)))
+        (dolist (var vars)
+          (set (make-local-variable (car var)) (cdr-safe var)))))))
+
 (defun drupal-locate-dominating-module (file &optional info-file-location)
   "Look up the directory hierarchy from FILE for a Drupal module root.
 Stop at the first parent where a matching module is found and



reply via email to

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