From 447890a7ea96da048fa720d313b32860c995e8bb Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Thu, 19 Dec 2019 14:30:16 +0100 Subject: Many changes... --- .emacs.d/lisp/php-mode.el | 108 +++++++++++++++++++++++++++++++++------------- 1 file changed, 77 insertions(+), 31 deletions(-) (limited to '.emacs.d/lisp/php-mode.el') diff --git a/.emacs.d/lisp/php-mode.el b/.emacs.d/lisp/php-mode.el index a339e17..9be3b55 100644 --- a/.emacs.d/lisp/php-mode.el +++ b/.emacs.d/lisp/php-mode.el @@ -444,8 +444,32 @@ In that case set to `NIL'." (prefix "\\" "::"))) (c-lang-defconst c-operators - php (delete '(postfix-if-paren "<" ">") - (c-lang-const c-operators))) + php `((prefix "new" "clone") + ,@(c-lang-const c-identifier-ops) + (postfix "->") + (postfix "++" "--" "[" "]" "(" ")") + (right-assoc "**") + (prefix "++" "--" "+" "-" "~" "(" ")" "@") + (prefix "instanceof") + (prefix "!") + (left-assoc "*" "/" "%") + (left-assoc "+" "-" ".") + (left-assoc "<<" ">>") + (left-assoc "<" ">" "<=" ">=") + (left-assoc "==" "!=" "===" "!==" "<>" "<=>") + (left-assoc "&") + (left-assoc "^") + (left-assoc "|") + (left-assoc "&&") + (left-assoc "||") + (right-assoc "??") + (left-assoc "?:") + (right-assoc-sequence "?" ":") + (right-assoc ,@(c-lang-const c-assignment-operators)) + (left-assoc "and") + (left-assoc "xor") + (left-assoc "or") + (left-assoc ","))) ;; Allow '\' when scanning from open brace back to defining ;; construct like class @@ -950,31 +974,43 @@ this ^ lineup" (goto-char (point-max))) (c-put-char-property (1- (point)) 'syntax-table (string-to-syntax "|"))) +(defvar-local php-mode--propertize-extend-region-current nil + "Prevent undesirable recursion in PHP-SYNTAX-PROPERTIZE-EXTEND-REGION") + (defun php-syntax-propertize-extend-region (start end) "Extend the propertize region if START or END falls inside a PHP heredoc." - (let ((new-start) - (new-end)) - (goto-char start) - (when (re-search-backward php-heredoc-start-re nil t) - (let ((maybe (point))) - (when (and (re-search-forward - (php-heredoc-end-re (match-string 0)) nil t) - (> (point) start)) - (setq new-start maybe)))) - (goto-char end) - (when (re-search-backward php-heredoc-start-re nil t) - (if (re-search-forward - (php-heredoc-end-re (match-string 0)) nil t) - (when (> (point) end) - (setq new-end (point))) - (setq new-end (point-max)))) - (when (or new-start new-end) - (cons (or new-start start) (or new-end end))))) + (let ((pair (cons start end))) + (when (not (member pair php-mode--propertize-extend-region-current)) + ;; re-search functions may trigger + ;; syntax-propertize-extend-region-functions to be called again, which in + ;; turn call this to be called again. + (push pair php-mode--propertize-extend-region-current) + (unwind-protect + (let ((new-start) + (new-end)) + (goto-char start) + (when (re-search-backward php-heredoc-start-re nil t) + (let ((maybe (point))) + (when (and (re-search-forward (php-heredoc-end-re (match-string 0)) nil t) + (> (point) start)) + (setq new-start maybe)))) + (goto-char end) + (when (re-search-backward php-heredoc-start-re nil t) + (if (re-search-forward (php-heredoc-end-re (match-string 0)) nil t) + (when (> (point) end) + (setq new-end (point))) + (setq new-end (point-max)))) + (when (or new-start new-end) + (cons (or new-start start) (or new-end end)))) + ;; Cleanup + (setq php-mode--propertize-extend-region-current + (delete pair php-mode--propertize-extend-region-current)))))) (easy-menu-define php-mode-menu php-mode-map "PHP Mode Commands" (cons "PHP" (c-lang-const c-mode-menu php))) (defvar-local php-mode--delayed-set-style nil) +(defvar-local php-style-delete-trailing-whitespace nil) (defun php-set-style (stylename &optional dont-override) "Set the current `php-mode' buffer to use the style STYLENAME. @@ -1029,7 +1065,8 @@ After setting the stylevars run hooks according to STYLENAME (when php-mode--delayed-set-style (let ((coding-style (or (and (boundp 'php-project-coding-style) php-project-coding-style) php-mode-coding-style))) - (prog1 (php-set-style (symbol-name coding-style)) + (prog1 (when coding-style + (php-set-style (symbol-name coding-style))) (remove-hook 'hack-local-variables-hook #'php-mode-set-style-delay))))) (defvar php-mode-syntax-table @@ -1077,8 +1114,8 @@ After setting the stylevars run hooks according to STYLENAME (setq-local font-lock-constant-face 'php-constant) (setq-local syntax-propertize-function #'php-syntax-propertize-function) - (add-to-list (make-local-variable 'syntax-propertize-extend-region-functions) - #'php-syntax-propertize-extend-region) + (add-hook 'syntax-propertize-extend-region-functions + #'php-syntax-propertize-extend-region t t) (setq imenu-generic-expression php-imenu-generic-expression) @@ -1250,20 +1287,22 @@ current `tags-file-name'." nil))) (defun php-show-arglist () + "Show function arguments at cursor position." (interactive) (let* ((tagname (php-get-pattern)) (buf (find-tag-noselect tagname nil nil)) arglist) (with-current-buffer buf - (goto-char (point-min)) - (when (re-search-forward - (format "function\\s-+%s\\s-*(\\([^{]*\\))" tagname) - nil t) - (setq arglist (buffer-substring-no-properties - (match-beginning 1) (match-end 1))))) + (save-excursion + (goto-char (point-min)) + (when (re-search-forward + (format "function\\s-+%s\\s-*(\\([^{]*\\))" tagname) + nil t) + (setq arglist (buffer-substring-no-properties + (match-beginning 1) (match-end 1)))))) (if arglist (message "Arglist for %s: %s" tagname arglist) - (message "Unknown function: %s" tagname)))) + (message "Unknown function: %s" tagname)))) (defcustom php-search-documentation-browser-function nil "Function to display PHP documentation in a WWW browser. @@ -1464,7 +1503,14 @@ a completion list." ;; namespaces ("\\(\\([a-zA-Z0-9_]+\\\\\\)+[a-zA-Z0-9_]+\\|\\(\\\\[a-zA-Z0-9_]+\\)+\\)[^:a-zA-Z0-9_\\\\]" 1 'font-lock-type-face) ("\\(\\([a-zA-Z0-9_]+\\\\\\)+[a-zA-Z0-9_]+\\|\\(\\\\[a-zA-Z0-9_]+\\)+\\)::" 1 'php-constant) - + (,(eval-when-compile + (rx bol (* (syntax whitespace)) + (or "private" "protected" "public") + (+ (syntax whitespace)) + (group (? "?") (+ (or "\\" (syntax word) (syntax symbol)))) + (+ (syntax whitespace)) + (: "$" (+ (or (syntax word) (syntax symbol)))))) + 1 'php-class) ;; Support the ::class constant in PHP5.6 ("\\sw+\\(::\\)\\(class\\)\\b" (1 'php-paamayim-nekudotayim) (2 'php-magical-constant)) -- cgit v1.3