Xcode Style Open Quickly Command for Emacs

One of the features of Xcode I really enjoy is the Open Quickly command. I use the Open Quickly command to open standard header files frequently when programming in C. Since I've been doing a lot of development in Emacs instead of Xcode I've bee missing this simple yet useful command.

Here is my attempt at making an equivalent command in Emacs.

The Open Quickly command is a simple command. It takes a name like "string" then searches through some standard paths until it finds a file that matches. Usually (in my use) this is a header file, giving the name "string" would open the header /usr/include/string.h.

Emacs functions

The following Emacs functions when put in your .emacs file will give you a function called open-quickly that is, for my purposes, equivalent to Xcode's Open Quickly command.

;;; Xcode style open quickly command
;; Issues: Should not open messages when opening a new file.
;; Improvements: Should search all standard include paths.

; Makes a file path from a directory, a filename, and an extension.
(defun file-path (directory filename ext)
  (concat directory filename ext))

; Makes a header path with an implied '.h' as the extension.
(defun header-path (directory filename)
  (file-path directory filename ".h"))

; Quickly opens a header file.
(defun open-quickly (header-name)
 "Open a header file HEADER-NAME found in a standard include path."
 (interactive "MHeader name: ")
 (setq standard-include-directories (list "/usr/include/"
                 "/System/Library/Frameworks/Foundation.framework/Headers/"
                 "/System/Library/Frameworks/AppKit.framework/Headers/"))
 (dolist (dir standard-include-directories nil)
   (cond ((file-exists-p (header-path dir header-name))
          (find-file (header-path dir header-name))
          (return)))))

Once the code is in your .emacs file, use M-x load-file. Then type ~/.emacs

How to use open-quickly

To use Open Quickly just type M-x open-quickly, when prompted give it the name of a header file (without the extention).

Known Issues

Needed Improvements

Comments