* catching parenthesis errors in elisp
@ 2009-06-12 7:05 rustom
2009-06-12 9:57 ` Thien-Thi Nguyen
` (4 more replies)
0 siblings, 5 replies; 13+ messages in thread
From: rustom @ 2009-06-12 7:05 UTC (permalink / raw)
To: help-gnu-emacs
Im hacking on a 700 line elisp function.
While doing some (fairly mechanical) cut-paste operations it looks
like either Ive got a parenthesis or a quote (most likely double quote
but could also be single quote) error.
Any suggestions on how to catch such errors?
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: catching parenthesis errors in elisp
2009-06-12 7:05 catching parenthesis errors in elisp rustom
@ 2009-06-12 9:57 ` Thien-Thi Nguyen
2009-06-12 10:18 ` Tim X
` (3 subsequent siblings)
4 siblings, 0 replies; 13+ messages in thread
From: Thien-Thi Nguyen @ 2009-06-12 9:57 UTC (permalink / raw)
To: help-gnu-emacs
() rustom <rustompmody@gmail.com>
() Fri, 12 Jun 2009 00:05:58 -0700 (PDT)
Any suggestions on how to catch such errors?
Here are some suggestions, to catch the error:
- before it happens, do cut/paste by sexps;
- as it happens, see mic-paren.el;
- after it happens, try M-x check-parens RET.
thi
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: catching parenthesis errors in elisp
2009-06-12 7:05 catching parenthesis errors in elisp rustom
2009-06-12 9:57 ` Thien-Thi Nguyen
@ 2009-06-12 10:18 ` Tim X
2009-06-12 11:02 ` rustom
2009-06-12 10:26 ` Thierry Volpiatto
` (2 subsequent siblings)
4 siblings, 1 reply; 13+ messages in thread
From: Tim X @ 2009-06-12 10:18 UTC (permalink / raw)
To: help-gnu-emacs
rustom <rustompmody@gmail.com> writes:
> Im hacking on a 700 line elisp function.
> While doing some (fairly mechanical) cut-paste operations it looks
> like either Ive got a parenthesis or a quote (most likely double quote
> but could also be single quote) error.
>
> Any suggestions on how to catch such errors?
Have a look at occur and make sure you are using paren matching mode.
For lisp, I'd also suggest looking at paredit mode. It is a mode that is
very handy for editing lisp like languages. It has commands for
manipulating the text as sexps, puts in matching () etc. Takes a little
to get use to it, but once you are, it makes editing lisp like languages
really fast an efficient.
Personally, I'd also be breaking up the function - 700 lines in one
function is a little excessive IMO. Apart from making it harder to find
simple syntax errors, it makes it harder to hold the whole thing in your
head conceptually and probably has lots of repetition (your reference to
cut and paste makes me suspect there is too much repetition. Try to
follow the D.R.Y. mantra (Don't repeat yourself).
My basic approach with lisp like languages is to write small functions,
get them working in the repl and once I'm happy with them, put them into
the source file. If I can't see the whole function in one screen, it
usually means its time to break it down into smaller functions. If I can
see lots of similar constructs in a function, then its almost certainly
a sign its time to break the similar bits outinto its own function.
HTH
Tim
--
tcross (at) rapttech dot com dot au
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: catching parenthesis errors in elisp
2009-06-12 7:05 catching parenthesis errors in elisp rustom
2009-06-12 9:57 ` Thien-Thi Nguyen
2009-06-12 10:18 ` Tim X
@ 2009-06-12 10:26 ` Thierry Volpiatto
2009-06-12 11:55 ` Xah Lee
2009-06-13 1:04 ` Joe Fineman
4 siblings, 0 replies; 13+ messages in thread
From: Thierry Volpiatto @ 2009-06-12 10:26 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
you can try to use:
C-M f ==> forward-sexp
or
C-M d ==> down-list
or
C-M n ==> forward-list
starting to the beginning of your defun with a big prefix arg
(e.g C-u4567 C-M f)
You will have an error giving you the exact position of your error.
If you have many functions and you don't know which one have error,
use C-M e in the same way, it will stop on the wrong defun.
Then use the above commands as described.
Hope that help.
rustom <rustompmody@gmail.com> writes:
> Im hacking on a 700 line elisp function.
> While doing some (fairly mechanical) cut-paste operations it looks
> like either Ive got a parenthesis or a quote (most likely double quote
> but could also be single quote) error.
>
> Any suggestions on how to catch such errors?
>
--
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: catching parenthesis errors in elisp
2009-06-12 10:18 ` Tim X
@ 2009-06-12 11:02 ` rustom
0 siblings, 0 replies; 13+ messages in thread
From: rustom @ 2009-06-12 11:02 UTC (permalink / raw)
To: help-gnu-emacs
On Jun 12, 3:18 pm, Tim X <t...@nospam.dev.null> wrote:
> rustom <rustompm...@gmail.com> writes:
> > Im hacking on a 700 line elisp function.
> > While doing some (fairly mechanical) cut-paste operations it looks
> > like either Ive got a parenthesis or a quote (most likely double quote
> > but could also be single quote) error.
>
> > Any suggestions on how to catch such errors?
>
> Have a look at occur and make sure you are using paren matching mode.
>
> For lisp, I'd also suggest looking at paredit mode. It is a mode that is
> very handy for editing lisp like languages. It has commands for
> manipulating the text as sexps, puts in matching () etc. Takes a little
> to get use to it, but once you are, it makes editing lisp like languages
> really fast an efficient.
>
> Personally, I'd also be breaking up the function - 700 lines in one
> function is a little excessive IMO. Apart from making it harder to find
> simple syntax errors, it makes it harder to hold the whole thing in your
> head conceptually and probably has lots of repetition (your reference to
> cut and paste makes me suspect there is too much repetition. Try to
> follow the D.R.Y. mantra (Don't repeat yourself).
Im only trying to make small changes to a 700 line func in org-mode.
[I dont think I could write a 70 line lisp function if I tried :-) ]
In making those changes Ive probably missed escaping (backslashing) a
double-quote is what I guess.
If I put the cursor on the start of the start
(defun org-export-as-docbook
and hit C-M-f I get unbalanced parenthesis 1, 27478
Putting it at the end of the defun and adding a close paren gives me
mismatched parenthesis.
Hence my diagnosis that its not a paren problem but a double-quote
problem
>
> My basic approach with lisp like languages is to write small functions,
> get them working in the repl and once I'm happy with them, put them into
> the source file. If I can't see the whole function in one screen, it
> usually means its time to break it down into smaller functions. If I can
> see lots of similar constructs in a function, then its almost certainly
> a sign its time to break the similar bits outinto its own function.
>
> HTH
>
> Tim
>
> --
> tcross (at) rapttech dot com dot au
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: catching parenthesis errors in elisp
2009-06-12 7:05 catching parenthesis errors in elisp rustom
` (2 preceding siblings ...)
2009-06-12 10:26 ` Thierry Volpiatto
@ 2009-06-12 11:55 ` Xah Lee
2009-06-12 12:06 ` rustom
2009-06-13 1:04 ` Joe Fineman
4 siblings, 1 reply; 13+ messages in thread
From: Xah Lee @ 2009-06-12 11:55 UTC (permalink / raw)
To: help-gnu-emacs
On Jun 12, 12:05 am, rustom <rustompm...@gmail.com> wrote:
> Im hacking on a 700 line elisp function.
> While doing some (fairly mechanical) cut-paste operations it looks
> like either Ive got a parenthesis or a quote (most likely double quote
> but could also be single quote) error.
>
> Any suggestions on how to catch such errors?
here's some recommendation based on how i code elisp.
• never type single paren. I always type them in pairs. And never
delete one of them.
• use tree navigation to move between code.
• to delete or move parts of expression, select the whole expression,
cut & copy to move.
so, when i code in lisp, there is never ever unmatched parenthesis.
this method beats paren-edit mode.
the detail of my editing and setup is here:
• Tips For Editing Lisp Code With Emacs
http://xahlee.org/emacs/emacs_editing_lisp.html
to select current unit of sexp, i press one key, which is bound to
extend-selection, which is defined in my ergoemacs mode. The code is
shown here:
• A Text Editor Feature: Extend Selection By Semantic Unit
http://xahlee.org/emacs/syntax_tree_walk.html
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: catching parenthesis errors in elisp
2009-06-12 11:55 ` Xah Lee
@ 2009-06-12 12:06 ` rustom
2009-06-12 12:24 ` Pascal J. Bourguignon
2009-06-12 12:25 ` rustom
0 siblings, 2 replies; 13+ messages in thread
From: rustom @ 2009-06-12 12:06 UTC (permalink / raw)
To: help-gnu-emacs
On Jun 12, 4:55 pm, Xah Lee <xah...@gmail.com> wrote:
> On Jun 12, 12:05 am, rustom <rustompm...@gmail.com> wrote:
>
> > Im hacking on a 700 line elisp function.
> > While doing some (fairly mechanical) cut-paste operations it looks
> > like either Ive got a parenthesis or a quote (most likely double quote
> > but could also be single quote) error.
>
> > Any suggestions on how to catch such errors?
>
> here's some recommendation based on how i code elisp.
>
> • never type single paren. I always type them in pairs. And never
> delete one of them.
> • use tree navigation to move between code.
> • to delete or move parts of expression, select the whole expression,
> cut & copy to move.
>
> so, when i code in lisp, there is never ever unmatched parenthesis.
>
> this method beats paren-edit mode.
Ive *not* written this lisp.
All did (or tried to do) was take some existing lisp and change it a
bit here and there -- mostly nothing more than changing some strings.
>
> the detail of my editing and setup is here:
>
> • Tips For Editing Lisp Code With Emacs
> http://xahlee.org/emacs/emacs_editing_lisp.html
>
> to select current unit of sexp, i press one key, which is bound to
> extend-selection, which is defined in my ergoemacs mode. The code is
> shown here:
>
> • A Text Editor Feature: Extend Selection By Semantic Unit
> http://xahlee.org/emacs/syntax_tree_walk.html
>
> Xah
> ∑http://xahlee.org/
>
> ☄
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: catching parenthesis errors in elisp
2009-06-12 12:06 ` rustom
@ 2009-06-12 12:24 ` Pascal J. Bourguignon
2009-06-12 12:25 ` rustom
1 sibling, 0 replies; 13+ messages in thread
From: Pascal J. Bourguignon @ 2009-06-12 12:24 UTC (permalink / raw)
To: help-gnu-emacs
rustom <rustompmody@gmail.com> writes:
> Ive *not* written this lisp.
What makes you think that our advices applies only on lisp code YOU
would have written? Obviously we apply them to OUR OWN code, not on
YOUR code!
> All did (or tried to do) was take some existing lisp and change it a
> bit here and there -- mostly nothing more than changing some strings.
Start again from the beginning.
1- download and load paredit. Evaluate (add-hook 'emacs-lisp-mode-hook 'paredit-mode)
2- Open the original emacs lisp file again.
3- Edit carefully with the help of paredit. Paredit also manages
strings so you cannot insert or remove a stray double-quote.
--
__Pascal Bourguignon__
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: catching parenthesis errors in elisp
2009-06-12 12:06 ` rustom
2009-06-12 12:24 ` Pascal J. Bourguignon
@ 2009-06-12 12:25 ` rustom
2009-06-12 15:32 ` Giorgos Keramidas
2009-06-13 2:47 ` Barry Margolin
1 sibling, 2 replies; 13+ messages in thread
From: rustom @ 2009-06-12 12:25 UTC (permalink / raw)
To: help-gnu-emacs
On Jun 12, 5:06 pm, rustom <rustompm...@gmail.com> wrote:
>
> Ive *not* written this lisp.
> All did (or tried to do) was take some existing lisp and change it a
> bit here and there -- mostly nothing more than changing some strings.
>
I should mention that now that error has gone -- in the sense that I'm
not getting scan errors and mismatch paren errors.
But the way it is behaving (or unbehaving) I conclude that large
sections of it have 'disappeared' into a string most likely.
I should also mention here what I did to 'get rid' of the error.
The function giving the paren error I moved into a new file
There I found that the culprit seemed to be a large let* -- moved it
to a second file
Voila! No check-paren errors (no changes on my part other than the C-M-
k and C-y done to move sexps around)
Moved file 2 back into file 1 where it was pulled out; then file1 back
into the original.
No check-paren errors ; no load errors.
I find this weird
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: catching parenthesis errors in elisp
2009-06-12 12:25 ` rustom
@ 2009-06-12 15:32 ` Giorgos Keramidas
2009-06-13 2:47 ` Barry Margolin
1 sibling, 0 replies; 13+ messages in thread
From: Giorgos Keramidas @ 2009-06-12 15:32 UTC (permalink / raw)
To: help-gnu-emacs
On Fri, 12 Jun 2009 05:25:33 -0700 (PDT), rustom <rustompmody@gmail.com> wrote:
>On Jun 12, 5:06 pm, rustom <rustompm...@gmail.com> wrote:
>> Ive *not* written this lisp.
>> All did (or tried to do) was take some existing lisp and change it a
>> bit here and there -- mostly nothing more than changing some strings.
>
> I should mention that now that error has gone -- in the sense that I'm
> not getting scan errors and mismatch paren errors.
>
> But the way it is behaving (or unbehaving) I conclude that large
> sections of it have 'disappeared' into a string most likely.
FWIW, syntax highlighting helps a lot when you are looking for this sort
of error. Try enabling font-lock-mode and skim through the function.
When you see large chunks of code highlighted with the colour of string
literals, it's often an indication of a missing quote or an extra quote.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: catching parenthesis errors in elisp
2009-06-12 7:05 catching parenthesis errors in elisp rustom
` (3 preceding siblings ...)
2009-06-12 11:55 ` Xah Lee
@ 2009-06-13 1:04 ` Joe Fineman
4 siblings, 0 replies; 13+ messages in thread
From: Joe Fineman @ 2009-06-13 1:04 UTC (permalink / raw)
To: help-gnu-emacs
I always enter parens in matching pairs. Combined with the use of C-j
for new lines, which makes paren errors conspicuous thru wrong
indentation, that pretty much eliminates such errors in writing defuns
ab initio.
However, in *revising* defuns it is often necessary to insert & delete
parens singly, and that can lead to an insidious kind of error (I have
made it several times in the last few days): an extra paren at the end
of the defun. That is indetectable thru indentation & does not
obstruct evaling it from within (C-M-x), but will cause an abort the
next time the .emacs or Commands.el file is loaded as a whole. The
best preventive I have found is to put point after the final paren &
look for a match; but you have to remember to do it.
--
--- Joe Fineman joe_f@verizon.net
||: Christians & Marxists think suffering must mean something. :||
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: catching parenthesis errors in elisp
2009-06-12 12:25 ` rustom
2009-06-12 15:32 ` Giorgos Keramidas
@ 2009-06-13 2:47 ` Barry Margolin
2009-06-13 6:43 ` rustom
1 sibling, 1 reply; 13+ messages in thread
From: Barry Margolin @ 2009-06-13 2:47 UTC (permalink / raw)
To: help-gnu-emacs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1618 bytes --]
In article
<029be122-b0a6-426c-ac48-18e970009a97@r31g2000prh.googlegroups.com>,
rustom <rustompmody@gmail.com> wrote:
> On Jun 12, 5:06 pm, rustom <rustompm...@gmail.com> wrote:
> >
> > Ive *not* written this lisp.
> > All did (or tried to do) was take some existing lisp and change it a
> > bit here and there -- mostly nothing more than changing some strings.
> >
>
> I should mention that now that error has gone -- in the sense that I'm
> not getting scan errors and mismatch paren errors.
>
> But the way it is behaving (or unbehaving) I conclude that large
> sections of it have 'disappeared' into a string most likely.
>
> I should also mention here what I did to 'get rid' of the error.
> The function giving the paren error I moved into a new file
> There I found that the culprit seemed to be a large let* -- moved it
> to a second file
> Voila! No check-paren errors (no changes on my part other than the C-M-
> k and C-y done to move sexps around)
>
> Moved file 2 back into file 1 where it was pulled out; then file1 back
> into the original.
> No check-paren errors ; no load errors.
>
> I find this weird
Re-indent the new file, and then diff it against the original that you
modified. Look for places where the change to a line is the amount of
indentation. That suggests a parenthesis problem right before that
(unless the intent of your change was to nest a block of code within
something new).
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: catching parenthesis errors in elisp
2009-06-13 2:47 ` Barry Margolin
@ 2009-06-13 6:43 ` rustom
0 siblings, 0 replies; 13+ messages in thread
From: rustom @ 2009-06-13 6:43 UTC (permalink / raw)
To: help-gnu-emacs
On Jun 13, 7:47 am, Barry Margolin <bar...@alum.mit.edu> wrote:
> Re-indent the new file, and then diff it against the original that you
> modified. Look for places where the change to a line is the amount of
> indentation. That suggests a parenthesis problem right before that
> (unless the intent of your change was to nest a block of code within
> something new).
>
Giorgos suggestion of using syntax coloring and yours of re-indenting
and re-checking are what I am trying (before hearing Pascal and
redoing it with paredit)
Are there some settings/modes to make white-space diffs standout
better?
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2009-06-13 6:43 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-12 7:05 catching parenthesis errors in elisp rustom
2009-06-12 9:57 ` Thien-Thi Nguyen
2009-06-12 10:18 ` Tim X
2009-06-12 11:02 ` rustom
2009-06-12 10:26 ` Thierry Volpiatto
2009-06-12 11:55 ` Xah Lee
2009-06-12 12:06 ` rustom
2009-06-12 12:24 ` Pascal J. Bourguignon
2009-06-12 12:25 ` rustom
2009-06-12 15:32 ` Giorgos Keramidas
2009-06-13 2:47 ` Barry Margolin
2009-06-13 6:43 ` rustom
2009-06-13 1:04 ` Joe Fineman
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).