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

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

[elpa] externals/phpinspect c848398fe3 2/2: Implement auto-insert-mode i


From: ELPA Syncer
Subject: [elpa] externals/phpinspect c848398fe3 2/2: Implement auto-insert-mode integration
Date: Sat, 28 Sep 2024 12:58:50 -0400 (EDT)

branch: externals/phpinspect
commit c848398fe3aab101ee73a9a43b8fa9dfbc725e33
Author: Hugo Thunnissen <devel@hugot.nl>
Commit: Hugo Thunnissen <devel@hugot.nl>

    Implement auto-insert-mode integration
---
 phpinspect-autoload.el |  8 +++++++-
 phpinspect-name.el     |  4 ++++
 phpinspect.el          | 25 +++++++++++++++++++++++--
 3 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/phpinspect-autoload.el b/phpinspect-autoload.el
index d43837fe00..2e06ea3ab0 100644
--- a/phpinspect-autoload.el
+++ b/phpinspect-autoload.el
@@ -131,7 +131,13 @@ qualified name of a type should be based on the file name 
alone."
       (dolist (dir (phpinspect-psrX-directories strategy))
         (when (string-prefix-p (expand-file-name dir) file-name)
           (throw 'phpinspect--return
-                 (phpinspect-psrX-filename-to-typename strategy dir 
file-name)))))))
+                 (phpinspect-psrX-file-name-to-type-name strategy dir 
file-name)))))))
+
+(defun phpinspect-autoloader-request-type-name (autoloader file-name)
+  (catch 'phpinspect--return
+    (dolist (strat (phpinspect-autoloader-local-strategies autoloader))
+      (when-let ((type-name (phpinspect-al-strategy-request-type-name strat 
file-name)))
+        (throw 'phpinspect--return type-name)))))
 
 (defun phpinspect-autoloader-ensure-file-indexed (autoloader file-name)
   (catch 'phpinspect--break
diff --git a/phpinspect-name.el b/phpinspect-name.el
index 7ee0bdc4a4..0bc0184493 100644
--- a/phpinspect-name.el
+++ b/phpinspect-name.el
@@ -96,6 +96,10 @@ Return value is itself an instance of `phpinspect-name'."
                     (phpinspect-name-string-namespace)
                     (phpinspect-intern-name))))))
 
+(define-inline phpinspect-name-non-fqn-string (name)
+  (inline-quote
+   (string-trim-left (phpinspect-name-string ,name) "\\\\")))
+
 (defun phpinspect-names-to-alist (names)
   (let ((alist))
     (dolist (name names)
diff --git a/phpinspect.el b/phpinspect.el
index 7a239faf15..31980118c1 100644
--- a/phpinspect.el
+++ b/phpinspect.el
@@ -163,8 +163,6 @@
 
 Reparses the entire buffer without token reuse."
   (when (and (boundp 'phpinspect-mode) phpinspect-mode)
-    (phpinspect-buffer-reindex phpinspect-current-buffer)
-
     ;; Make sure that the project's autoloader is aware of the file
     (when-let ((file-name (buffer-file-name))
                (project (phpinspect-buffer-project phpinspect-current-buffer))
@@ -459,5 +457,28 @@ before the search is executed."
     (phpinspect-project-refresh-autoloader project)
     (phpinspect-project-enqueue-include-dirs project)))
 
+(defun phpinspect-insert-skeleton ()
+  "Insert a PHP opening tag and a namespace at the top of the buffer.
+
+Only works when in a PSR0 or PSR4 autoload-able directory."
+  (interactive)
+  (when (and phpinspect-mode buffer-file-name)
+    (when-let ((type-name (phpinspect-autoloader-request-type-name
+                           (phpinspect-project-autoload
+                            (phpinspect-current-project))
+                           buffer-file-name)))
+      (save-excursion
+        (goto-char (point-min))
+
+        (insert (format "<?php
+
+namespace %s;
+
+" (phpinspect-name-non-fqn-string
+   (phpinspect-name-namespace type-name))))))))
+
+(when (featurep 'autoinsert)
+  (define-auto-insert "\\.php$" #'phpinspect-insert-skeleton))
+
 (provide 'phpinspect)
 ;;; phpinspect.el ends here



reply via email to

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