.emacs.d / starter-kit-php.el

;;; starter-kit-php.el --- Some helpful PHP code
;;; stolen from:
;;; modified by mahmoud abdelkader (

;; load the php directory files
;; and set the variable
(setq php-files-dir (concat dotfiles-dir "languages/php/"))

;; load the php subdirectory
(add-to-list 'load-path php-files-dir)

(require 'php-mode)

;; for Zend Views with the .phtml extension
(add-to-list 'auto-mode-alist '("\\.phtml" . php-mode))

(defun flymake-php-enable ()
  (when (and buffer-file-name
              (file-name-directory buffer-file-name))
             (file-writable-p buffer-file-name)
             (if (fboundp 'tramp-list-remote-buffers)
                 (not (subsetp
                       (list (current-buffer))
    (local-set-key (kbd "C-c d")
    (local-set-key (kbd "C-c n")
    (local-set-key (kbd "C-c p")
    (flymake-mode t)))

(defun javadoc-php-newline-and-indent ()
  "Advanced C-j for Javadoc multiline comments.
Inserts `*' at the beggining of the new line
unless return was pressed outside the comment"
  (setq last (point))
  (setq is-inside
    (if (search-backward "*/" nil t)
        ;; there are some comment endings - search forward
        (if (search-forward "/*" last t)

      ;; it's the only comment - search backward
      (goto-char last)
      (if (search-backward "/*" nil t)

  ;; go to last char position
  (goto-char last)

  ;; the point is inside some comment, insert `*'
  (if is-inside
    (insert "* ")

    ;; else insert only new-line

(eval-after-load 'php-mode
     (require 'flymake)
     (add-hook 'php-mode-hook 'flymake-php-enable)
     (add-hook 'php-mode-hook
               (lambda ()
                 (c-set-style "stroustrup")
                 (local-set-key [(control j)] 'javadoc-php-newline-and-indent)))))

(provide 'starter-kit-php)
;; starter-kit-php.el ends here