I've started using Emacs again. I first got into Emacs at Digital Domain where it was the tool of choice for many of the coders. After I left though I've become complacent (and stuck) and settled with other editors. At work there is of course Visual Studio, which is fine and a complete IDE.

However, yesterday I downloaded Emacs for Windows after I stumbled over a video explaining org-mode and thought it would be good thing to use both for keeping notes at work, and for other projects that I keep on the side.

I had to dig out the old .emacs files I got from Nafees at Digital Domain and customized them a bit. I also found some cool tricks specifically for drupal:

;; Drupal specific files php files
(add-to-list 'auto-mode-alist '("\\.module$" . php-mode))
(add-to-list 'auto-mode-alist '("\\.inc$" . php-mode))
(add-to-list 'auto-mode-alist '("\\.install$" . php-mode))
(add-to-list 'auto-mode-alist '("\\.engine$" . php-mode))
(add-to-list 'auto-mode-alist '("\\.theme$" . php-mode))

One of the most annoying operations in Emacs IMHO is switching between buffers. Using c-x b and typing can be useful if you have several buffers open, but most times I have only a few open at the same time. Therefore these shortcuts help me quickly switch between buffers:

(define-key global-map [f1] 'next-buffer)
(define-key global-map [f2] 'previous-buffer)

also, if you are windows damaged like me, undo and searching functions are ingrained as:

(define-key global-map "\C-z" 'undo)
(define-key global-map [f3] 'isearch-forward)

Emacs can also help with automatic indentation of code. Since there are no set standards for indentation and formatting of code, and source of great debate, there are ways to manipulate that:

;; Indentation
;; IDE tab and indentation settings.
;; http://cc-mode.sourceforge.net/html-manual/Syntactic-Symbols.html
;; The settings are basically stroustrup mode, but a few differences
(setq indent-tabs-mode nil)
(setq tab-width 4)
(setq c-basic-offset tab-width)
(c-set-offset 'statement-block-intro '+)
(c-set-offset 'defun-block-intro '+)
(c-set-offset 'substatement '+)
(c-set-offset 'substatement-open 'c-indent-one-line-block)
(c-set-offset 'brace-list-open 2)  ;; enum \n { ...
(c-set-offset 'innamespace 2)      ;; namespace ... {
(c-set-offset 'access-label -2)    ;; public/private/protected
(c-set-offset 'case-label +2)      ;; switch (...) { label:
(c-set-offset 'statement-case-open 0)
(c-set-offset 'statement-cont 'c-lineup-math)
(c-set-offset 'inline-open +2)
(c-set-offset 'arglist-intro '+)   ;; statement( \n arg1, \n arg2, ... 
(c-set-offset 'arglist-close 0)    ;; )

Since PHP-mode is based on c-mode it will adhere to the same settings. Finally I would just like to share the color scheme that I stole from Nafees. It also serves as an example on how to write a LISP function and execute it:

;; Colors
(defun color-theme-johan ()
  (set-background-color "gray15")
  (set-foreground-color "gray85")
  (set-cursor-color "violet" )
  (autoload 'faces "faces" t )
  (set-face-foreground 'bold "red" )
  (set-face-foreground 'bold-italic "blue" )
  (set-face-foreground 'italic "deeppink2" )
  (set-face-background 'highlight "thistle3")
  (set-face-foreground 'underline "darkorange4" )
  (set-face-foreground 'modeline "black")
  (set-face-background 'modeline "Orange")
  (set-face-foreground 'region "red3")                     ;; marked text
  (set-face-background 'region "antiquewhite1")
  (set-face-foreground 'secondary-selection "yellow4")
   '(org-level-1 ((t (:foreground "DarkOrange" :background "Black"))))
   '(org-level-2 ((t (:background "Black"))))

;; Apply colors
My Emacs settings file4.31 KB