From de9d904f4a4a7b3df8d536bc3dc964c1b2c61786 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Tue, 6 Mar 2018 13:11:32 +0100 Subject: Upgrade php-mode, yasnippet and add glib_false glib_print glib_printf glib_true --- .emacs.d/lisp/php-mode.el | 104 +++++++++---------------- .emacs.d/lisp/php-project.el | 143 +++++++++++++++++++++++++++++++++++ .emacs.d/lisp/yasnippet.el | 22 +++--- .emacs.d/snippets/c-mode/glib_false | 5 ++ .emacs.d/snippets/c-mode/glib_print | 5 ++ .emacs.d/snippets/c-mode/glib_printf | 5 ++ .emacs.d/snippets/c-mode/glib_true | 5 ++ 7 files changed, 209 insertions(+), 80 deletions(-) create mode 100644 .emacs.d/lisp/php-project.el create mode 100644 .emacs.d/snippets/c-mode/glib_false create mode 100644 .emacs.d/snippets/c-mode/glib_print create mode 100644 .emacs.d/snippets/c-mode/glib_printf create mode 100644 .emacs.d/snippets/c-mode/glib_true diff --git a/.emacs.d/lisp/php-mode.el b/.emacs.d/lisp/php-mode.el index 629c974..2e23642 100644 --- a/.emacs.d/lisp/php-mode.el +++ b/.emacs.d/lisp/php-mode.el @@ -8,14 +8,14 @@ ;; Maintainer: USAMI Kenta ;; URL: https://github.com/ejmr/php-mode ;; Keywords: languages php -;; Version: 1.18.4 +;; Version: 1.19.0 ;; Package-Requires: ((emacs "24") (cl-lib "0.5")) ;; License: GPL-3.0-or-later -(defconst php-mode-version-number "1.18.4" +(defconst php-mode-version-number "1.19.0" "PHP Mode version number.") -(defconst php-mode-modified "2018-01-30" +(defconst php-mode-modified "2018-03-05" "PHP Mode build date.") ;; This file is free software; you can redistribute it and/or @@ -83,9 +83,11 @@ (require 'etags) (require 'speedbar) (require 'imenu) +(require 'php-project nil t) (require 'cl-lib) (require 'mode-local) +(require 'php-project) (eval-when-compile (require 'regexp-opt) @@ -373,14 +375,15 @@ This variable can take one of the following symbol values: (const :tag "WordPress" wordpress) (const :tag "Symfony2" symfony2) (const :tag "PSR-2" psr2)) - :set 'php-mode-custom-coding-style-set :initialize 'custom-initialize-default) -(defun php-mode-custom-coding-style-set (sym value) - (when (eq major-mode 'php-mode) - (set sym value) - (set-default sym value) - (php-set-style (symbol-name value)))) + +(defcustom php-mode-enable-project-coding-style t + "When set to true override php-mode-coding-style by php-project-coding-style. + +If you want to suppress styles from being overwritten by directory / file +local variables, set NIL." + :type 'boolean) (defun php-mode-version () "Display string describing the version of PHP Mode." @@ -388,30 +391,8 @@ This variable can take one of the following symbol values: (message "PHP Mode %s of %s" php-mode-version-number php-mode-modified)) -(defvar php-available-project-root-files - '((projectile ".projectile") - (composer "composer.json" "composer.lock") - (git ".git") - (mercurial ".hg") - (subversion ".svn") - ;; NOTICE: This method does not detect the top level of .editorconfig - ;; However, we can integrate it by adding the editorconfig.el's API. - ;;(editorconfig . ".editorconfig") - )) - ;;;###autoload -(progn - (defvar php-project-root 'auto - "Method of searching for the top level directory. - -`auto' (default) - Try to search file in order of `php-available-project-root-files'. - -SYMBOL - Key of `php-available-project-root-files'.") - (make-variable-buffer-local 'php-project-root) - (put 'php-project-root 'safe-local-variable - #'(lambda (v) (assq v php-available-project-root-files)))) +(define-obsolete-variable-alias 'php-available-project-root-files 'php-project-available-root-files "1.19.0") (defvar php-mode-map (let ((map (make-sparse-keymap))) @@ -441,11 +422,8 @@ SYMBOL ;; ;; https://www.gnu.org/software/emacs/manual/html_node/ccmode/Subword-Movement.html ;; - ;; for more information about Submode Word. - (if (boundp 'subword-mode) - (if subword-mode - (subword-mode nil) - (subword-mode t))) + ;; for more information about Subword mode. + (define-key map (kbd "C-c C-w") 'subword-mode) ;; We inherit c-beginning-of-defun and c-end-of-defun from CC Mode ;; but we have two replacement functions specifically for PHP. We @@ -595,7 +573,6 @@ PHP does not have an \"enum\"-like keyword." "iterable" "as" "break" - "catch all" "catch" "clone" "default" @@ -682,7 +659,6 @@ but only if the setting is enabled" (indent-tabs-mode . nil) (tab-width . ,(default-value 'tab-width)) (fill-column . ,(default-value 'fill-column)) - (require-final-newline . ,(default-value 'require-final-newline)) (show-trailing-whitespace . ,(default-value 'show-trailing-whitespace)) (php-style-delete-trailing-whitespace . nil))) @@ -736,8 +712,7 @@ but only if the setting is enabled" '("php" (c-offsets-alist . ((statement-cont . php-lineup-hanging-semicolon))) (c-indent-comments-syntactically-p . t) - (fill-column . 78) - (require-final-newline . t))) + (fill-column . 78))) (defun php-enable-symfony2-coding-style () "Make php-mode use coding styles that are preferable for working with Symfony2." @@ -750,7 +725,6 @@ but only if the setting is enabled" (c-offsets-alist . ((statement-cont . +))) (c-indent-comments-syntactically-p . t) (fill-column . 78) - (require-final-newline . t) (show-trailing-whitespace . t) (php-style-delete-trailing-whitespace . t))) @@ -1148,15 +1122,24 @@ After setting the stylevars run hooks according to STYLENAME (put 'php-set-style 'interactive-form (interactive-form 'c-set-style)) +(defun php-mode-set-style-delay () + "Set the current `php-mode' buffer to use the style by custom or local variables." + (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)) + (remove-hook 'hack-local-variables-hook #'php-mode-set-style-delay)))) + (defun php-mode-debug () "Display informations useful for debugging PHP Mode." (interactive) (message "--- PHP-MODE DEBUG BEGIN ---") (message "versions: %s; %s" (emacs-version) (php-mode-version)) (message "major-mode: %s" major-mode) - (message "minor-modes: %s" (cl-remove-if - (lambda (s) (string-match-p "global" (symbol-name s))) - minor-mode-list)) + (message "minor-modes: %s" + (cl-loop for s in minor-mode-list + unless (string-match-p "global" (symbol-name s)) + if (and (boundp s) (symbol-value s)) + collect s)) (message "variables: %s" (cl-loop for v in '(indent-tabs-mode tab-width) collect (list v (symbol-value v)))) @@ -1203,13 +1186,12 @@ After setting the stylevars run hooks according to STYLENAME ;; PHP vars are case-sensitive (setq case-fold-search t) - ;; Do not force newline at end of file. Such newlines can cause - ;; trouble if the PHP file is included in another file before calls - ;; to header() or cookie(). - (set (make-local-variable 'require-final-newline) nil) - (set (make-local-variable 'next-line-add-newlines) nil) - - (php-set-style (symbol-name php-mode-coding-style)) + ;; When php-mode-enable-project-coding-style is set, it is delayed by hook. + ;; Since it depends on the timing at which the file local variable is set. + ;; File local variables are set after initialization of major mode except `run-hook' is complete. + (if php-mode-enable-project-coding-style + (add-hook 'hack-local-variables-hook #'php-mode-set-style-delay t t) + (php-set-style (symbol-name php-mode-coding-style))) (when (or php-mode-force-pear (and (stringp buffer-file-name) @@ -1599,12 +1581,6 @@ a completion list." ;; already fontified by another pattern. Note that using OVERRIDE ;; is usually overkill. `( - ;; Highlight variables, e.g. 'var' in '$var' and '$obj->var', but - ;; not in $obj->var() - ("->\\(\\sw+\\)\\s-*(" 1 'php-method-call) - - ("\\(\\$\\|->\\)\\([a-zA-Z0-9_]+\\)" 2 'php-property-name) - ;; Highlight all upper-cased symbols as constant ("\\<\\([A-Z_][A-Z0-9_]+\\)\\>" 1 'php-constant) @@ -1752,18 +1728,6 @@ The output will appear in the buffer *PHP*." (when (re-search-backward re-pattern nil t) (match-string-no-properties 1)))) -;;;###autoload -(defun php-project-get-root-dir () - "Return path to current PHP project." - (let ((detect-method (if (stringp php-project-root) - (list php-project-root) - (if (eq php-project-root 'auto) - (cl-loop for m in php-available-project-root-files - append (cdr m)) - (cdr-safe (assq php-project-root php-available-project-root-files)))))) - (cl-loop for m in detect-method - thereis (locate-dominating-file default-directory m)))) - ;;;###autoload (defun php-current-class () "Insert current class name if cursor in class context." diff --git a/.emacs.d/lisp/php-project.el b/.emacs.d/lisp/php-project.el new file mode 100644 index 0000000..cb04341 --- /dev/null +++ b/.emacs.d/lisp/php-project.el @@ -0,0 +1,143 @@ +;;; php-project.el --- Project support for PHP application -*- lexical-binding: t; -*- + +;; Copyright (C) 2018 Friends of Emacs-PHP development + +;; Author: USAMI Kenta +;; Keywords: tools, files +;; URL: https://github.com/ejmr/php-mode +;; Version: 1.19.0 +;; Package-Requires: ((emacs "24") (cl-lib "0.5")) +;; License: GPL-3.0-or-later + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; Define project specific functions and variables for PHP application. +;; +;; ## API +;; +;; ### `php-project-get-root-dir()' +;; +;; Return root directory of current buffer file. The root directory is +;; determined by several marker file or directory. +;; +;; ### `php-project-get-bootstrap-scripts()' +;; +;; Return list of path to bootstrap script file. +;; +;; ## `.dir-locals.el' support +;; +;; - `php-project-coding-style' +;; - Symbol value of the coding style. (ex. `pear', `psr2') +;; - `php-project-root' +;; - Symbol of marker file of project root. (ex. `git', `composer') +;; - Full path to project root directory. (ex. "/path/to/your-project") +;; - `php-project-bootstrap-scripts' +;; - List of path to bootstrap file of project. +;; (ex. (((root . "vendor/autoload.php") (root . "inc/bootstrap.php"))) +;; + +;;; Code: +(require 'cl-lib) + +;; Constants +(defconst php-project-composer-autoloader "vendor/autoload.php") + +;; Variables +(defvar php-project-available-root-files + '((projectile ".projectile") + (composer "composer.json" "composer.lock") + (git ".git") + (mercurial ".hg") + (subversion ".svn") + ;; NOTICE: This method does not detect the top level of .editorconfig + ;; However, we can integrate it by adding the editorconfig.el's API. + ;;(editorconfig . ".editorconfig") + )) + +;; Buffer local variables + +;;;###autoload +(progn + (defvar php-project-root 'auto + "Method of searching for the top level directory. + +`auto' (default) + Try to search file in order of `php-project-available-root-files'. + +SYMBOL + Key of `php-project-available-root-files'.") + (make-variable-buffer-local 'php-project-root) + (put 'php-project-root 'safe-local-variable + #'(lambda (v) (assq v php-project-available-root-files)))) + +;;;###autoload +(progn + (defvar php-project-bootstrap-scripts nil + "List of path to bootstrap php script file. + +The ideal bootstrap file is silent, it only includes dependent files, +defines constants, and sets the class loaders.") + (make-variable-buffer-local 'php-project-bootstrap-scripts) + (put 'php-project-bootstrap-scripts 'safe-local-variable #'php-project--eval-bootstrap-scripts)) + +;;;###autoload +(progn + (defvar php-project-coding-style nil + "Symbol value of the coding style of the project that PHP major mode refers to. + +Typically it is `pear', `drupal', `wordpress', `symfony2' and `psr2'.") + (make-variable-buffer-local 'php-project-coding-style) + (put 'php-project-coding-style 'safe-local-variable #'symbolp)) + + +;; Functions + +(defun php-project--eval-bootstrap-scripts (val) + "Return T when `VAL' is valid list of safe bootstrap php script." + (cond + ((stringp val) (and (file-exists-p val) val)) + ((eq 'composer val) + (let ((path (expand-file-name php-project-composer-autoloader (php-project-get-root-dir)))) + (and (file-exists-p path) path))) + ((and (consp val) (eq 'root (car val)) (stringp (cdr val))) + (let ((path (expand-file-name (cdr val) (php-project-get-root-dir)))) + (and (file-exists-p path) path))) + ((null val) nil) + ((listp val) + (cl-loop for v in val collect (php-project--eval-bootstrap-scripts v))) + (t nil))) + +;;;###autoload +(defun php-project-get-bootstrap-scripts () + "Return list of bootstrap script." + (let ((scripts (php-project--eval-bootstrap-scripts php-project-bootstrap-scripts))) + (if (stringp scripts) (list scripts) scripts))) + +;;;###autoload +(defun php-project-get-root-dir () + "Return path to current PHP project." + (let ((detect-method + (cond + ((stringp php-project-root) (list php-project-root)) + ((eq php-project-root 'auto) + (cl-loop for m in php-project-available-root-files + append (cdr m))) + (t (cdr-safe (assq php-project-root php-project-available-root-files)))))) + (cl-loop for m in detect-method + thereis (locate-dominating-file default-directory m)))) + +(provide 'php-project) +;;; php-project.el ends here diff --git a/.emacs.d/lisp/yasnippet.el b/.emacs.d/lisp/yasnippet.el index 69b880a..1f92adc 100644 --- a/.emacs.d/lisp/yasnippet.el +++ b/.emacs.d/lisp/yasnippet.el @@ -237,7 +237,7 @@ nil. - To signal that the user quit the prompting process, you can signal `quit' with - (signal \\='quit \"user quit!\")." + (signal \\='quit \"user quit!\")" :type '(repeat function)) (defcustom yas-indent-line 'auto @@ -984,11 +984,8 @@ Honour `yas-dont-activate-functions', which see." Meaning it's visiting a file under one of the mode directories in `yas-snippet-dirs'." (when buffer-file-name - (member - (expand-file-name - ".." - (file-name-directory buffer-file-name)) - (yas-snippet-dirs)))) + (cl-member buffer-file-name (yas-snippet-dirs) + :test #'file-in-directory-p))) ;; We're abusing `magic-fallback-mode-alist' here because ;; `auto-mode-alist' doesn't support function matchers. @@ -2949,7 +2946,8 @@ Otherwise signal `yas-exception'." (defun yas-field-value (number) "Get the string for field with NUMBER. -Use this in primary and mirror transformations to tget." +Use this in primary and mirror transformations to get the text of +other fields." (let* ((snippet (car (yas-active-snippets))) (field (and snippet (yas--snippet-find-field snippet number)))) @@ -4305,9 +4303,13 @@ The SNIPPET's markers are preserved." ;; Now do stuff for `fixed' and `auto'. (save-excursion (cond ((eq yas-indent-line 'fixed) - (while (and (zerop (forward-line)) - (zerop (current-column))) - (indent-to-column yas--indent-original-column))) + (forward-line 1) + (let ((indent-line-function + (lambda () + (indent-to-column yas--indent-original-column)))) + (yas--indent-region (line-beginning-position) + (point-max) + snippet))) ((eq yas-indent-line 'auto) (unless yas-also-auto-indent-first-line (forward-line 1)) diff --git a/.emacs.d/snippets/c-mode/glib_false b/.emacs.d/snippets/c-mode/glib_false new file mode 100644 index 0000000..de9015d --- /dev/null +++ b/.emacs.d/snippets/c-mode/glib_false @@ -0,0 +1,5 @@ +# -*- mode: snippet -*- +# name: glib_false +# key: GF +# -- +FALSE \ No newline at end of file diff --git a/.emacs.d/snippets/c-mode/glib_print b/.emacs.d/snippets/c-mode/glib_print new file mode 100644 index 0000000..23adaab --- /dev/null +++ b/.emacs.d/snippets/c-mode/glib_print @@ -0,0 +1,5 @@ +# -*- mode: snippet -*- +# name: glib_print +# key: gp +# -- +g_printf("$0"); \ No newline at end of file diff --git a/.emacs.d/snippets/c-mode/glib_printf b/.emacs.d/snippets/c-mode/glib_printf new file mode 100644 index 0000000..06107db --- /dev/null +++ b/.emacs.d/snippets/c-mode/glib_printf @@ -0,0 +1,5 @@ +# -*- mode: snippet -*- +# name: glib_printf +# key: gpf +# -- +g_printf("${1:format string}"$2); \ No newline at end of file diff --git a/.emacs.d/snippets/c-mode/glib_true b/.emacs.d/snippets/c-mode/glib_true new file mode 100644 index 0000000..0baf8e8 --- /dev/null +++ b/.emacs.d/snippets/c-mode/glib_true @@ -0,0 +1,5 @@ +# -*- mode: snippet -*- +# name: glib_true +# key: GT +# -- +TRUE \ No newline at end of file -- cgit v1.3