Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use astyle within Emacs?

Tags:

emacs

I am using windows emacs with specifications below.

GNU Emacs 23.0.91.1 (i386-mingw-nt5.1.2600) of 2009-02-26

I want to be able to run astyle so it can reformat the code by using a key command or menu. What is some other equivalent in emacs?

like image 347
dubnde Avatar asked Apr 29 '09 11:04

dubnde


1 Answers

Something like this might do:

(defun astyle-this-buffer (pmin pmax)
  (interactive "r")
  (shell-command-on-region pmin pmax
                           "astyle" ;; add options here...
                           (current-buffer) t 
                           (get-buffer-create "*Astyle Errors*") t))

This will run the "astyle" command on the selected region.

Or, you could simply use emacs' built-in code formatting by typing something like

 C-x h C-M-\

(I.e. select the whole buffer and run indent-region)

like image 98
Edric Avatar answered Oct 05 '22 08:10

Edric