Saltycrane logo

SaltyCrane Blog

Notes on Python, Django, 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 23.0.60.1, 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 http://js2-mode.googlecode.com/files/js2-20080616a.el
$ 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.

php-mode

http://php-mode.sourceforge.net/
cd ~/incoming
wget http://downloads.sourceforge.net/project/php-mode/php-mode/1.5.0/php-mode-1.5.0.tar.gz
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

alternatively:

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

http://stackoverflow.com/questions/270930/using-emacs-to-recursively-find-and-replace-in-text-files-not-already-open

  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 Comment — feed icon Comments feed for this post


#1 Mihamina Rakotomandimby commented on 2011-12-08:

php-mode seems to have been forked on github and 1.6.4: http://goo.gl/jB03o

Post a comment

Required
Required, but not displayed
Optional

Format using Markdown. (No HTML.)
  • Code blocks: prefix each line by at least 4 spaces or 1 tab (and a blank line before and after)
  • Code span: surround with backticks
  • Blockquotes: prefix lines to be quoted with >
  • Links: <URL>
  • Links w/ description: [description](URL)
Created with Django | Hosted by Linode