emacs

Coloring emacs active pane

When working using multi-panes within emacs, I often lose track of which pane my cursor is on.

There’s a very easy way to customize emacs to color panes differently based on whether they are active:

http://stackoverflow.com/questions/9446673/asking-emacs-to-highlight-more-clearly-which-window-pane-has-the-focus-cursor

brew · 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

emacs · html · php

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

emacs · mac os

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

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

emacs · mac os

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

emacs

Indent macros as regular C code in emacs

Indenting macros as it were regular code, may cause confusion, since macros are not to be considered part of the code. Although, when programming with openmp and its directives (#pragma omp), it’s annoying to have they indented to the beginning of the line, specially because openmp directives may be nested.

So, to change indentation, add the following line to you .emacs configuration file:

(c-set-offset (quote cpp-macro) 0 nil)

Source: http://stackoverflow.com/questions/4669219/indent-preprocessor-directives-as-c-code-in-emacs