From: Cecil Westerhof <Cecil@decebal.nl>
To: help-gnu-emacs@gnu.org
Subject: check-lisp-parenthesis
Date: Thu, 24 Dec 2009 15:43:22 +0100 [thread overview]
Message-ID: <87tyvg5t6d.fsf@Traian.DecebalComp> (raw)
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
next reply other threads:[~2009-12-24 14:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-24 14:43 Cecil Westerhof [this message]
2009-12-24 16:19 ` check-lisp-parenthesis Pascal J. Bourguignon
2009-12-25 11:26 ` check-lisp-parenthesis Cecil Westerhof
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87tyvg5t6d.fsf@Traian.DecebalComp \
--to=cecil@decebal.nl \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).