Skip to content

Latest commit

 

History

History
308 lines (232 loc) · 10.1 KB

dkh-php.org

File metadata and controls

308 lines (232 loc) · 10.1 KB

E-Wax PHP

This is part of the E-Wax Starter Kit Instance.

“The telescreen received and transmitted simultaneously….There was no way of knowing whether you were being watched at any given moment.”

George Orwell

1984

php+-mode

(require 'php+-mode)
(php+-mode-setup)

  

To get an idea of what you can do with php+-mode, you can get a description and list of keybindings/functions for php+-mode by typing: C-h m when inside of a php+-mode file.

If you have existing projects, or would like to add a new one, you can add them to the php-project list by running: M-x php-project-add

If you are starting a new project, you can use create the directories and add the new project to your php-project-list all at once by running: M-x zf-create-directory-structure

Notes:

There is a known issue with company-mode version 0.5. If company mode isn’t loading, or you get errors about pysmell or gtags, you need to remove the gtags and pysmell backends from company-mode. Cutomize the variable `company-backends` and remove the lines for `company-pysmell` and `company-gtags`.

While you’re at it, you can also add a User-Defined company backend to the merged backends section of company-backends called `company-my-php-backend`. This backend will check the php.net documentation for completions of php keywords and such.

=============================================================================== CONFIGURATION

You can use the various “customize …” options in the php+-mode menus to customize php+-mode. Hopefully most of these customize options are self-explanatory. For a full list of cutomize options, just browse through each of the customize groups with `M-x customize-group`:

  • php-completion
    • php-doc
    • php-format
    • php-parse
    • php-project
    • php-tags
    • php-test
    • php+-mode

*********** EXECUTABLES

You may need to tell emacs where various executables are. For instance, if php, phpunit, or phpcs (if you use the latter two) are not on your operating system’s execute path, you may need to customize the following variables to tell them explicitly where the executables are:

php-exectuable phpcs-shell-command phpmd-shell-command phpunit-shell-command

************************ PROJECTS AND DIRECTORIES

To add a project to the projects list the easy way, run: M-x php-project-add Alternatively, you can add projects manually by going to PHP+ -> Project -> Customize Projects in the menu or by typing M-x customize-variable php-project-list

If you use customize, the main variable to setup here is the PHP Project List. This is a list of directories on your computer that correspons with a set of php files or project.

To setup a project, insert a new item in the list and fill in the fields:

Project Nickname - This is just a nickname for the project. Project Directory - This is the base directory for the project. For projects using the Zend Framework, this will typically be the directory where application, library, etc, are. Project TAGS File - This is the TAGS file for the project. Extra TAGS Directories - A list of directories to include when generating the project TAGS file. You may want to put the Zend Framework directories here. Project directory is included by default. PHPUnit Config File - This is the xml configuration file that phpunit will use when phpunit is run from php+-mode. phpcs/phpmd Subdirectories - This is a list of directories which should be included when phpcs is run for the project directory. phpdoc overrides - these are project specific phpdoc information to include in doc blocks. Project agnostic defaults can be set by customizing php-doc. Zend Framework Global Namespace - This is the namespace of files generated outside of modules (in the “main area” so to speak). Traditionally, this was “Default” but has recently more likely to be “Application”. This will result in, for instance, models outside of modules being named Default_Model_<name> or Application_Model_<name>. (Only necessary for projects using Zend Framework). Zend Framework Default Module - This is the default module that will be used as default if the Zend project makes use of a default module in the modules directory instead of keeping default controllers, models, etc, inside the applications directory (not in modules). (Only necessary for projects using Zend Framework).

**** TAGS

Tags files are basically compiled files of symbols that link various files together, allowing you, for instance, to find the definition of a function by “following” its name in a call somewhere else in your code. This is done in emacs using the find-tag function, bound to M-. by default.

In order to use tags, you have to do two things:

1.) Create a tags file 2.) Load the tags file

The php-tags portion of php+-mode eases this process. It requires you to have exhuberant-ctags installed. This is different from ctags. Basically, in my experience, if your ctags does not have a -e flag, you need to get exhuberant-ctags to use. There is a customizable variable php-tag-shell-command where you can set the path to your ctags command if neccessary.

To create a tags file you can either go to PHP+ -> Tags -> Create tags file in the menu, or run M-x php-create-tag-file

A tags file will be created in the location given in the php-project-list settings for the current project. After the tags file is generated, you will be prompted to load the newly created tags file.

Once the tags files is created, php-project will automatically load it whenever you switch to a file or buffer that resides inside that project’s directory.

Settings

PHP

(setq php-manual-path "~/git/.emacs.d/php/php-chunked-xhtml/")

(setq php-completion-file "~/git/ewax/misc/php-completion-file")

  

Drupal

(require 'drupal-mode)

(setq auto-mode-alist
      (append
       '(
;; ("\\.php$" . php-mode)
("\.\(module\|test\|install\|theme\)$" . drupal-mode)
("/drupal.*\.\(php\|inc\)$" . drupal-mode)
("\.info" . conf-mode)
         ) auto-mode-alist))

  
(define-derived-mode drupal-mode php+-mode "Drupal"
  "Major mode for Drupal source code.
\\{drupal-mode-map}"
  (setq case-fold-search t) 
  (setq indent-tabs-mode nil)
  (setq c-basic-offset 2)
  (setq indent-tabs-mode nil)
  (setq tab-width 2)
  (setq fill-column 78)
  (c-set-offset 'arglist-cont 0)
  (c-set-offset 'arglist-intro '+)
  (c-set-offset 'case-label 2)
  (c-set-offset 'arglist-close 0)
  (setq yas/buffer-local-condition 
  '(cond
   ((looking-at "\\w") nil)
   ((and
     (not (bobp))
     (or (equal "font-lock-comment-face"
                (get-char-property (1- (point)) 'face))
         (equal "font-lock-string-face"
                (get-char-property (1- (point)) 'face))))
    '(require-snippet-condition . force-in-comment))
   (t t))))
(define-key drupal-mode-map (kbd "TAB") 'indent-according-to-mode)
(add-hook 'drupal-mode-hook (lambda () (flymake-mode 1)))
(add-hook 'drupal-mode-hook (lambda () (yas/minor-mode 1)))
(add-to-list 'auto-mode-alist '("\\.\\(php\\|test\\|module\\|inc\\|install\\|engine\\|profile\\|.theme\\)$" . drupal-mode))
(add-to-list 'auto-mode-alist '("\\.tpl.php$" . html-helper-mode))
(define-key drupal-mode-map '[M-S-up] 'flymake-goto-prev-error)
(define-key drupal-mode-map '[M-S-down] 'flymake-goto-next-error)
(define-key drupal-mode-map (kbd "C-c C-c") 'comment-dwim)

(defun sacha/drupal-module-name ()
  "Return the Drupal module name for .module and .install files."
  (file-name-sans-extension (file-name-nondirectory
                             (buffer-file-name))))
(add-to-list 'hs-special-modes-alist '(drupal-mode "{" "}" "/[*/]" nil hs-c-like-adjust-block-beginning))

  

Drush

(add-to-list 'load-path "~/.emacs.d/src/drupal-mode/")
(require 'drupal-drush-commands)

  

General

(defvar php-search-url "http://www.php.net/")
(defvar php-manual-url "http://www.php.net/manual/en/")

(defun php-search-documentation ()
  "Search PHP documentation for the word at the point."
  (interactive)
  (w3m-browse-url (concat php-search-url (current-word t))))

(add-hook 'php-mode-hook 'my-php-mode-stuff)

(defun my-php-mode-stuff ()
  (local-set-key (kbd "C-x g p") 'my-php-function-lookup)
  (local-set-key (kbd "C-x g P") 'my-php-symbol-lookup))


(defun my-php-symbol-lookup ()
  (interactive)
  (let ((symbol (symbol-at-point)))
    (if (not symbol)
        (message "No symbol at point.")

      (browse-url (concat "http://php.net/manual-lookup.php?pattern="
                          (symbol-name symbol))))))


(defun my-php-function-lookup ()
  (interactive)
  (let* ((function (symbol-name (or (symbol-at-point)
                                    (error "No function at point."))))
         (buf (url-retrieve-synchronously (concat "http://php.net/manual-lookup.php?pattern=" function))))
    (with-current-buffer buf
      (goto-char (point-min))
        (let (desc)
          (when (re-search-forward "<div class=\"methodsynopsis dc-description\">\\(\\(.\\|\n\\)*?\\)</div>" nil t)
            (setq desc
              (replace-regexp-in-string
                " +" " "
                (replace-regexp-in-string
                  "\n" ""
                  (replace-regexp-in-string "<.*?>" "" (match-string-no-properties 1)))))

            (when (re-search-forward "<p class=\"para rdfs-comment\">\\(\\(.\\|\n\\)*?\\)</p>" nil t)
              (setq desc
                    (concat desc "\n\n"
                            (replace-regexp-in-string
                             " +" " "
                             (replace-regexp-in-string
                              "\n" ""
                              (replace-regexp-in-string "<.*?>" "" (match-string-no-properties 1))))))))

          (if desc
              (message desc)
            (message "Could not extract function info. Press C-x g P to go the description."))))
    (kill-buffer buf)))

  

*Conclusion

(message "0 dkh-php... Done")