[OS X Emacs] c++ and aquamac

Art Werschulz agw at comcast.net
Fri May 28 08:50:51 EDT 2010


Hi.

On May 27, 2010, at 11:19 PM, Jared Studyvin wrote:

> Hello,
> I'm new to aquamac. How do I compile and execute a c++ program. I can compile but not execute the .out file that is produced. Any help or suggestions would be great.

Not quite on-topic, but close ...

Here are some customizations that make my life easier.  If you like them (or simply want to try them out), put the code into your .emacs file or your Preferences.el file.

(defun indent-buffer-ask()
   (when (y-or-n-p "Indent buffer before saving? ")
     (indent-region (point-min) (point-max))))

(defun indent-buffer-no-ask()
  (indent-region (point-min) (point-max)))

(setq c++-mode-hook
      '(lambda ()
         (c-set-style "cc-mode")
         (define-key c++-mode-map "\C-c\C-c" 'compile)
         (define-key c++-mode-map "\C-c\C-e" 'next-error)
;        (add-hook 'before-save-hook 'indent-buffer-ask nil t)                  
	 (add-hook 'before-save-hook 'indent-buffer-no-ask nil t)
))

Explanation: 

(1) My code is automatically indented when I save a C++ file.  There's an alternative version that asks first; since my answer is invariably "y", I find the no-ask version better.

(2) C-c C-c compiles the program.  The default behavior is to run the command "make -k", which is echoed in the minibuffer.  If you change what's in the minibuffer, your changed version will be remembered for the next time.

(3) If there's a compilation error, C-c C-e will put the point at the location of said error.

Enjoy.

Art Werschulz
207 Stoughton Avenue, Cranford  NJ 07016-2838
(908) 272-1146






More information about the MacOSX-Emacs mailing list