From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: use Elisp to improve your Elisp - some code issues Date: Sun, 02 Aug 2015 18:44:06 +0200 Organization: Informatimago Message-ID: <87oaiptzc9.fsf@kuiper.lan.informatimago.com> References: <871tfmwk8v.fsf@nl106-137-147.student.uu.se> <87pp353doq.fsf@robertthorpeconsulting.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1438533891 23309 80.91.229.3 (2 Aug 2015 16:44:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 2 Aug 2015 16:44:51 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Aug 02 18:44:38 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZLwNJ-0001sX-B6 for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Aug 2015 18:44:37 +0200 Original-Received: from localhost ([::1]:56420 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZLwNI-0007aL-ND for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Aug 2015 12:44:36 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55866) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZLwN4-0007Xe-08 for help-gnu-emacs@gnu.org; Sun, 02 Aug 2015 12:44:23 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZLwN0-0003Vx-PC for help-gnu-emacs@gnu.org; Sun, 02 Aug 2015 12:44:21 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:49159) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZLwN0-0003VV-Gy for help-gnu-emacs@gnu.org; Sun, 02 Aug 2015 12:44:18 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1ZLwMw-0001lE-81 for help-gnu-emacs@gnu.org; Sun, 02 Aug 2015 18:44:14 +0200 Original-Received: from amontsouris-654-1-254-53.w83-202.abo.wanadoo.fr ([83.202.185.53]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 02 Aug 2015 18:44:14 +0200 Original-Received: from pjb by amontsouris-654-1-254-53.w83-202.abo.wanadoo.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 02 Aug 2015 18:44:14 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 52 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: amontsouris-654-1-254-53.w83-202.abo.wanadoo.fr Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:ZTkyNTFlZTBkMDk1NDdiNjYzNGJiMzM2YmViNmFlNDllMDU5ZGRmYg== X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:106214 Archived-At: Robert Thorpe writes: > Emanuel Berg writes: > >> "Pascal J. Bourguignon" >> writes: >> >>> No. >>> >>> I said that if you went beyond those simple case, >>> your regexp solution would break lamentably. >> >> This is an interface to regexps so it sure doesn't go >> anywhere beyond what can be expressed by regexps. > > I agree with Pascal & Marcin. > > Why not use the "read" function to read in the code of the file. Then > you have everything as a tree. You can use car and cdr to walk the tree > and find the relevant function calls. Then you're in the right place in > the Chomsky heirachy. Careful, there's a reason why not to use read and instead to use forward-sexp and other emacs editing function. read will drop comments, newlines, indentation, etc. Since most of the case, you will transform only some form or subform, you may want to keep the rest of the source file intact. Therefore using primarily forward-sexp/down-list/up-list to navigate the source is better. You may then use read-from-string+buffer-substring to transform a sexp identified with forward-sexp, to process it, and insert+pp to format it back into the buffer. On the other hand, you may consider that comments have nothing to do in source databases, and that pp is authoritative, and therefore use read and pp to build an editor that will maintain the source database automatically for yourself. Then you always work at the sexp level. It's probably to be able to work at the sexp level that docstrings were invented, since even in LISP 1.5, comments existed (in the form of comment cards). -- __Pascal Bourguignon__ http://www.informatimago.com/ “The factory of the future will have only two employees, a man and a dog. The man will be there to feed the dog. The dog will be there to keep the man from touching the equipment.” -- Carl Bass CEO Autodesk