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 | 10 +++++ .emacs.d/lisp/php-face.el | 5 +++ .emacs.d/lisp/php-mode.el | 108 ++++++++++++++++++++++++++++++++------------- .emacs.d/lisp/php.el | 60 +++++++++++++++++++++++++ .emacs.d/lisp/yasnippet.el | 22 ++++++--- 5 files changed, 167 insertions(+), 38 deletions(-) diff --git a/.emacs b/.emacs index 594c445..0b5d15e 100644 --- a/.emacs +++ b/.emacs @@ -55,6 +55,7 @@ (set-keyboard-coding-system 'utf-8) (put 'downcase-region 'disabled nil) +(kill-buffer "*scratch*") ;; Programming section @@ -93,6 +94,15 @@ (require 'yaml-mode) (add-to-list 'auto-mode-alist '("\\.yml$" . yaml-mode)) +;; Python +(require 'whitespace) +(add-hook 'python-mode-hook + (lambda () + (progn + (setq whitespace-line-column 80) + (setq whitespace-style '(face empty tabs lines-tail trailing)) + (whitespace-mode)))) + ;; yasnippet (require 'yasnippet) (yas-global-mode 1) diff --git a/.emacs.d/lisp/php-face.el b/.emacs.d/lisp/php-face.el index 75bdc81..4230bae 100644 --- a/.emacs.d/lisp/php-face.el +++ b/.emacs.d/lisp/php-face.el @@ -101,6 +101,11 @@ :group 'php-faces :tag "PHP Type") +(defface php-class '((t (:inherit font-lock-type-face))) + "PHP Mode face used to highlight class." + :group 'php-faces + :tag "PHP Class") + (defface php-constant '((t (:inherit font-lock-constant-face))) "PHP Mode face used to highlight constants." :group 'php-faces 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)) diff --git a/.emacs.d/lisp/php.el b/.emacs.d/lisp/php.el index 336c267..2bf117b 100644 --- a/.emacs.d/lisp/php.el +++ b/.emacs.d/lisp/php.el @@ -28,8 +28,10 @@ ;; This file provides common variable and functions for PHP packages. ;;; Code: +(require 'cl-lib) (require 'flymake) (require 'php-project) +(require 'rx) ;;;###autoload (defgroup php nil @@ -121,6 +123,14 @@ You can replace \"en\" with your ISO language code." :group 'php :tag "PHP Mode Maybe Hook" :type 'hook) + +(defcustom php-default-builtin-web-server-port 3939 + "Port number of PHP Built-in HTTP server (php -S)." + :group 'php + :tag "PHP Default Built-in Web Server Port" + :type 'integer + :link '(url-link :tag "Built-in web server" + "https://www.php.net/manual/features.commandline.webserver.php")) ;;; PHP Keywords (defconst php-magical-constants @@ -299,5 +309,55 @@ Look at the `php-executable' variable instead of the constant \"php\" command." (when matched (insert (concat matched php-namespace-suffix-when-insert))))) +;;;###autoload +(defun php-run-builtin-web-server (router-or-dir hostname port &optional document-root) + "Run PHP Built-in web server. + +`ROUTER-OR-DIR': Path to router PHP script or Document root. +`HOSTNAME': Hostname or IP address of Built-in web server. +`PORT': Port number of Built-in web server. +`DOCUMENT-ROOT': Path to Document root. + +When `DOCUMENT-ROOT' is NIL, the document root is obtained from `ROUTER-OR-DIR'." + (interactive + (let ((insert-default-directory t) + (d-o-r (read-file-name "Document root or Script: " default-directory))) + (list + (expand-file-name d-o-r) + (read-string "Hostname: " "0.0.0.0") + (read-number "Port: " php-default-builtin-web-server-port) + (if (file-directory-p d-o-r) + nil + (let ((root-input (read-file-name "Document root: " (directory-file-name d-o-r)))) + (file-name-directory + (if (file-directory-p root-input) + root-input + (directory-file-name root-input)))))))) + (let* ((default-directory + (or document-root + (if (file-directory-p router-or-dir) + router-or-dir + (directory-file-name router-or-dir)))) + (pattern (rx-form `(: bos ,(getenv "HOME")))) + (short-dirname (replace-regexp-in-string pattern "~" default-directory)) + (short-filename (replace-regexp-in-string pattern "~" router-or-dir)) + (buf-name (format "php -S %s:%s -t %s %s" + hostname + port + short-dirname + (if document-root short-filename ""))) + (args (cl-remove-if + #'null + (list "-S" + (format "%s:%d" hostname port) + "-t" + default-directory + (when document-root router-or-dir))))) + (message "Run PHP built-in server: %s" buf-name) + (apply #'make-comint buf-name php-executable nil args) + (funcall + (if (called-interactively-p 'interactive) #'display-buffer #'get-buffer) + (format "*%s*" buf-name)))) + (provide 'php) ;;; php.el ends here diff --git a/.emacs.d/lisp/yasnippet.el b/.emacs.d/lisp/yasnippet.el index 9951940..3bbb94d 100644 --- a/.emacs.d/lisp/yasnippet.el +++ b/.emacs.d/lisp/yasnippet.el @@ -1,6 +1,6 @@ -;;; yasnippet.el --- Yet another snippet extension for Emacs. +;;; yasnippet.el --- Yet another snippet extension for Emacs -;; Copyright (C) 2008-2018 Free Software Foundation, Inc. +;; Copyright (C) 2008-2019 Free Software Foundation, Inc. ;; Authors: pluskid , ;; João Távora , ;; Noam Postavsky @@ -381,8 +381,7 @@ the trigger key itself." (defcustom yas-alias-to-yas/prefix-p t "If non-nil make aliases for the old style yas/ prefixed symbols. It must be set to nil before loading yasnippet to take effect." - :type 'boolean - :group 'yasnippet) + :type 'boolean) ;; Only two faces, and one of them shouldn't even be used... ;; @@ -790,12 +789,12 @@ expanded.") ["About" yas-about :help "Display some information about YASnippet"])) +(define-obsolete-variable-alias 'yas-extra-modes 'yas--extra-modes "0.9.1") (defvar yas--extra-modes nil "An internal list of modes for which to also lookup snippets. This variable probably makes more sense as buffer-local, so ensure your use `make-local-variable' when you set it.") -(define-obsolete-variable-alias 'yas-extra-modes 'yas--extra-modes "0.9.1") (defvar yas--tables (make-hash-table) "A hash table of mode symbols to `yas--table' objects.") @@ -3039,8 +3038,13 @@ snippet field. The arguments are the same as `completing-read'. (defun yas--auto-next () "Helper for `yas-auto-next'." - (remove-hook 'post-command-hook #'yas--auto-next t) - (yas-next-field)) + (cl-loop + do (progn (remove-hook 'post-command-hook #'yas--auto-next t) + (yas-next-field)) + ;; The transform in the next field may have requested auto-next as + ;; well. Call it ourselves, since the command loop itself won't + ;; recheck the value of post-command-hook while running it. + while (memq #'yas--auto-next post-command-hook))) (defmacro yas-auto-next (&rest body) "Automatically advance to next field after eval'ing BODY." @@ -4149,6 +4153,7 @@ After revival, push the `yas--take-care-of-redo' in the (when (yas--maybe-move-to-active-field snippet) (setf (yas--snippet-control-overlay snippet) (yas--make-control-overlay snippet beg end)) (overlay-put (yas--snippet-control-overlay snippet) 'yas--snippet snippet) + (push snippet yas--active-snippets) (when (listp buffer-undo-list) (push `(apply yas--take-care-of-redo ,snippet) buffer-undo-list)))) @@ -4683,7 +4688,10 @@ SAVED-QUOTES is the in format returned by `yas--save-backquotes'." (defun yas--scan-sexps (from count) (ignore-errors (save-match-data ; `scan-sexps' may modify match data. + ;; Parse using the syntax table corresponding to the yasnippet syntax. (with-syntax-table (standard-syntax-table) + ;; And ignore syntax-table properties that may have been placed by the + ;; major mode since these aren't related to the yasnippet syntax. (let ((parse-sexp-lookup-properties nil)) (scan-sexps from count)))))) -- cgit v1.3