aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--oni-php/oni-php.el33
1 files changed, 25 insertions, 8 deletions
diff --git a/oni-php/oni-php.el b/oni-php/oni-php.el
index 6505802..b9a5c79 100644
--- a/oni-php/oni-php.el
+++ b/oni-php/oni-php.el
@@ -147,18 +147,35 @@ Do the insert N times."
(indent-region start (point))
(goto-char insert-marker))))
+(defun oni-php-doc-use-comment ()
+ "Insert a PHP documentation comment for a use statement."
+ (interactive)
+ (let ((start (point))
+ (class (save-excursion
+ (save-match-data
+ (search-forward-regexp (rx "use " (group (minimal-match (zero-or-more alnum))) ";"))
+ (match-string 1)))))
+ (insert "/**\n * @use " class)
+ (let ((insert-marker (point-marker)))
+ (insert "\n */")
+ (indent-region start (point))
+ (goto-char insert-marker))))
+
(defun oni-php-comment-dwim (func &rest args)
"See if a PHP documentation comment should be added and add it.
Otherwise call FUNC with ARGS. This is meant as advice around
‘comment-dwim’ to make it smarter for PHP code."
- (if (and (derived-mode-p 'php-mode)
- (not (region-active-p))
- (looking-back (rx (minimal-match (zero-or-more blank))) (line-beginning-position))
- (looking-at (rx (minimal-match (zero-or-more (any whitespace "\n")))
- (or (regexp php-beginning-of-defun-regexp)
- (regexp php--re-classlike-pattern)))))
- (oni-php-doc-comment)
- (apply func args)))
+ (cond ((looking-at (rx (minimal-match (zero-or-more (any whitespace "\n")))
+ "use "))
+ (oni-php-doc-use-comment))
+ ((and (derived-mode-p 'php-mode)
+ (not (region-active-p))
+ (looking-back (rx (minimal-match (zero-or-more blank))) (line-beginning-position))
+ (looking-at (rx (minimal-match (zero-or-more (any whitespace "\n")))
+ (or (regexp php-beginning-of-defun-regexp)
+ (regexp php--re-classlike-pattern)))))
+ (oni-php-doc-comment))
+ (t (apply func args))))
(defhydra php-mode-hydra (:color blue)
("a" align-current "Align current selection"))