SaltyCrane Blog — Notes on Python and web development on Ubuntu Linux

Emacs notes

Note: I am using Emacs 23.1 on Ubuntu Jaunty Linux

js2-mode (for javascript)

I tried to byte-compile js2-mode in Emacs, using M-x byte-compile-file RET js2.el RET from within Emacs, but I got a Error: Variable binding depth exceeds max-specpdl-size message. Luckily the comments on the Installation Instructions page on the wiki had help for this.

$ cd ~/.emacs.d/site-lisp
$ wget
$ emacs --batch --eval '(byte-compile-file "js2-20080616a.el")'

I added the following to my ~/.emacs:

(autoload 'js2-mode "js2-20080616a" nil t)
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))

Update 2010-03-11: I've switched to espresso-mode.

cd ~/incoming
tar zxvf php-mode-1.5.0.tar.gz
cp -p php-mode-1.5.0/php-mode.el ~/.emacs.d/site-lisp/php-mode-1.5.0.el

Add the following to your .emacs:

(autoload 'php-mode "php-mode-1.5.0")
(add-to-list 'auto-mode-alist
     	     '("\\.php[34]?\\'\\|\\.phtml\\'" . php-mode))

How to manually set the major mode

See 28.1 How Major Modes are Chosen in the Emacs manual. For example to change to js2-mode:

M-x js2-mode

How to use sudo in Tramp

note the two colons

C-c C-f /sudo::/etc/apache2/httpd.conf


C-c C-f /sudo:root@localhost:/etc/apache2/httpd.conf

How to align columns

M-x align may work but M-x align-regexp is more powerful.

How to replace <br> with a newline when using replace-string

Via this article, hit C-q C-j to insert a newline character.

M-x replace-string <br> RET C-q C-j

How to remove ^M characters

Use C-q, quoted-insert to insert a literal ^M character.

M-x replace-string C-q C-m RET RET

How to search and replace in multiple files

  1. M-x find-name-dired: you will be prompted for a root directory and a filename pattern.
  2. Press t to "toggle mark" for all files found.
  3. Press Q for "Query-Replace in Files...": you will be prompted for query/substitution regexps.
  4. Proceed as with query-replace-regexp: SPACE to replace and move to next match, n to skip a match, etc.

How to test out regular expressions

M-x re-builder


#1 Mihamina Rakotomandimby commented on :

php-mode seems to have been forked on github and 1.6.4: