all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to set Emacs indentation style in batch mode
@ 2004-10-26  1:28 Bob Whitaker
  2004-10-26  9:26 ` Aidan Kehoe
  0 siblings, 1 reply; 3+ messages in thread
From: Bob Whitaker @ 2004-10-26  1:28 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to set Emacs indentation style in batch mode
  2004-10-26  1:28 How to set Emacs indentation style in batch mode Bob Whitaker
@ 2004-10-26  9:26 ` Aidan Kehoe
  2004-10-26 14:41   ` Bob Whitaker
  0 siblings, 1 reply; 3+ messages in thread
From: Aidan Kehoe @ 2004-10-26  9:26 UTC (permalink / raw)



 Ar an cúigiú lá is fiche de mí Deireadh Fómhair, scríobh Bob Whitaker: 

 > 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?

Yes. Try '(c-set-style "stroustrup")' instead of '(setq-default
c-default-style "stroustrup")'; the former modifies the environment for the
current file, the latter changes a global default, which isn't much use to
you because it doesn't apply to the current file. (The current C indentation
style has already been initialised.) 

-- 
Like the early Christians, Marx expected the millennium very soon; like
their successors, his have been disappointed--once more, the world has shown
itself recalcitrant to a tidy formula embodying the hopes of some section of
mankind. (Russell)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to set Emacs indentation style in batch mode
  2004-10-26  9:26 ` Aidan Kehoe
@ 2004-10-26 14:41   ` Bob Whitaker
  0 siblings, 0 replies; 3+ messages in thread
From: Bob Whitaker @ 2004-10-26 14:41 UTC (permalink / raw)


Thanks to both!!! You were both right!!! The script now works great.
For the archives, here is my current implementation (works OK):

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; FILE
;; ====
;; emacs_pretty_print.el
;;
;; USAGE
;; =====
;; Invoke "xemacs" as follows:
;;
;;   xemacs -batch MyFile.cpp -load emacs_pretty_print.el
;;
(c-set-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)
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-10-26 14:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-26  1:28 How to set Emacs indentation style in batch mode Bob Whitaker
2004-10-26  9:26 ` Aidan Kehoe
2004-10-26 14:41   ` Bob Whitaker

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.