diff options
| -rw-r--r-- | .emacs.d/lisp/php-mode.el | 107 |
1 files changed, 53 insertions, 54 deletions
diff --git a/.emacs.d/lisp/php-mode.el b/.emacs.d/lisp/php-mode.el index 1841c4b..c90fa55 100644 --- a/.emacs.d/lisp/php-mode.el +++ b/.emacs.d/lisp/php-mode.el | |||
| @@ -11,7 +11,7 @@ | |||
| 11 | (defconst php-mode-version-number "1.15.3" | 11 | (defconst php-mode-version-number "1.15.3" |
| 12 | "PHP Mode version number.") | 12 | "PHP Mode version number.") |
| 13 | 13 | ||
| 14 | (defconst php-mode-modified "2015-01-31" | 14 | (defconst php-mode-modified "2015-03-09" |
| 15 | "PHP Mode build date.") | 15 | "PHP Mode build date.") |
| 16 | 16 | ||
| 17 | ;;; License | 17 | ;;; License |
| @@ -87,18 +87,15 @@ | |||
| 87 | 87 | ||
| 88 | ;; Work around emacs bug#18845, cc-mode expects cl to be loaded | 88 | ;; Work around emacs bug#18845, cc-mode expects cl to be loaded |
| 89 | ;; while php-mode only uses cl-lib (without compatibility aliases) | 89 | ;; while php-mode only uses cl-lib (without compatibility aliases) |
| 90 | (eval-when-compile | 90 | (eval-and-compile |
| 91 | (if (and (= emacs-major-version 24) (= emacs-minor-version 4)) | 91 | (if (and (= emacs-major-version 24) (>= emacs-minor-version 4)) |
| 92 | (require 'cl))) | 92 | (require 'cl))) |
| 93 | 93 | ||
| 94 | ;; Use the recommended cl functions in php-mode but alias them to the | 94 | ;; Use the recommended cl functions in php-mode but alias them to the |
| 95 | ;; old names when we detect emacs < 24.3 | 95 | ;; old names when we detect emacs < 24.3 |
| 96 | (if (and (= emacs-major-version 24) (< emacs-minor-version 3)) | 96 | (if (and (= emacs-major-version 24) (< emacs-minor-version 3)) |
| 97 | (progn | 97 | (unless (fboundp 'cl-set-difference) |
| 98 | (unless (fboundp 'cl-flet) | 98 | (defalias 'cl-set-difference 'set-difference))) |
| 99 | (defalias 'cl-flet 'flet)) | ||
| 100 | (unless (fboundp 'cl-set-difference) | ||
| 101 | (defalias 'cl-set-difference 'set-difference)))) | ||
| 102 | 99 | ||
| 103 | 100 | ||
| 104 | ;; Local variables | 101 | ;; Local variables |
| @@ -110,7 +107,8 @@ | |||
| 110 | :link '(url-link :tag "Official Site" "https://github.com/ejmr/php-mode") | 107 | :link '(url-link :tag "Official Site" "https://github.com/ejmr/php-mode") |
| 111 | :link '(url-link :tag "PHP Mode Wiki" "https://github.com/ejmr/php-mode/wiki")) | 108 | :link '(url-link :tag "PHP Mode Wiki" "https://github.com/ejmr/php-mode/wiki")) |
| 112 | 109 | ||
| 113 | (defcustom php-executable "/usr/bin/php" | 110 | (defcustom php-executable (or (executable-find "php") |
| 111 | "/usr/bin/php") | ||
| 114 | "The location of the PHP executable." | 112 | "The location of the PHP executable." |
| 115 | :type 'string | 113 | :type 'string |
| 116 | :group 'php) | 114 | :group 'php) |
| @@ -691,7 +689,8 @@ working with Symfony2." | |||
| 691 | 689 | ||
| 692 | (c-add-style | 690 | (c-add-style |
| 693 | "psr2" | 691 | "psr2" |
| 694 | '("php")) | 692 | '("php" |
| 693 | (c-offsets-alist . ((statement-cont . +))))) | ||
| 695 | 694 | ||
| 696 | (defun php-enable-psr2-coding-style () | 695 | (defun php-enable-psr2-coding-style () |
| 697 | "Makes php-mode comply to the PSR-2 coding style" | 696 | "Makes php-mode comply to the PSR-2 coding style" |
| @@ -829,7 +828,8 @@ example `html-mode'. Known such libraries are:\n\t" | |||
| 829 | (move-beginning-of-line nil) | 828 | (move-beginning-of-line nil) |
| 830 | ;; Don't indent heredoc end mark | 829 | ;; Don't indent heredoc end mark |
| 831 | (save-match-data | 830 | (save-match-data |
| 832 | (unless (looking-at "[a-zA-Z0-9_]+;\n") | 831 | (unless (and (looking-at "[a-zA-Z0-9_]+;\n") |
| 832 | (php-in-string-p)) | ||
| 833 | (setq doit t))) | 833 | (setq doit t))) |
| 834 | (goto-char here) | 834 | (goto-char here) |
| 835 | (when doit | 835 | (when doit |
| @@ -870,6 +870,15 @@ This is was done due to the problem reported here: | |||
| 870 | "See `php-c-at-vsemi-p'." | 870 | "See `php-c-at-vsemi-p'." |
| 871 | ) | 871 | ) |
| 872 | 872 | ||
| 873 | (defsubst php-in-string-p () | ||
| 874 | (nth 3 (syntax-ppss))) | ||
| 875 | |||
| 876 | (defsubst php-in-comment-p () | ||
| 877 | (nth 4 (syntax-ppss))) | ||
| 878 | |||
| 879 | (defsubst php-in-string-or-comment-p () | ||
| 880 | (nth 8 (syntax-ppss))) | ||
| 881 | |||
| 873 | (defun php-lineup-string-cont (langelem) | 882 | (defun php-lineup-string-cont (langelem) |
| 874 | "Line up string toward equal sign or dot | 883 | "Line up string toward equal sign or dot |
| 875 | e.g. | 884 | e.g. |
| @@ -878,9 +887,12 @@ $str = 'some' | |||
| 878 | this ^ lineup" | 887 | this ^ lineup" |
| 879 | (save-excursion | 888 | (save-excursion |
| 880 | (goto-char (cdr langelem)) | 889 | (goto-char (cdr langelem)) |
| 881 | (when (or (search-forward "=" (line-end-position) t) | 890 | (let (ret finish) |
| 882 | (search-forward "." (line-end-position) t)) | 891 | (while (and (not finish) (re-search-forward "[=.]" (line-end-position) t)) |
| 883 | (vector (1- (current-column)))))) | 892 | (unless (php-in-string-or-comment-p) |
| 893 | (setq finish t | ||
| 894 | ret (vector (1- (current-column)))))) | ||
| 895 | ret))) | ||
| 884 | 896 | ||
| 885 | (defun php-lineup-arglist-intro (langelem) | 897 | (defun php-lineup-arglist-intro (langelem) |
| 886 | (save-excursion | 898 | (save-excursion |
| @@ -913,12 +925,6 @@ the string HEREDOC-START." | |||
| 913 | (string-match "\\w+" heredoc-start) | 925 | (string-match "\\w+" heredoc-start) |
| 914 | (concat "^\\(" (match-string 0 heredoc-start) "\\)\\W")) | 926 | (concat "^\\(" (match-string 0 heredoc-start) "\\)\\W")) |
| 915 | 927 | ||
| 916 | (defsubst php-in-string-p () | ||
| 917 | (nth 3 (syntax-ppss))) | ||
| 918 | |||
| 919 | (defsubst php-in-comment-p () | ||
| 920 | (nth 4 (syntax-ppss))) | ||
| 921 | |||
| 922 | (defun php-syntax-propertize-function (start end) | 928 | (defun php-syntax-propertize-function (start end) |
| 923 | "Apply propertize rules from START to END." | 929 | "Apply propertize rules from START to END." |
| 924 | ;; (defconst php-syntax-propertize-function | 930 | ;; (defconst php-syntax-propertize-function |
| @@ -1279,27 +1285,24 @@ exists, and nil otherwise. | |||
| 1279 | 1285 | ||
| 1280 | With a prefix argument, prompt (with completion) for a word to search for." | 1286 | With a prefix argument, prompt (with completion) for a word to search for." |
| 1281 | (interactive (php--search-documentation-read-arg)) | 1287 | (interactive (php--search-documentation-read-arg)) |
| 1282 | (cl-flet ((php-file-for (type name) | 1288 | (let ((file (catch 'found |
| 1283 | (expand-file-name | 1289 | (loop for type in php-search-local-documentation-types do |
| 1284 | (format "%s.%s.html" type | 1290 | (let* ((doc-html (format "%s.%s.html" |
| 1285 | (replace-regexp-in-string | 1291 | type |
| 1286 | "_" "-" (downcase name))) | 1292 | (replace-regexp-in-string |
| 1287 | php-manual-path)) | 1293 | "_" "-" (downcase word)))) |
| 1288 | (php-file-url (file) | 1294 | (file (expand-file-name doc-html php-manual-path))) |
| 1289 | ;; Some browsers require the file:// prefix. | 1295 | (when (file-exists-p file) |
| 1290 | ;; Others do not seem to care. But it should | 1296 | (throw 'found file))))))) |
| 1291 | ;; never be incorrect to use the prefix. | 1297 | (when file |
| 1292 | (if (string-prefix-p "file://" file) | 1298 | (let ((file-url (if (string-prefix-p "file://" file) |
| 1293 | file | 1299 | file |
| 1294 | (concat "file://" file)))) | 1300 | (concat "file://" file)))) |
| 1295 | (let ((file (catch 'found | 1301 | (php-browse-documentation-url file-url)) |
| 1296 | (loop for type in php-search-local-documentation-types do | 1302 | t))) |
| 1297 | (let ((file (php-file-for type word))) | 1303 | |
| 1298 | (when (file-exists-p file) | 1304 | (defsubst php-search-web-documentation (word) |
| 1299 | (throw 'found file))))))) | 1305 | (php-browse-documentation-url (concat php-search-url word))) |
| 1300 | (when file | ||
| 1301 | (php-browse-documentation-url (php-file-url file)) | ||
| 1302 | t)))) | ||
| 1303 | 1306 | ||
| 1304 | ;; Define function documentation function | 1307 | ;; Define function documentation function |
| 1305 | (defun php-search-documentation (word) | 1308 | (defun php-search-documentation (word) |
| @@ -1314,14 +1317,11 @@ With a prefix argument, prompt for a documentation word to search | |||
| 1314 | for. If the local documentation is available, it is used to build | 1317 | for. If the local documentation is available, it is used to build |
| 1315 | a completion list." | 1318 | a completion list." |
| 1316 | (interactive (php--search-documentation-read-arg)) | 1319 | (interactive (php--search-documentation-read-arg)) |
| 1317 | (cl-flet ((php-search-web-documentation (name) | 1320 | (if (and (stringp php-manual-path) |
| 1318 | (php-browse-documentation-url | 1321 | (not (string= php-manual-path ""))) |
| 1319 | (concat php-search-url name)))) | 1322 | (or (php-search-local-documentation word) |
| 1320 | (if (and (stringp php-manual-path) | 1323 | (php-search-web-documentation word)) |
| 1321 | (not (string= php-manual-path ""))) | 1324 | (php-search-web-documentation word))) |
| 1322 | (or (php-search-local-documentation word) | ||
| 1323 | (php-search-web-documentation word)) | ||
| 1324 | (php-search-web-documentation word)))) | ||
| 1325 | 1325 | ||
| 1326 | ;; Define function for browsing manual | 1326 | ;; Define function for browsing manual |
| 1327 | (defun php-browse-manual () | 1327 | (defun php-browse-manual () |
| @@ -1446,11 +1446,10 @@ The output will appear in the buffer *PHP*." | |||
| 1446 | ;; Calling 'php -r' will fail if we send it code that starts with | 1446 | ;; Calling 'php -r' will fail if we send it code that starts with |
| 1447 | ;; '<?php', which is likely. So we run the code through this | 1447 | ;; '<?php', which is likely. So we run the code through this |
| 1448 | ;; function to check for that prefix and remove it. | 1448 | ;; function to check for that prefix and remove it. |
| 1449 | (cl-flet ((clean-php-code (code) | 1449 | (let ((cleaned-php-code (if (string-prefix-p "<?php" code t) |
| 1450 | (if (string-prefix-p "<?php" code t) | 1450 | (substring code 5) |
| 1451 | (substring code 5) | 1451 | code))) |
| 1452 | code))) | 1452 | (call-process php-executable nil php-buffer nil "-r" cleaned-php-code)))) |
| 1453 | (call-process "php" nil php-buffer nil "-r" (clean-php-code code))))) | ||
| 1454 | 1453 | ||
| 1455 | 1454 | ||
| 1456 | (defface php-annotations-annotation-face '((t . (:inherit font-lock-constant-face))) | 1455 | (defface php-annotations-annotation-face '((t . (:inherit font-lock-constant-face))) |
