From 633aa066a900607361b85b110db9ac387b5f258b Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Mon, 24 Apr 2017 12:23:56 +0200 Subject: php-mode yasnippet upgrade --- .emacs.d/lisp/php-mode.el | 158 +++++++++++++++++++++++++++++---------------- .emacs.d/lisp/yasnippet.el | 84 ++++++++++++++++-------- 2 files changed, 159 insertions(+), 83 deletions(-) diff --git a/.emacs.d/lisp/php-mode.el b/.emacs.d/lisp/php-mode.el index 9498d4d..12aa8c0 100644 --- a/.emacs.d/lisp/php-mode.el +++ b/.emacs.d/lisp/php-mode.el @@ -12,7 +12,7 @@ (defconst php-mode-version-number "1.18.3" "PHP Mode version number.") -(defconst php-mode-modified "2017-04-04" +(defconst php-mode-modified "2017-04-19" "PHP Mode build date.") ;;; License @@ -179,11 +179,11 @@ of constants when set." ;; remove old keywords (when (boundp 'php-extra-constants) (font-lock-remove-keywords - 'php-mode `((,(php-mode-extra-constants-create-regexp php-extra-constants) 1 php-constant-face)))) + 'php-mode `((,(php-mode-extra-constants-create-regexp php-extra-constants) 1 'php-constant)))) ;; add new keywords (when value (font-lock-add-keywords - 'php-mode `((,(php-mode-extra-constants-create-regexp value) 1 php-constant-face)))) + 'php-mode `((,(php-mode-extra-constants-create-regexp value) 1 'php-constant)))) (set sym value)) (defcustom php-lineup-cascaded-calls nil @@ -490,7 +490,7 @@ This variable can take one of the following symbol values: (c-lang-defconst c-primitive-type-kwds php '("int" "integer" "bool" "boolean" "float" "double" "real" - "string" "object")) + "string" "object" "void")) (c-lang-defconst c-class-decl-kwds "Keywords introducing declarations where the following block (if any) @@ -552,7 +552,6 @@ PHP does not have an \"enum\"-like keyword." "array" "callable" "iterable" - "void" "as" "break" "catch all" @@ -1006,58 +1005,95 @@ PHP heredoc." :group 'php :group 'faces) -(defvar php-string-face 'php-string-face) -(defvar php-keyword-face 'php-keyword-face) -(defvar php-builtin-face 'php-builtin-face) -(defvar php-function-name-face 'php-function-name-face) -(defvar php-variable-name-face 'php-variable-name-face) -(defvar php-type-face 'php-type-face) -(defvar php-constant-face 'php-constant-face) -(defvar php-php-tag-face 'php-php-tag-face) -(defvar php-doc-annotation-tag-face 'php-doc-annotation-tag-face) -(defvar php-doc-class-name-face 'php-doc-class-name-face) - -(defface php-string-face '((t (:inherit font-lock-string-face))) +(defface php-string '((t (:inherit font-lock-string-face))) "PHP Mode face used to highlight string literals." :group 'php-faces) -(defface php-keyword-face '((t (:inherit font-lock-keyword-face))) +(defface php-keyword '((t (:inherit font-lock-keyword-face))) "PHP Mode face used to highlight keywords." :group 'php-faces) -(defface php-builtin-face '((t (:inherit font-lock-builtin-face))) +(defface php-builtin '((t (:inherit font-lock-builtin-face))) "PHP Mode face used to highlight builtins." :group 'php-faces) -(defface php-function-name-face '((t (:inherit font-lock-function-name-face))) +(defface php-function-name '((t (:inherit font-lock-function-name-face))) "PHP Mode face used to highlight function names." :group 'php-faces) -(defface php-variable-name-face '((t (:inherit font-lock-variable-name-face))) +(defface php-function-call '((t (:inherit default))) + "PHP Mode face used to highlight function names in calles." + :group 'php-faces) + +(defface php-method-call '((t (:inherit php-function-call))) + "PHP Mode face used to highlight method names in calles." + :group 'php-faces) + +(defface php-static-method-call '((t (:inherit php-method-call))) + "PHP Mode face used to highlight static method names in calles." + :group 'php-faces) + +(defface php-variable-name '((t (:inherit font-lock-variable-name-face))) "PHP Mode face used to highlight variable names." :group 'php-faces) -(defface php-type-face '((t (:inherit font-lock-type-face))) +(defface php-property-name '((t (:inherit php-variable-name-face))) + "PHP Mode face used to highlight property names." + :group 'php-faces) + +(defface php-variable-sigil '((t (:inherit default))) + "PHP Mode face used to highlight variable sigils ($)." + :group 'php-faces) + +(defface php-object-op '((t (:inherit default))) + "PHP Mode face used to object operators (->)." + :group 'php-faces) + +(defface php-paamayim-nekudotayim '((t (:inherit default))) + "PHP Mode face used to highlight \"Paamayim Nekudotayim\" scope resolution operators (::)." + :group 'php-faces) + +(defface php-type '((t (:inherit font-lock-type-face))) "PHP Mode face used to highlight types." :group 'php-faces) -(defface php-constant-face '((t (:inherit font-lock-constant-face))) +(defface php-constant '((t (:inherit font-lock-constant-face))) "PHP Mode face used to highlight constants." :group 'php-faces) -(defface php-php-tag-face '((t (:inherit font-lock-constant-face))) +(defface php-$this '((t (:inherit php-constant))) + "PHP Mode face used to highlight $this variables." + :group 'php-faces) + +(defface php-$this-sigil '((t (:inherit php-constant))) + "PHP Mode face used to highlight sigils($) of $this variable." + :group 'php-faces) + +(defface php-php-tag '((t (:inherit font-lock-constant-face))) "PHP Mode face used to highlight PHP tags." :group 'php-faces) -(defface php-doc-annotation-tag-face '((t . (:inherit font-lock-constant-face))) +(defface php-doc-annotation-tag '((t . (:inherit font-lock-constant-face))) "Face used to highlight annotation tags in doc-comment." :group 'php-faces) -(defface php-doc-class-name-face '((t (:inherit php-string-face))) +(defface php-doc-variable-sigil '((t (:inherit font-lock-variable-name-face))) + "PHP Mode face used to highlight variable sigils($)." + :group 'php-faces) + +(defface php-doc-$this '((t (:inherit php-type))) + "PHP Mode face used to highlight $this variable in doc-comment." + :group 'php-faces) + +(defface php-doc-$this-sigil '((t (:inherit php-type))) + "PHP Mode face used to highlight sigil of $this variable in doc-comment." + :group 'php-faces) + +(defface php-doc-class-name '((t (:inherit php-string))) "Face used to class names in doc-comment." :group 'php-faces) -(define-obsolete-face-alias 'php-annotations-annotation-face 'php-doc-annotation-tag-face "1.19.0") +(define-obsolete-face-alias 'php-annotations-annotation-face 'php-doc-annotation-tag "1.19.0") ;;;###autoload @@ -1070,12 +1106,12 @@ PHP heredoc." (c-init-language-vars php-mode) (c-common-init 'php-mode) - (set (make-local-variable font-lock-string-face) php-string-face) - (set (make-local-variable font-lock-keyword-face) php-keyword-face) - (set (make-local-variable font-lock-builtin-face) php-builtin-face) - (set (make-local-variable font-lock-function-name-face) php-function-name-face) - (set (make-local-variable font-lock-variable-name-face) php-variable-name-face) - (set (make-local-variable font-lock-constant-face) php-constant-face) + (set (make-local-variable font-lock-string-face) 'php-string) + (set (make-local-variable font-lock-keyword-face) 'php-keyword) + (set (make-local-variable font-lock-builtin-face) 'php-builtin) + (set (make-local-variable font-lock-function-name-face) 'php-function-name) + (set (make-local-variable font-lock-variable-name-face) 'php-variable-name) + (set (make-local-variable font-lock-constant-face) 'php-constant) (modify-syntax-entry ?_ "_" php-mode-syntax-table) (modify-syntax-entry ?` "\"" php-mode-syntax-table) @@ -1435,7 +1471,7 @@ a completion list." ;; Font Lock (defconst php-phpdoc-type-keywords (list "string" "integer" "int" "boolean" "bool" "float" - "double" "object" "mixed" "array" "resource" "$this" + "double" "object" "mixed" "array" "resource" "void" "null" "false" "true" "self" "static" "callable" "iterable" "number")) @@ -1444,13 +1480,15 @@ a completion list." (defconst php-phpdoc-font-lock-doc-comments `(("{@[-[:alpha:]]+\\s-\\([^}]*\\)}" ; "{@foo ...}" markup. - (0 php-doc-annotation-tag-face prepend nil) - (1 php-string-face prepend nil)) - (,(rx "$" (in "A-Za-z_") (* (in "0-9A-Za-z_"))) - 0 php-variable-name-face prepend nil) + (0 'php-doc-annotation-tag prepend nil) + (1 'php-string prepend nil)) + (,(rx (group "$") (group (in "A-Za-z_") (* (in "0-9A-Za-z_")))) + (1 'php-doc-variable-sigil prepend nil) + (2 'php-variable-name prepend nil)) + ("\\(\\$\\)\\(this\\)\\>" (1 'php-doc-$this-sigil prepend nil) (2 'php-doc-$this prepend nil)) (,(concat "\\s-@" (regexp-opt php-phpdoc-type-tags) "\\s-+" "\\(" (rx (+ (? "?") (? "\\") (+ (in "0-9A-Z_a-z")) (? "[]") (? "|"))) "\\)+") - 1 php-string-face prepend nil) + 1 'php-string prepend nil) (,(concat "\\(?:|\\|\\?\\|\\s-\\)\\(" (regexp-opt php-phpdoc-type-keywords 'words) "\\)") @@ -1458,7 +1496,7 @@ a completion list." ("https?://[^\n\t ]+" 0 'link prepend nil) ("^\\(?:/\\*\\)?\\(?:\\s \\|\\*\\)*\\(@[[:alpha:]][-[:alpha:]\\]*\\)" ; "@foo ..." markup. - 1 php-doc-annotation-tag-face prepend nil))) + 1 'php-doc-annotation-tag prepend nil))) (defvar php-phpdoc-font-lock-keywords `((,(lambda (limit) @@ -1480,27 +1518,32 @@ a completion list." '( ;; Highlight variables, e.g. 'var' in '$var' and '$obj->var', but ;; not in $obj->var() - ("->\\(\\sw+\\)\\s-*(" 1 'default) + ("\\(->\\)\\(\\sw+\\)\\s-*(" (1 'php-object-op) (2 'php-method-call)) ;; Highlight special variables - ("\\$\\(this\\|that\\)\\_>" 1 php-constant-face) - ("\\(\\$\\|->\\)\\([a-zA-Z0-9_]+\\)" 2 php-variable-name-face) + ("\\(\\$\\)\\(this\\|that\\)\\_>" (1 'php-$this-sigil) (2 'php-$this)) + ("\\(\\$\\)\\([a-zA-Z0-9_]+\\)" (1 'php-variable-sigil) (2 'php-variable-name)) + ("\\(->\\)\\([a-zA-Z0-9_]+\\)" (1 'php-object-op) (2 'php-property-name)) ;; Highlight function/method names - ("\\var', but ;; not in $obj->var() - ("->\\(\\sw+\\)\\s-*(" 1 'default) + ("->\\(\\sw+\\)\\s-*(" 1 'php-method-call) - ("\\(\\$\\|->\\)\\([a-zA-Z0-9_]+\\)" 2 php-variable-name-face) + ("\\(\\$\\|->\\)\\([a-zA-Z0-9_]+\\)" 2 'php-property-name) ;; Highlight all upper-cased symbols as constant - ("\\<\\([A-Z_][A-Z0-9_]+\\)\\>" 1 php-constant-face) + ("\\<\\([A-Z_][A-Z0-9_]+\\)\\>" 1 'php-constant) ;; Highlight all statically accessed class names as constant, ;; another valid option would be using type-face, but using ;; constant-face because this is how it works in c++-mode. - ("\\(\\sw+\\)::" 1 php-constant-face) + ("\\(\\sw+\\)\\(::\\)" (1 'php-constant) (2 'php-paamayim-nekudotayim)) ;; Highlight class name after "use .. as" ("\\" "")) 0 php-php-tag-face))) + (,(regexp-opt '("?>" "")) 0 'php-php-tag))) "Detailed highlighting for PHP mode.") (defvar php-font-lock-keywords php-font-lock-keywords-3 @@ -1600,7 +1646,7 @@ The output will appear in the buffer *PHP*." (let ((quoted-stuff (nth 3 (syntax-ppss)))) (when (and quoted-stuff (member quoted-stuff '(?\" ?`))) (put-text-property (match-beginning 0) (match-end 0) - 'face 'php-variable-name-face)))) + 'face 'php-variable-name)))) nil) (eval-after-load 'php-mode @@ -1635,7 +1681,7 @@ The output will appear in the buffer *PHP*." ;; Special care is taken to restore the original syntax, because we ;; want \ not to be word for functions like forward-word. (defadvice font-lock-fontify-keywords-region (around backslash-as-word activate) - "Fontify keywords with backslash as word character" + "Fontify keywords with backslash as word character." (let ((old-syntax (string (char-syntax ?\\)))) (modify-syntax-entry ?\\ "w") ad-do-it diff --git a/.emacs.d/lisp/yasnippet.el b/.emacs.d/lisp/yasnippet.el index 47b8ff5..a3a1eaa 100644 --- a/.emacs.d/lisp/yasnippet.el +++ b/.emacs.d/lisp/yasnippet.el @@ -152,10 +152,13 @@ :prefix "yas-" :group 'editing) +(defconst yas--loaddir + (file-name-directory (or load-file-name buffer-file-name)) + "Directory that yasnippet was loaded from.") + (defvar yas-installed-snippets-dir nil) (setq yas-installed-snippets-dir - (when load-file-name - (expand-file-name "snippets" (file-name-directory load-file-name)))) + (expand-file-name "snippets" yas--loaddir)) (defconst yas--default-user-snippets-dir (expand-file-name "snippets" user-emacs-directory)) @@ -577,7 +580,9 @@ conditions. "Holds the YASnippet menu.") (defun yas--maybe-expand-key-filter (cmd) - (if (yas--templates-for-key-at-point) cmd)) + (when (let ((yas--condition-cache-timestamp (current-time))) + (yas--templates-for-key-at-point)) + cmd)) (defconst yas-maybe-expand '(menu-item "" yas-expand :filter yas--maybe-expand-key-filter) @@ -1977,9 +1982,24 @@ This works by stubbing a few functions, then calling (defun yas-about () (interactive) - (message (concat "yasnippet (version " - yas--version - ") -- pluskid/joaotavora/npostavs"))) + (message "yasnippet (version %s) -- pluskid/joaotavora/npostavs" + (or (ignore-errors (car (let ((default-directory yas--loaddir)) + (process-lines "git" "describe" + "--tags" "--dirty")))) + (when (and (featurep 'package) + (fboundp 'package-desc-version) + (fboundp 'package-version-join)) + (defvar package-alist) + (ignore-errors + (let* ((yas-pkg (cdr (assq 'yasnippet package-alist))) + (version (package-version-join + (package-desc-version (car yas-pkg))))) + ;; Special case for MELPA's bogus version numbers. + (if (string-match "\\`20..[01][0-9][0-3][0-9][.][0-9]\\{3,4\\}\\'" + version) + (concat yas--version "-snapshot" version) + version)))) + yas--version))) ;;; Apropos snippet menu: @@ -2212,7 +2232,8 @@ object satisfying `yas--field-p' to restrict the expansion to." (yas--fallback)))) (defun yas--maybe-expand-from-keymap-filter (cmd) - (let* ((vec (cl-subseq (this-command-keys-vector) + (let* ((yas--condition-cache-timestamp (current-time)) + (vec (cl-subseq (this-command-keys-vector) (if current-prefix-arg (length (this-command-keys)) 0))) @@ -3272,7 +3293,8 @@ This renders the snippet as ordinary text." (overlay-buffer control-overlay)) (setq yas-snippet-beg (overlay-start control-overlay)) (setq yas-snippet-end (overlay-end control-overlay)) - (delete-overlay control-overlay)) + (delete-overlay control-overlay) + (setf (yas--snippet-control-overlay snippet) nil)) (let ((yas--inhibit-overlay-hooks t)) (when yas--active-field-overlay @@ -3427,8 +3449,9 @@ If so cleans up the whole snippet up." ;; ;; This was found useful for performance reasons, so that an excessive ;; number of live markers aren't kept around in the -;; `buffer-undo-list'. We reuse the original marker object, although -;; that's probably not necessary. +;; `buffer-undo-list'. We don't reuse the original marker object +;; because that leaves an unreadable object in the history list and +;; undo-tree persistence has trouble with that. ;; ;; This shouldn't bring horrible problems with undo/redo, but you ;; never know. @@ -3436,16 +3459,13 @@ If so cleans up the whole snippet up." (defun yas--markers-to-points (snippet) "Save all markers of SNIPPET as positions." (yas--snippet-map-markers (lambda (m) - (prog1 (cons (marker-position m) m) + (prog1 (marker-position m) (set-marker m nil))) snippet)) (defun yas--points-to-markers (snippet) "Restore SNIPPET's marker positions, saved by `yas--markers-to-points'." - (yas--snippet-map-markers (lambda (p-m) - (set-marker (cdr p-m) (car p-m)) - (cdr p-m)) - snippet)) + (yas--snippet-map-markers #'copy-marker snippet)) (defun yas--maybe-move-to-active-field (snippet) "Try to move to SNIPPET's active (or first) field and return it if found." @@ -3588,7 +3608,8 @@ field start. This hook does nothing if an undo is in progress." (reoverlays nil)) (dolist (snippet snippets) (dolist (m (yas--collect-snippet-markers snippet)) - (push (yas--snapshot-marker-location m beg end) remarkers)) + (when (and (<= beg m) (<= m end)) + (push (yas--snapshot-marker-location m beg end) remarkers))) (push (yas--snapshot-overlay-location (yas--snippet-control-overlay snippet) beg end) reoverlays)) @@ -3790,6 +3811,7 @@ considered when expanding the snippet." (yas--letenv (yas--snippet-expand-env snippet) (yas--move-to-field snippet first-field)))) (yas--message 4 "snippet expanded.") + (setq deactivate-mark nil) t)))) (defun yas--take-care-of-redo (_beg _end snippet) @@ -4111,15 +4133,21 @@ The returned value is a list of the form (MARKER REGEXP WS-COUNT)." (nconc before (list marker) after) "[[:space:]\n]*")) (progn (goto-char marker) - (skip-syntax-forward " " end) + (skip-chars-forward "[:space:]\n" end) (- (point) marker))))) (defun yas--snapshot-overlay-location (overlay beg end) "Like `yas--snapshot-marker-location' for overlays. -The returned format is (OVERLAY (RE WS) (RE WS))." - (list overlay - (cdr (yas--snapshot-marker-location (overlay-start overlay) beg end)) - (cdr (yas--snapshot-marker-location (overlay-end overlay) beg end)))) +The returned format is (OVERLAY (RE WS) (RE WS)). Either of +the (RE WS) lists may be nil if the start or end, respectively, +of the overlay is outside the range BEG .. END." + (let ((obeg (overlay-start overlay)) + (oend (overlay-end overlay))) + (list overlay + (when (and (<= beg obeg) (< obeg end)) + (cdr (yas--snapshot-marker-location obeg beg end))) + (when (and (<= beg oend) (< oend end)) + (cdr (yas--snapshot-marker-location oend beg end)))))) (defun yas--snapshot-overlay-line-location (overlay) "Return info for restoring OVERLAY's line based location. @@ -4142,8 +4170,8 @@ Buffer must be narrowed to BEG..END used to create the snapshot info." (lwarn '(yasnippet re-marker) :warning "Couldn't find: %S" regexp) (goto-char (match-beginning 1)) - (skip-syntax-forward " ") - (skip-syntax-backward " " (- (point) ws-count)))) + (skip-chars-forward "[:space:]\n") + (skip-chars-backward "[:space:]\n" (- (point) ws-count)))) (defun yas--restore-marker-location (re-marker) "Restores marker based on info from `yas--snapshot-marker-location'. @@ -4156,10 +4184,12 @@ Buffer must be narrowed to BEG..END used to create the snapshot info." Buffer must be narrowed to BEG..END used to create the snapshot info." (cl-destructuring-bind (overlay loc-beg loc-end) ov-locations (move-overlay overlay - (progn (apply #'yas--goto-saved-location loc-beg) - (point)) - (progn (apply #'yas--goto-saved-location loc-end) - (point))))) + (if (not loc-beg) (overlay-start overlay) + (apply #'yas--goto-saved-location loc-beg) + (point)) + (if (not loc-end) (overlay-end overlay) + (apply #'yas--goto-saved-location loc-end) + (point))))) (defun yas--restore-overlay-line-location (ov-locations) -- cgit v1.3