help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to set Emacs indentation style in batch mode


From: Bob Whitaker
Subject: How to set Emacs indentation style in batch mode
Date: 25 Oct 2004 18:28:54 -0700

Hello,

My end goal is to create a "pretty print" utility to indent poorly
indented C++ code automatically.

I have been successful by using XEmacs in batch mode but the only
problem is that it defaults to "gnu" indentation style, whereas I
would like "stroustrup" indentation style. Does anyone know how to do
this?

Here is the simple "emacs_pretty_print.el" file which I use:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; FILE
;; ====
;; emacs_pretty_print.el
;;
;; USAGE
;; =====
;; Invoke "xemacs" as follows:
;;
;;   xemacs -batch MyFile.cpp -load emacs_pretty_print.el
;;
(setq-default c-default-style "stroustrup")
(setq-default c-basic-offset 3)
(setq-default indent-tabs-mode  nil)
(untabify (point-min) (point-max))
(indent-region (point-min) (point-max) nil)
(save-buffer)
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Unfortunately this ".el" file does not work 100%. The formatted code
is in "gnu" style instead of "stroustrup" style. Notice that the other
"setq-default" parameters are set correctly (offset 3, and tabs nil).
I can change "c-basic-offset" to 2 or 4 and I can change
"indent-tabs-mode" to t or nil to verify correct operation. The only
problem is that "c-default-style" seems to be ignored. I have also
tried other modes like "ellemtel" without success.

I have searched Usenet archives and I have tried numerous other
combinations, such as follows:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
(setq-default c-set-style "stroustrup")
(setq         c-set-style "stroustrup")
(setq-default c-default-style "stroustrup")
(setq         c-default-style "stroustrup")
(add-hook 'c-mode-hook '(lambda() (c++-mode)))
(add-hook 'c-mode-common-hook '(lambda() (c-set-style "stroustrup")))
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

None of the above combinations works either. I have tried this using
the following version of Xemacs:

galaxy>xemacs -V
XEmacs 20.4 "Emerald" [Lucid] (sparc-sun-solaris2.6) of Wed May 16
2001 on guild

There must be a simple way to set the indentation style in batch mode,
but I just can't figure it out... Any help would be appreciated.

Thanks,

Bob


reply via email to

[Prev in Thread] Current Thread [Next in Thread]