aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2025-01-24 12:47:09 -0800
committerGravatar Tom Willemse2025-01-24 12:47:09 -0800
commit4121bdb89c1d83949cc368bf81998887b6678168 (patch)
tree666f5ae241a4788ce5bd62e53c6f69e5758f1cfc
parentd8468edadcfc778a92fafd4849d3f5e6ceb94bd8 (diff)
downloademacs-config-4121bdb89c1d83949cc368bf81998887b6678168.tar.gz
emacs-config-4121bdb89c1d83949cc368bf81998887b6678168.zip
oni-php: Add command to enter expected operator
The command either inserts a ‘.’ if point is next to, or inside, a string or inside a comment. Otherwise it'll insert the access operator ‘->’ instead.
-rw-r--r--oni-php/oni-php.el20
1 files changed, 19 insertions, 1 deletions
diff --git a/oni-php/oni-php.el b/oni-php/oni-php.el
index 986cb35..d90251e 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: 2025.0122.121804
+;; Version: 2025.0124.124542
;; Package-Requires: (php-mode oni-yasnippet oni-flycheck oni-company oni-hydra ggtags fic-mode company-php)
;; This program is free software; you can redistribute it and/or modify
@@ -94,6 +94,23 @@ nil for some reason."
(insert "use " class ";\n")
(pulse-momentary-highlight-region start (point))))))
+(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)))
+ (save-excursion
+ (skip-syntax-backward " ")
+ (nth 3 (syntax-ppss (1- (point)))))
+ (save-excursion
+ (skip-syntax-forward " ")
+ (nth 3 (syntax-ppss (1+ (point))))))
+ (self-insert-command N)
+ (dotimes (_ N) (insert "->"))))
+
(defhydra php-mode-hydra (:color blue)
("a" align-current "Align current selection"))
@@ -114,6 +131,7 @@ nil for some reason."
(add-to-list 'company-backends 'company-ac-php-backend))
(define-key php-mode-map (kbd "C-c m") #'php-mode-hydra/body)
+(define-key php-mode-map (kbd ".") #'oni-php-insert-dot-dwim)
;; In PHP code it's nice to have any ~=>~ aligned.