aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2026-04-07 09:15:36 -0700
committerGravatar Tom Willemse2026-04-07 09:15:36 -0700
commit6c68d871fbbb9bd2c270fc5cb162c8be58666736 (patch)
tree648b49be1bc8782f54d20b48549aeee8972bfed7
parentf054cce03bafd2104f72cd1bdeeaa19e28b888f3 (diff)
downloademacs-config-6c68d871fbbb9bd2c270fc5cb162c8be58666736.tar.gz
emacs-config-6c68d871fbbb9bd2c270fc5cb162c8be58666736.zip
oni-php: Add auto-insert template for .php files
-rw-r--r--oni-php/oni-php.el35
-rw-r--r--oni-php/snippets/php-mode/namespace6
2 files changed, 33 insertions, 8 deletions
diff --git a/oni-php/oni-php.el b/oni-php/oni-php.el
index b9a5c79..612d645 100644
--- a/oni-php/oni-php.el
+++ b/oni-php/oni-php.el
@@ -4,7 +4,7 @@
;; Author: Tom Willemse <tom@ryuslash.org>
;; Keywords: local
-;; Version: 2026.0406.114757
+;; Version: 2026.0406.154601
;; Package-Requires: (oni-yasnippet oni-flycheck oni-company oni-hydra oni-smartparens ggtags fic-mode company-php rainbow-delimiters rainbow-identifiers)
;; This program is free software; you can redistribute it and/or modify
@@ -177,6 +177,23 @@ Otherwise call FUNC with ARGS. This is meant as advice around
(oni-php-doc-comment))
(t (apply func args))))
+(defun oni-php-generate-namespace ()
+ (string-join
+ (mapcar
+ (lambda (s)
+ (let ((case-fold-search nil))
+ (if (string-match-p (rx upper-case) s)
+ s
+ (capitalize s))))
+ (cdr (split-string
+ (directory-file-name
+ (file-name-directory
+ (file-relative-name
+ buffer-file-name
+ (project-root (project-current)))))
+ "/")))
+ "\\"))
+
(defhydra php-mode-hydra (:color blue)
("a" align-current "Align current selection"))
@@ -251,13 +268,25 @@ Otherwise call FUNC with ARGS. This is meant as advice around
(add-to-list 'grep-files-aliases '("php" . "*.php *.inc *.module")))
(with-eval-after-load 'autoinsert
- (setf (map-elt auto-insert-alist (rx "Test.php" eos))
+ (setf (map-elt auto-insert-alist (rx ".php" eos))
+ '(nil
+ "<?php\n"
+ "\n"
+ "declare(strict_types=1);\n"
+ "\n"
+ "namespace " (oni-php-generate-namespace) ";\n"
+ "\n"
+ "class " (file-name-sans-extension (file-name-nondirectory (buffer-file-name))) "\n"
+ "{\n"
+ > _ "\n"
+ "}\n")
+ (map-elt auto-insert-alist (rx "Test.php" eos))
'(nil
"<?php\n"
"\n"
"declare(strict_types=1);\n"
"\n"
- "namespace " (string-join (mapcar #'capitalize (cdr (split-string (directory-file-name (file-name-directory (file-relative-name buffer-file-name (project-root (project-current))))) "/"))) "\\") ";\n"
+ "namespace " (oni-php-generate-namespace) ";\n"
"\n"
"use Illuminate\\Foundation\\Testing\\RefreshDatabase;\n"
"use Illuminate\\Foundation\\Testing\\WithFaker;\n"
diff --git a/oni-php/snippets/php-mode/namespace b/oni-php/snippets/php-mode/namespace
index 01abd02..7a5b5e1 100644
--- a/oni-php/snippets/php-mode/namespace
+++ b/oni-php/snippets/php-mode/namespace
@@ -2,8 +2,4 @@
# name: namespace
# key: ns
# --
-namespace ${1:`(string-join
- (mapcar
- (lambda (s) (let ((case-fold-search nil)) (if (string-match-p (rx upper-case) s) s (capitalize s))))
- (cdr (split-string (directory-file-name (file-name-directory (file-relative-name buffer-file-name (project-root (project-current))))) "/")))
- "\\")`}; \ No newline at end of file
+namespace ${1:`(oni-php-generate-namespace)`}; \ No newline at end of file