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¶
- M-x find-name-dired: you will be prompted for a root directory and a filename pattern.
 - Press t to "toggle mark" for all files found.
 - Press Q for "Query-Replace in Files...": you will be prompted for query/substitution regexps.
 - 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
Related posts
- Magit in Spacemacs (evil-magit) notes — posted 2018-11-02
 - Switching from Emacs to Vim (actually Spacemacs) — posted 2015-12-31
 - Colorized, interactive "git blame" in Emacs: vc-annotate — posted 2011-05-28
 - My Emacs Python environment — posted 2010-05-10
 - Emacs espresso-mode for jQuery — posted 2010-03-10
 - Notes on C++ development with Emacs on Ubuntu Linux — posted 2009-07-08
 
Comments
php-mode seems to have been forked on github and 1.6.4: http://goo.gl/jB03o
