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: Strangle problem with batch mode. Date: Thu, 12 Feb 2009 11:05:40 -0800 (PST) Organization: http://groups.google.com Message-ID: References: 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 1234506054 7040 80.91.229.12 (13 Feb 2009 06:20:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 13 Feb 2009 06:20:54 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Feb 13 07:22:08 2009 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 1LXrR9-0005Aw-Vc for geh-help-gnu-emacs@m.gmane.org; Fri, 13 Feb 2009 07:22:08 +0100 Original-Received: from localhost ([127.0.0.1]:34674 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LXrPq-0006r6-2l for geh-help-gnu-emacs@m.gmane.org; Fri, 13 Feb 2009 01:20:46 -0500 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!a39g2000prl.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help,comp.emacs,comp.lang.lisp,comp.lang.scheme Original-Lines: 135 Original-NNTP-Posting-Host: 24.6.175.142 Original-X-Trace: posting.google.com 1234465540 19521 127.0.0.1 (12 Feb 2009 19:05:40 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Thu, 12 Feb 2009 19:05:40 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: a39g2000prl.googlegroups.com; posting-host=24.6.175.142; 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:166783 comp.emacs:97788 comp.lang.lisp:260794 comp.lang.scheme:79285 X-Mailman-Approved-At: Fri, 13 Feb 2009 01:20:16 -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:62099 Archived-At: On Feb 11, 1:11 am, Andy Stewart wrote: > Hi all, > > I write elisp-format.el for format elisp file. > File athttp://www.emacswiki.org/cgi-bin/emacs/elisp-format.el > Detail describe athttp://www.emacswiki.org/cgi-bin/emacs/ElispFormat > > In elisp-format.el, have a command "elisp-format-directory" can format > elisp files under specify directory. > > Example, eval (elisp-format-directory "~/elisp/") can format all elisp > files under "~/elisp/". > > But when i use command > > emacs -batch -l ~/MyEmacs/Site-Lisp/Packages/LazyCatSelf/elisp-format.el = --eval=3D"(progn (require 'elisp-format) (elisp-format-directory \"~/elisp/= \"))" > > it can't work. > > I don't know why `batch' mode can't work. > > Any idea? > > Thanks! > > -- Andy Btw, i promised Andy a thank you money of $15, and promised to pay him $50 if this code is practically usable. If anyone could pitch in some ammount, even $5, will be great! Let me explain why i think this is very important. Today, coders, in about any language, format his code manually, on a line-by-line basis. Although how many indentation is taken care of in most editors, however, it is still manual process on every line. For example, in perl, when i type for (my $var =3D 0; $var < 5; $var++) { then i have to press return, at that point. Then, depending on the editor, i might have to press Tab. Sure, there are template systems that takes care of the whole =E2=80=9Cfor=E2=80=9D loop, but on the whole, = programers are essentially manually formatting each and every line of code. With today's hardware speed and much software advancement, much of these labor can be done by machine. A coder, should be able to press a button, then the current semantic unit of the lang will be automatically formatted to his preference settings. Press another button, the whole file is auto formatted to his liking. Similarly, calling a function can auto-format entire dir of source code. This feature can be builtin in the editor. occasionally you'll see such a tool available in one lang or another, but in general, programers are still manually doing formatting line by line, in just about all editors. The above depicts the vision. (^_^) for now, we can start with lisp source code, with emacs. Lisp source code has a very simple lexical grammar, and emacs is quite powerful in text processing. So, i imagined, it is not too difficult to have a auto-formatter in emacs for elisp code. For example, suppose i am going to write a function (defun previous-user-buffer () "Switch to the next user buffer in cyclic order." (interactive) (previous-buffer) (let ((i 0)) (while (and (string-match "^*" (buffer-name)) (< i 10)) (setq i (1+ i)) (previous-buffer)))) I don't have to press return, tab, in every step. I can simply type them straight, and when the line gets too long or when i want to, i press a button, it gets broken into multiple lines at proper places with proper number of tabs. This is similar to how editing in word processor progressed. (in the 1980s, writer has to press return when cursor reaches the right margin. But since 1990s, auto-wrap is there.) If programer wants, he can set the auto wrap to be automatic, much like emacs automatic option for fill-region. Note that this feature, in whole perfection, is buildin in the Mathematica language's editor (aka Frontend) since 1997. It not only does one-dimentional pure text source code formatting, but deals with source code that renders into 2D typeset mathematics in real time, all on the fly, as you edit. back to elisp with emacs... as a first step, we are aiming for these goals: A: provide a format-buffer functions, so that it will reformat all the code in the current buffer. (Andy alread did this superbly, with version that format current block, region, buffer, file, dir.) B: the result of reformat-buffer must remain 100% valid of the same behavior. For example, i can run reformat-buffer on all existing elisp files bundled with emacs, save them, compile them, and expect emacs to restart fine. Note: This must be achived 100%. C: About how exactly it formats, see a sample here: http://xahlee.org/emacs/lisp_formatter.html The exact detail of formatting is not very important. The important thing is that the code will be able to correctly scan the lexical grammar of the code (as in B above). The exact formatting can be later tweaked to perfection, with customizable variables. It is ok if the code will format badly for say 5% of source code input. This still beats programer manually format every singe line. D: the speed should be practically usable. Say, 1000 lines of code for under no more that 5 sec on a mid range PC today. Once this works, i think it shouldn't be hard to make it work in common lisp, scheme lisp, clojure, newlisp. With today's tech, i think this is very doable with emacs. Andy already did a superb job, but there are still small problems to be fixed. Please try the code. If you can pitch in $5, please email me and Andy. That's be super! Thank you very much, Xah =E2=88=91 http://xahlee.org/ =E2=98=84