[bt-devel] C++ indenting
Gabriel M. Beddingfield
gabriel at teuton.org
Thu Aug 18 19:24:01 MST 2005
On Thursday 18 August 2005 11:44 am, Joachim Ansorg wrote:
>
> Hm, emacs for indenting ;)
> What is a command line to indent a file?
I thought about being a wise-guy and actually coming up with a bash-compatable
'command line'...
I've attached an elisp file. When you run this command, make sure you have
the right path to the elisp file.
emacs --batch --script /path/to/batch-cpp-indent.el -f batch-cpp-indent *.cpp
*.h
I borrowed and adopted the script from the fella in the copyright notice.
Viz. http://www.geocities.com/robm351/faq/index-31.html
Peace,
Gabriel
--
(@_
_ ) \_______________________________________________
(_)@8 at 8{}<__g_a_b_r_i_e_l___m___b_e_d_d_i_n_g_f_i_e_l_d__>
)_/
(@
-------------- next part --------------
;;; batch-cpp-indent.el -- non-interactive indentation of C++ code
;;; Copyright (C) 1999 Samuel Tardieu.
;;; mod'd 8/18/05 by Gabriel M. Beddingfield
;;; Typical use: define a script called "cpp-indent" containing:
;;;
;;; #! /bin/sh
;;; emacs --batch --script batch-cpp-indent.el -f batch-cpp-indent "$"
;;;
;;; then call "cpp-indent *.cpp *.h" to indent your files.
;;; Author: Samuel Tardieu <samdebian.org>
;;; Gabriel Beddingfield <gabriel at teuton.org>
(require 'cc-mode)
;;;###autoload
(defun batch-cpp-indent ()
"Run `indent-region' on the files remaining on the command line.
Use this from the command line, with `-batch';
it won't work in an interactive Emacs.
For example, invoke \"emacs -batch -f batch-cpp-indent *.cpp *.h\""
(if (not noninteractive)
(error "`batch-cpp-indent' is to be used only with -batch"))
(while command-line-args-left
(let ((source (car command-line-args-left)))
(find-file source)
(c++-mode)
(c-set-style "linux")
(indent-region (point-min) (point-max))
(write-file source))
(setq command-line-args-left (cdr command-line-args-left)))
(message "Done")
(kill-emacs 0))
More information about the bt-devel
mailing list