Category Archives: emacs

Fixing emacs install path

I’ve recently switched from macports to brew. Things that were previously installed using macports were not working properly. For example emacs,

$brew list emacs

Returned the following:

/usr/local/Cellar/emacs/24.4/bin/ebrowse
/usr/local/Cellar/emacs/24.4/bin/emacs
/usr/local/Cellar/emacs/24.4/bin/emacs-24.4
/usr/local/Cellar/emacs/24.4/bin/emacsclient
/usr/local/Cellar/emacs/24.4/bin/etags
/usr/local/Cellar/emacs/24.4/bin/grep-changelog
/usr/local/Cellar/emacs/24.4/homebrew.mxcl.emacs.plist
/usr/local/Cellar/emacs/24.4/libexec/emacs/ (5 files)
/usr/local/Cellar/emacs/24.4/share/applications/emacs.desktop
/usr/local/Cellar/emacs/24.4/share/emacs/ (3822 files)
/usr/local/Cellar/emacs/24.4/share/icons/ (7 files)
/usr/local/Cellar/emacs/24.4/share/info/ (62 files)
/usr/local/Cellar/emacs/24.4/share/man/ (5 files)
/usr/local/Cellar/emacs/24.4/var/games/ (2 files)

But emacs, linked to /usr/local/bin/emacs was not linked to /usr/local/Cellar/emacs/24.4/bin/emacs

The fix was running

$brew link emacs

But before that I had to fix permissions to /usr/local/share/emacs which was set by macports: http://stackoverflow.com/questions/16844826/error-when-trying-to-brew-link-autoconf

Working with mixed HTML and PHP code in emacs

I found that the html-helper-mode is a better alternative than either php or html mode.

To set this mode automatically for .php and .html files, just add the following entry in your .emacs configuration:

(setq auto-mode-alist (cons '("\\.php$" . html-helper-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.html$" . html-helper-mode) auto-mode-alist))

To check in which mode you’re currently on,

C-h m
Display documentation of the current major mode (describe-mode).

References:

[1] http://xahlee.org/emacs/emacs_html.html
[2] http://jeremy.zawodny.com/emacs/emacs-4.html

Gtags on emacs

In a previous post about emacs etags, I received a tip from Alex Ott suggesting gtags for C/C++.

Installing

On MacOS, you can get gtags through mac ports, installing the “global” package.

Usage

To build the symbols table, it’s simple as doing:

gtags

at the root of the project.

Usage on emacs

First, you need to add a gtags-mode on emacs and tell it where to find the gtags script if gtags.el file is not installed in the default location (mac ports install it on /opt/local/share/gtags by default). On the preferences files, I added these lines:

(setq load-path (cons "/opt/local/share/gtags/" load-path))                                                                                                             
(autoload 'gtags-mode "gtags" "" t)  

Some useful commands:

  • gtags-find-tag [tag name] — this command finds the definition of tag name.
  • gtags-find-rtag [tag name] — this command finds the usage of the tag name
  • gtags-find-tag-from-here — this command is a smart version of the above. It will look up the name that is pointed by your cursor. If your cursor is on a definition, it will look for usage. On the other hand, if your cursor is on a usage, it will look for the definition.

One may wish to bind this last command to some key.

Reference

http://www.gnu.org/s/global/globaldoc.html

Emacs etags

etags is a simple way to find the definition of a function. This is very useful if you’re reading code from a large application.

You can run the following command at the root of the sources:

find . | grep -P "(c|cpp|h|hpp)$" | etags - 

(Sorry, I don’t know how to do it directly with find)

Then, when using emacs, just place the cursor above the function name and type

M-.

This will take you to the function definition.

References:
http://www.gnu.org/software/libtool/manual/emacs/Tags.html

Cmake syntax highlighting for aquamacs

Aquamacs does not offer syntax highlighting for cmake files for default. To change that, download the parser from cmake website: http://www.cmake.org/CMakeDocs/cmake-mode.el

Then, add the following lines in the configuration file for aquamacs, usually in: ~/Library/Preferences/Aquamacs Emacs/Preferences.el

; Add cmake listfile names to the mode list.
(setq auto-mode-alist
	  (append
	   '(("CMakeLists\\.txt\\'" . cmake-mode))
	   '(("\\.cmake\\'" . cmake-mode))
	   auto-mode-alist))

(autoload 'cmake-mode "~/CMake/Docs/cmake-mode.el" t)

Source:

http://www.itk.org/Wiki/CMake_Editors_Support