unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: jari.aalto@tamk.fi (Jari Aalto+mail.tpu)
Subject: Re: tab / indent / spaces / modes [PHP coding]
Date: Sun, 08 Feb 2004 12:27:28 +0200	[thread overview]
Message-ID: <ekt550j3.fsf_-_@blue.sea.net> (raw)
In-Reply-To: mailman.1647.1075510308.928.help-gnu-emacs@gnu.org

* Fri 2004-01-30 Emory Smith <emory.smith <AT> mac.com> gnu.emacs.help
* <http://groups.google.com/groups?oi=djq&as_umsgid=%3Cmailman.1647.1075510308.928.help-gnu-emacs@gnu.org>
| On Jan 27, 2004, at 2:07 PM, kgold wrote:
| 
| > richard <AT> sunsetandlabrea.com (Richard Chamberlain) writes:
| >>
| >> I'm using php-mode and I want to be able to switch off the indentation
| >> mode, because what I want for formatting and what php-mode suggests is
| >> different.
| >
| > Rather than turn off indentation, why not just customize it to format
| > the way you like?  In emacs, nearly everything is customizable.
| >
| 
| im also using php and having trouble with indentation.  i would like
| to keep the indentation on and customize it (as kgold suggested).
| 
| my main problem is with comments (// or /**/).  php-mode seems to not
| recognize them as comments and gives me doubly indented line after i
| use one (even if they are after the semicolon.
| 
| so i was wondering how i might find out (and change) what character
| sequences php-mode recognizes as comment delimiters and what it does
| when it recognizes one.

I use this something likes this for PHP (This is only part of the
setup). Hope it gives some ideas. PHP uses cc-mode, so the indentation
must be defined there.

Jari

(require 'cl)

(setq tab-stop-list
      (let ((i 4) list)
        (while (< i 80)
          (setq list (cons i list))
          (setq i (+ i 4)))
        (reverse list)))

(defun my-tmp-set-tab-key-to-run-4-spaces (map)
  "Define TAB key to run 4 spaces."
  (setq indent-tabs-mode nil)   ;; do NOT use tab characters
  (define-key map "\t" 'tab-to-tab-stop))

(defun my-tmp-c-coding-setup ()
  "Define C and C++ defaul coding style."
  ;; See cc-compat.el
  (setq c-basic-offset 4)                  ;; Default was 2
  (setq c-indent-level 4)                  ;; Default was 2
  (setq c-label-offset 0)                  ;; Default was -2
  (setq c-continued-statement-offset    0) ;; Default was 2
  ;; See cc-vars.el / C-h v c-offsets-alist
  (c-set-offset 'comment-intro         '(c-lineup-comment))
  (c-set-offset 'topmost-intro-cont    '+) ;; Was c-lineup-topmost-intro-cont
  (c-set-offset 'arglist-intro         '+) ;; Default was +
  (c-set-offset 'arglist-close          0) ;; Default was +
  ;; (c-set-offset 'arglist-cont-nonempty '(c-lineup-arglist))
  (c-set-offset 'access-label           0) ;; Default was -
  (c-set-offset 'label                  0) ;; Default was 2
  (c-set-offset 'defun-block-intro     '+)
  (c-set-offset 'statement-cont         0) ;; Default was +
  (c-set-offset 'substatement-open      0)
  (c-set-offset 'statement-block-intro '+))

(defun my-tmp-c-mode-setup ()
  "Prepare C and C++ mode."
  (dolist (hook '(c++-mode-hook
                  c-mode-hook))
    (add-hook hook 'my-tmp-c-coding-setup)))

(my-tmp-c-mode-setup)


;;  Status: 3rd party package   http://sourceforge.net/projects/php-mode/
;;
;;  Emacs does not have built-in PHP coding support
;;  This mode uses C mode

(defun my-tmp-php-compile-command ()
  "Set default compile command."
  (when (and (string-match "php" (symbol-name major-mode))
             (executable-find "php"))
    (setq compile-command "php ")))

(defun my-tmp-php-mode-turn-on-settings ()
  "When ´php-mode' is turned on, run these settings."
  (setq c-auto-newline t) ;; See M-x c-toggle-auto-state
  ;;  Cancel CC mode's electric keys
  (define-key php-mode-map "/" 'self-insert-command)
  (define-key php-mode-map "," 'self-insert-command)
  (define-key php-mode-map ";" 'self-insert-command)
  (define-key php-mode-map "(" 'self-insert-command)
  (define-key php-mode-map ")" 'self-insert-command))

(defun my-tmp-php-mode ()
  "Write PHP code."
  (interactive)
  (cond
   ((fboundp 'php-mode)
    (let ((func 'php-mode))
      (funcall func)))
   ((fboundp 'html-helper-mode)
    (let ((func 'html-helper-mode))
      (funcall func 1))
    (my-tmp-set-tab-key-to-run-4-spaces (current-local-map)))
   ((fboundp 'html-mode)
    (html-mode)
    (my-tmp-set-tab-key-to-run-4-spaces (current-local-map)))
   (t
    (text-mode)))
  (my-tmp-php-compile-command))

(defun my-tmp-php-mode-setup ()
  "Install PHP support."
  (pushnew '("\\.php[s34]?$"  . my-tmp-php-mode) auto-mode-alist :test 'equal)
  (cond
   ((or (fboundp 'php-mode)
        (locate-library "php-mode"))
    (autoload 'php-mode "php-mode" "" t)
    (setq php-manual-url "http://www.php.net/manual/en/")
    (add-hook 'php-mode-user-hook 'my-tmp-php-mode-turn-on-settings))))

(my-tmp-php-mode-setup)



-- 
http://tiny-tools.sourceforge.net/
Swatch @time   http://www.mir.com.my/iTime/itime.htm
               http://www.ryanthiessen.com/swatch/resources.htm
Use Licenses!  http://www.linuxjournal.com/article.php?sid=6225
Which Licence? http://www.linuxjournal.com/article.php?sid=4825
OSI Licences   http://www.opensource.org/licenses/

  parent reply	other threads:[~2004-02-08 10:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-27 11:54 tab / indent / spaces / modes Richard Chamberlain
2004-01-27 14:07 ` kgold
2004-01-31  0:51   ` Emory Smith
     [not found]   ` <mailman.1647.1075510308.928.help-gnu-emacs@gnu.org>
2004-02-08 10:27     ` Jari Aalto+mail.tpu [this message]
2004-01-27 20:31 ` Peter Lee
2004-01-28 11:24 ` Richard Chamberlain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ekt550j3.fsf_-_@blue.sea.net \
    --to=jari.aalto@tamk.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).