[Ilugc] code formatting in emacs?
- From: linux@xxxxxxxxxxxxxxxx (Suresh Ramasubramanian)
- Date: Tue Jul 11 14:01:01 2006
balachandar muruganantham wrote:
Hi,
i am using emacs in fedora core 3.
how do i do code formatting in a existing php script? like setting
indentation automatically?
M-x php-mode
more detailed - stick this in your .emacs
;
; Bug in 'css-mode when "required"
;
;(require 'css-mode)
(autoload 'css-mode "css-mode")
(add-to-list 'auto-mode-alist '("\\.css\\'" . css-mode))
(add-hook 'css-mode-hook 'turn-on-font-lock)
(require 'php-mode)
(autoload 'php-mode "php-mode" "PHP editing mode" t)
;; normally you'd have these uncommented, but we are
;; going to treat them as HTML/PHP files.
;(add-to-list 'auto-mode-alist '("\\.php\\'" . php-mode))
;(add-to-list 'auto-mode-alist '("\\.inc\\'" . php-mode))
(add-hook 'php-mode-user-hook 'turn-on-font-lock)
(require 'javascript-mode)
(autoload 'javascript-mode "javascript-mode" "Javascript Editing Mode" t)
(add-to-list 'auto-mode-alist '("\\.js\\'" . javascript-mode))
(add-hook 'javascript-mode-hook 'turn-on-font-lock)
(require 'mmm-mode)
(setq mmm-global-mode 'maybe)
;; set up an mmm group for fancy html editing
(mmm-add-group
'fancy-html
'(
(html-css-attribute
:submode css-mode
:face mmm-declaration-submode-face
:delimiter-mode nil
:front "style=\""
:back "\"")
)
)
;; What files to invoke the new html-mode for?
(add-to-list 'auto-mode-alist '("\\.html?\\'" . html-mode))
(add-to-list 'auto-mode-alist '("\\.php\\'" . html-mode))
;; What features should be turned on in this html-mode?
(add-to-list 'mmm-mode-ext-classes-alist '(html-mode nil html-js))
(add-to-list 'mmm-mode-ext-classes-alist '(html-mode nil html-php))
(add-to-list 'mmm-mode-ext-classes-alist '(html-mode nil embedded-css))
(add-to-list 'mmm-mode-ext-classes-alist '(html-mode nil fancy-html))
;;
http://www.emacswiki.org/cgi-bin/wiki/HtmlToc
(defun html-show-toc ()
"Shows a TOC based on headings tags <H[1-6]>"
(interactive)
(if sgml-tags-invisible
(error "SGML tags are invisible")
(occur "<h[1-6]>")
(pop-to-buffer "*Occur*")
(vc-toggle-read-only)
(goto-char (point-min))
(replace-string "<h1>" "")
(goto-char (point-min))
(replace-string "<h2>" " ")
(goto-char (point-min))
(replace-string "<h3>" " ")
(goto-char (point-min))
(replace-string "<h4>" " ")
(goto-char (point-min))
(replace-string "<h5>" " ")
(goto-char (point-min))
(replace-string "<h6>" " ")
(goto-char (point-min))
(replace-regexp "</h[1-6]>" "")
(goto-char (point-min))
(toggle-read-only 1)))
Other related posts: