aboutsummaryrefslogtreecommitdiffstats
path: root/oni-php/oni-php.el
diff options
context:
space:
mode:
Diffstat (limited to 'oni-php/oni-php.el')
-rw-r--r--oni-php/oni-php.el26
1 files changed, 21 insertions, 5 deletions
diff --git a/oni-php/oni-php.el b/oni-php/oni-php.el
index 36bf76f..603f028 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.0331.120917
+;; Version: 2026.0406.114757
;; 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
@@ -103,14 +103,27 @@ nil for some reason."
(insert "use " class ";\n")
(pulse-momentary-highlight-region start (point)))))))
+(defun oni-php--syntax-in-string-p (syntax)
+ "Does SYNTAX indicate point is inside a string?"
+ (nth 3 syntax))
+
+(defun oni-php--syntax-in-comment-p (syntax)
+ "Does SYNTAX indicate point is inside a comment?"
+ (nth 4 syntax))
+
+(defun oni-php--in-string-or-comment-p ()
+ "Return whether or not point is within a string or comment."
+ (let ((syntax (syntax-ppss)))
+ (or (oni-php--syntax-in-string-p syntax)
+ (oni-php--syntax-in-comment-p syntax))))
+
(defun oni-php-insert-dot-dwim (N)
"Insert either a concatenation or access operator depending on context.
Do the insert N times."
(interactive "p")
- (if (or (let ((syntax (syntax-ppss)))
- (or (nth 3 syntax)
- (nth 4 syntax)))
+ (if (or (char-equal ?\ (char-before (point)))
+ (oni-php--in-string-or-comment-p)
(save-excursion
(skip-syntax-backward " ")
(nth 3 (syntax-ppss (1- (point)))))
@@ -118,7 +131,10 @@ Do the insert N times."
(skip-syntax-forward " ")
(nth 3 (syntax-ppss (1+ (point))))))
(self-insert-command N)
- (dotimes (_ N) (insert "->"))))
+ (let ((op (if (looking-back (rx "$" (minimal-match (one-or-more alnum))))
+ "->"
+ "::")))
+ (dotimes (_ N) (insert op)))))
(defun oni-php-doc-comment ()
"Insert a PHP documentation comment at point."