1
0
Fork 0

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.
This commit is contained in:
Tom Willemse 2025-01-24 12:47:09 -08:00
parent d8468edadc
commit 4121bdb89c

View file

@ -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.