From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Cecil Westerhof Newsgroups: gmane.emacs.help Subject: check-lisp-parenthesis Date: Thu, 24 Dec 2009 15:43:22 +0100 Organization: Decebal Computing Message-ID: <87tyvg5t6d.fsf@Traian.DecebalComp> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1261670108 4529 80.91.229.12 (24 Dec 2009 15:55:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 24 Dec 2009 15:55:08 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 24 16:55:01 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 1NNq1k-0003W7-Bf for geh-help-gnu-emacs@m.gmane.org; Thu, 24 Dec 2009 16:55:00 +0100 Original-Received: from localhost ([127.0.0.1]:54984 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NNpo6-0005vj-G0 for geh-help-gnu-emacs@m.gmane.org; Thu, 24 Dec 2009 10:40:54 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Original-Newsgroups: gnu.emacs.help Set: dutch X-Homepage: http://www.decebal.nl/ User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (gnu/linux) Cancel-Lock: sha1:j9Kx5MaxOb7F1FrDKUivmaXOTVY= Original-Lines: 72 Original-NNTP-Posting-Host: 84.53.123.169 Original-X-Trace: 1261665803 news.xs4all.nl 22933 decebal/[::ffff:84.53.123.169]:29393 Original-X-Complaints-To: abuse@xs4all.nl Original-Xref: news.stanford.edu gnu.emacs.help:175768 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:70845 Archived-At: I started with a function to check lisp parenthesis. Before a '(' I accept a space, a tab, a newline, a '(' and a ';'. When there is another character the user is asked if for the '(' a space has to be inserted. After a ')' I accept a space, a tab, a newline and a ')'. When there is another character the user is asked if after the ')' a space has to be appended. So far so good. But I also want to ask to remove white-space gaps. For example: (message message) )))) should be changed -when the user wants it- to: (message message))))) The gap is found, but when I say that I want to delete the gab, this is not done. What am I doing wrong? The code: (defun check-lisp-parenthesis () (interactive) (if (not (interactive-p)) (message "check-lisp-parenthesis can only be called interactive") (save-excursion (let ((found-gap-left 0) (found-gap-right 0) (found-left 0) (found-right 0) (inserted-gap-left 0) (inserted-gap-right 0) (inserted-left 0) (inserted-right 0) (message "")) (goto-char (point-min)) (while (re-search-forward "[^ \t\n(;](" nil t) (setq found-left (1+ found-left)) (goto-char (forward-point -1)) (when (y-or-n-p "Insert a space? ") (insert " ") (setq inserted-left (1+ inserted-left)))) (setq message (format "%sfound-left: %s, inserted-left: %s\n" message found-left inserted-left)) (goto-char (point-min)) (while (re-search-forward ")[^ \t\n)]" nil t) (setq found-right (1+ found-right)) (goto-char (forward-point -1)) (when (y-or-n-p "Append a space? ") (insert " ") (setq inserted-right (1+ inserted-right)))) (setq message (format "%sfound-right: %s, inserted-right: %s\n" message found-left inserted-left)) (goto-char (point-min)) (while (re-search-forward ")[ \t\n]+)" nil t) (setq found-gap-right (1+ found-gap-right)) (when (y-or-n-p (match-string 0)) ;"Delete gap? ") (replace-match "))" nil nil nil 0) (setq inserted-gap-right (1+ inserted-gap-right)))) (setq message (format "%sfound-gap-right: %s, inserted-gap-right: %s\n" message found-gap-right inserted-gap-right)) (message message) )))) -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof