* How do you make code look pretty??
@ 2005-07-27 16:47 T Smith
2005-07-27 20:04 ` J. David Boyd
[not found] ` <mailman.1921.1122495039.20277.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 5+ messages in thread
From: T Smith @ 2005-07-27 16:47 UTC (permalink / raw)
[-- Attachment #1.1: Type: text/plain, Size: 3082 bytes --]
Dear emacs helpers,
Anyway, I have some code that I want to be formatted to all look the
same. I opened a terminal and used:
indent file.cpp
It worked once on one specific file, but afterwards it always returned
any other files that I tried with it. By ruined I mean it was all
garbaled text with garbage and had these weird newline characters
everywhere that ruined it!
------------------------------ ----------------------------------------
********************************
My question is what commands will format the code to look nice? I
know of the "indent" command but it only seems to do uniform indenting
for all the code. What I am asking for is something that does the
indenting and auto edits the code to make it look a little more
pretty.
**************************
I know it sounds crazy that it worked once, but it did! I have the
file and it looks really good! I wanted that same thing on the others
but it ended up corrupting one of the files with all these "new line
characters". I also want to just state for the record that I have
searched the emacs functions a lot. And I searched google a lot. But
I am still only a newbie to emacs so I really am kinda having trouble
with finding any help.
Thanks,
Trevor
When i say "format" or "make it look pretty" I mean it does stuff like:
Ex: Take a really long if statement expression and make it into 4
lines instead of just one HUGE expression.
Ex:
if((expression[x][y]>work[x][y])||(expression[x+1][y]>work[x+1][y])||(expression[x][y+1]>work[x][y+1])||(expression[x][y-1]>work[x][y-1])||
if (( expression[x-1][y] > work[x-1][y] )
|| ( expression[x+1][y] > work[x+1][y] )
|| ( expression[x][y+1] > work[x][y+1] )
|| ( expression[x][y-1] > work[x][y-1] ))
Ex: Take an expression that has no spaces at all and add the proper
spaces to it. Ex: a+b becomes a + b
Ex:
for(inti=0;i<10;i++)
for( int i = 0; i < 10; i++ )
Ex:
inline void class::function()
inline void
class:function()
--------------------------------------------------
--------------------------------------------------
--------------------------------------------------
--------------------------------------------------
-----------------reply by one guy----------
--------------------------------------------------
--------------------------------------------------
--------------------------------------------------
--------------------------------------------------
In this case, I am not even sure that emacs is the right solution for you.
There exists a standalone utility called "indent" which will do more of what
you
want. Some of your issues are style issues for which emacs's c-mode will not
make modifications. My guess is that the reason it only worked once was
that,
on that occasion only, you had the whole buffer marked. It is also possible
that you tried it on buffers for which emacs did not what language to format
for.
Another key word you might check into is "prettyprint".
Regards,
David V.
[-- Attachment #1.2: Type: text/html, Size: 3762 bytes --]
[-- Attachment #2: Type: text/plain, Size: 152 bytes --]
_______________________________________________
Help-gnu-emacs mailing list
Help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How do you make code look pretty??
[not found] <mailman.1905.1122483652.20277.help-gnu-emacs@gnu.org>
@ 2005-07-27 17:40 ` Pascal Bourguignon
2005-07-27 18:49 ` David Hansen
0 siblings, 1 reply; 5+ messages in thread
From: Pascal Bourguignon @ 2005-07-27 17:40 UTC (permalink / raw)
T Smith <trevorboydsmith@gmail.com> writes:
> My question is what commands will format the code to look nice? I
> know of the "indent" command but it only seems to do uniform indenting
> for all the code. What I am asking for is something that does the
> indenting and auto edits the code to make it look a little more
> pretty.
You want something specific, so you'll need to write specific emacs
lisp code to implement it.
> When i say "format" or "make it look pretty" I mean it does stuff
> like:
> Ex: Take a really long if statement expression and make it into 4
> lines instead of just one HUGE expression.
> Ex:
> if((expression[x][y]>work[x][y])||(expression[x+1][y]>work[x+1][y])||(
> expression[x][y+1]>work[x][y+1])||(expression[x][y-1]>work[x][y-1])||
> if (( expression[x-1][y] > work[x-1][y] )
> || ( expression[x+1][y] > work[x+1][y] )
> || ( expression[x][y+1] > work[x][y+1] )
> || ( expression[x][y-1] > work[x][y-1] ))
Beurk. What'd look "pretty" for me would be:
if((work[x][y]<expression[x][y])
||(work[x+1][y]<expression[x+1][y])
||(work[x][y+1]<expression[x][y+1])
||(work[x][y-1]<expression[x][y-1])){
See what I mean by "specific"...
So, you need to write (at least a partial) parser for C in emacs lisp,
matching C statements and expressions, and reformating them.
--
__Pascal Bourguignon__ http://www.informatimago.com/
The world will now reboot. don't bother saving your artefacts.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How do you make code look pretty??
2005-07-27 17:40 ` Pascal Bourguignon
@ 2005-07-27 18:49 ` David Hansen
0 siblings, 0 replies; 5+ messages in thread
From: David Hansen @ 2005-07-27 18:49 UTC (permalink / raw)
On Wed, 27 Jul 2005 19:40:21 +0200 Pascal Bourguignon wrote:
> So, you need to write (at least a partial) parser for C in emacs lisp,
> matching C statements and expressions, and reformating them.
Probably reading the indent man page is enough...
David
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How do you make code look pretty??
2005-07-27 16:47 How do you make code look pretty?? T Smith
@ 2005-07-27 20:04 ` J. David Boyd
[not found] ` <mailman.1921.1122495039.20277.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 5+ messages in thread
From: J. David Boyd @ 2005-07-27 20:04 UTC (permalink / raw)
T Smith <trevorboydsmith@gmail.com> writes:
> Dear emacs helpers,
>
> My question is what commands will format the code to look nice? I know of
> the "indent" command but it only seems to do uniform indenting for all the
> code. What I am asking for is something that does the indenting and auto
> edits the code to make it look a little more pretty.
I would say that, if you are really picky about how your code looks, then you
should prepare yourself for disappointment.
I've never seen any utility that indents code *exactly* the way I would like
it, so I've just learned to live with what emacs does.
I don't want to have to run some third party app to indent my code.
And actually, after a while, you get used to what emacs does. It is quit
configurable, if you play around with the offsets of the different sections of
the code.
Here's three things I've put into my c-mode-hook, that I think really help:
(c-set-style "user")
(c-set-offset 'case-label '+)
(c-set-offset 'substatement-open 0)
Read the docs, there is much you can do inside of emacs itself.
Dave in Largo, FL
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How do you make code look pretty??
[not found] ` <mailman.1921.1122495039.20277.help-gnu-emacs@gnu.org>
@ 2005-07-27 20:24 ` Pascal Bourguignon
0 siblings, 0 replies; 5+ messages in thread
From: Pascal Bourguignon @ 2005-07-27 20:24 UTC (permalink / raw)
david@adboyd.com (J. David Boyd) writes:
> I would say that, if you are really picky about how your code looks, then you
> should prepare yourself for disappointment.
Or for some work.
> I've never seen any utility that indents code *exactly* the way I would like
> it, so I've just learned to live with what emacs does.
That's the reason why emacs includes a general purpose programming
language (emacs lisp), to allow you not to live with what emacs does,
but to implement your own utility.
--
__Pascal Bourguignon__ http://www.informatimago.com/
Our enemies are innovative and resourceful, and so are we. They never
stop thinking about new ways to harm our country and our people, and
neither do we. -- Georges W. Bush
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2005-07-27 20:24 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-27 16:47 How do you make code look pretty?? T Smith
2005-07-27 20:04 ` J. David Boyd
[not found] ` <mailman.1921.1122495039.20277.help-gnu-emacs@gnu.org>
2005-07-27 20:24 ` Pascal Bourguignon
[not found] <mailman.1905.1122483652.20277.help-gnu-emacs@gnu.org>
2005-07-27 17:40 ` Pascal Bourguignon
2005-07-27 18:49 ` David Hansen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).