From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Xah Lee Newsgroups: gmane.emacs.help Subject: Re: best to have max width of 79 or 80 in source code? Date: Sun, 30 Nov 2008 18:54:39 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <30ea20ec-ffcb-4ea1-a7d8-14e1caed696f@r36g2000prf.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1228107703 10838 80.91.229.12 (1 Dec 2008 05:01:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 1 Dec 2008 05:01:43 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Dec 01 06:02:47 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1L70vm-0006cf-F4 for geh-help-gnu-emacs@m.gmane.org; Mon, 01 Dec 2008 06:02:46 +0100 Original-Received: from localhost ([127.0.0.1]:51614 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L70ub-0006qT-MU for geh-help-gnu-emacs@m.gmane.org; Mon, 01 Dec 2008 00:01:34 -0500 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!a37g2000pre.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help,comp.emacs Original-Lines: 99 Original-NNTP-Posting-Host: 24.6.185.159 Original-X-Trace: posting.google.com 1228100079 31135 127.0.0.1 (1 Dec 2008 02:54:39 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Mon, 1 Dec 2008 02:54:39 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: a37g2000pre.googlegroups.com; posting-host=24.6.185.159; posting-account=bRPKjQoAAACxZsR8_VPXCX27T2YcsyMA User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; en) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:164945 comp.emacs:97410 X-Mailman-Approved-At: Mon, 01 Dec 2008 00:00:33 -0500 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:60274 Archived-At: On Nov 30, 5:45 pm, "seber...@spawar.navy.mil" wrote: > On Nov 30, 12:50 pm,XahLee wrote: > > > in my opinion, hard wrappnig lines or in general any manual code > > formatting is a major damage in computing, to the degree that > > influenced bad tools and language design which forces humans to think > > and do what dumb machines can easily automate. The line wrapping > > convention largely spurred the perpetual time wasted on arguing about > > code formatting and tools about it. > > I read some of the links you posted. I like idea of Emacs > automagically handling wrapping but one of those links seemed to > suggest that C and Python and Perl weren't amenable to this. One cannot auto-format Python source code due to the fact that formatting is part of the syntax, but C and Perl can to a large extent. (the automatting needn't be something like 100% =E2=80=9Cperfect=E2= =80=9D to be useful. (but it should be 100% correct. That is, the reformatted code should not break the code)) actually, having learned a lot elisp in the past couple of years, i think it's rather trivial to do. Basically, the command will just need to inseart line breaks in the right places in the source code, then call indent-region. (i.e. utilizing emacs's existing functions that handle indentation for each lang.) The tricky part would be to not break lines if it is inside string. But there are existing function(s) to determine if cursor is inside string. Also, lines must not be cut when inside comment block. Overall, the bulk of effort for this to work is massive amount of testing. e.g. Apply this to all source code in a large project, and compile and test if the program still runs. (this can be done for example for lisp mode on all elisp source code in emacs) ----------------------- So, in summary, each lang mode should have these functions: format-block format-buffer (current buffer) The format-block will just reformat the block of code the cursor is on. (a block can be defined as between 2 newlines) The fomat-block will have a easy keyboard shortcut of course. Also, for each lang mode, it'll have a local variable =E2=80=9Cformat-style= =E2=80=9D, whose value can be something like: logical, BSD-style, GNU-style, condensed (all white spaces removed). So, a user can just set one of these. (as opposed to setting 10 or so variables related to indentation style and brackets placement style and tabs/spaces style.) ------------------------- with the above, coder simply press a button and have his current block or buffer or files all reformatted to a style he likes. Instead of each coder pressing tab or delete or fill-* etc on a line-by-line basis as is currently practiced. this format-block can be tied to Enter key, so that it becomes automatic. (similar to, for example, how word processors auto wrap lines, started in about early 1990) Today, the Mathematica language autoformat code, even its source code is perhaps the most complex of all computer languages, since the source code also handles math formulas and on-the-fly rendering to traditional math notation (e.g. TeX). Mathematica has this auto format feature since ~1997. ---------------- the above sounds fancy, but it's is rather very trivial to do with respect to today's technology. (for most lang's source code anyway, such as C, Java, C++, Perl, Ruby, lisp etc) If one looks at IDEs, lots more much more harder problems have been solved. As far as i know, there are also standalone tools that reformat source code. I know Java has, and i think C has something called lint. There's also HTML::Lint. As examples of much harder problem being solved... e.g. Steve Yegge recently implement Javascript in elisp. And google implemneted Javascript that compiles to native code, for their Google Chrome browser. Emacs being what it is, this as a programing problem is easily handled in elisp, and this feature is the most fitting for emacs. ------------------- i will code this eventually just for my own use. (using a simple implementation on top of emacs's various indentation functions, as described above) In any case, for those elisp developer reading this, i think it would be quite a killer app for emacs. Xah =E2=88=91 http://xahlee.org/ =E2=98=84