GNU bug report logs - #283
scan-error for keyboard macro

Previous Next

Package: emacs;

Reported by: "Roland Winkler" <Roland.Winkler <at> physik.uni-erlangen.de>

Date: Tue, 20 May 2008 07:15:02 UTC

Severity: normal

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 283 in the body.
You can then email your comments to 283 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#283; Package emacs. Full text and rfc822 format available.

Acknowledgement sent to "Roland Winkler" <Roland.Winkler <at> physik.uni-erlangen.de>:
New bug report received and forwarded. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. Full text and rfc822 format available.

Message #5 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):

From: "Roland Winkler" <Roland.Winkler <at> physik.uni-erlangen.de>
To: bug-gnu-emacs <at> gnu.org
Subject: scan-error for keyboard macro
Date: Tue, 20 May 2008 09:06:19 +0200
The following piece of code was generated with insert-kbd-macro

(fset 'foo
   [?\C-[ ?f ?\C-[ ?  ?\C-[ ?b ?\C-[ ?w ?\C-x ?o ?\C-x ?\C-v left left ?\C-@ ?\C-r ?/ ?\C-m ?\C-w ?/ ?\C-y ?\C-[ ?y ?\C-m ?\C-x ?o])

If you put it into a file and load the file, the macro is available.
If you put point at the end of the macro definition and execute
C-x C-e (eval-last-sexp) this does not allow you to load the macro
(though eval-last-sexp doesn't throw an error, in the end the
macro foo is not available). If you put point inside the macro
definition and type C-M-x (eval-defun) it throws the error

(scan-error "Unbalanced parentheses" 1 145)

In GNU Emacs 22.2.1 (i686-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
 of 2008-03-27 on tfkp07
configured using `configure  '--with-x''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: C
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_US.iso885915
  locale-coding-system: iso-8859-15
  default-enable-multibyte-characters: nil





Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#283; Package emacs. Full text and rfc822 format available.

Acknowledgement sent to Stefan Monnier <monnier <at> IRO.UMontreal.CA>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. Full text and rfc822 format available.

Message #10 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Roland Winkler <Roland.Winkler <at> physik.uni-erlangen.de>
Cc: 283 <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
Subject: Re: bug#283: scan-error for keyboard macro
Date: Tue, 20 May 2008 09:06:28 -0400
> The following piece of code was generated with insert-kbd-macro
> (fset 'foo
>    [?\C-[ ?f ?\C-[ ?  ?\C-[ ?b ?\C-[ ?w ?\C-x ?o ?\C-x ?\C-v left left ?\C-@ ?\C-r ?/ ?\C-m ?\C-w ?/ ?\C-y ?\C-[ ?y ?\C-m ?\C-x ?o])

> If you put it into a file and load the file, the macro is available.
> If you put point at the end of the macro definition and execute
> C-x C-e (eval-last-sexp) this does not allow you to load the macro
> (though eval-last-sexp doesn't throw an error, in the end the
> macro foo is not available). If you put point inside the macro
> definition and type C-M-x (eval-defun) it throws the error

> (scan-error "Unbalanced parentheses" 1 145)

The problem is a known one: the emacs-lisp-mode and its syntax-table
does not properly recognize all the escaping going on in
character constants.  E.g. in ?\C-[, the mode thinks this opens a square
bracket expression.  If you add \ in front of the [ the problem
will disappear.

So we could fix it either by improving the Elisp code (i.e. either
improve syntax.c to be able to understand it, or add
a font-lock-syntactic-keywords), or by changing the printer code to
escape those chars with a \.  Can you confirm that the patch below
fixes it?


        Stefan


=== modified file 'lisp/macros.el'
--- lisp/macros.el	2008-05-06 14:18:59 +0000
+++ lisp/macros.el	2008-05-20 13:05:47 +0000
@@ -86,45 +86,7 @@
 	  (setq end (point-marker))
 	  (goto-char beg)
 	  (while (< (point) end)
-	    (let ((char (following-char)))
-	      (cond ((= char 0)
-		     (delete-region (point) (1+ (point)))
-		     (insert "\\C-@"))
-		    ((< char 27)
-		     (delete-region (point) (1+ (point)))
-		     (insert "\\C-" (+ 96 char)))
-		    ((= char ?\C-\\)
-		     (delete-region (point) (1+ (point)))
-		     (insert "\\C-\\\\"))
-		    ((< char 32)
-		     (delete-region (point) (1+ (point)))
-		     (insert "\\C-" (+ 64 char)))
-		    ((< char 127)
-		     (forward-char 1))
-		    ((= char 127)
-		     (delete-region (point) (1+ (point)))
-		     (insert "\\C-?"))
-		    ((= char 128)
-		     (delete-region (point) (1+ (point)))
-		     (insert "\\M-\\C-@"))
-		    ((= char (aref "\M-\C-\\" 0))
-		     (delete-region (point) (1+ (point)))
-		     (insert "\\M-\\C-\\\\"))
-		    ((< char 155)
-		     (delete-region (point) (1+ (point)))
-		     (insert "\\M-\\C-" (- char 32)))
-		    ((< char 160)
-		     (delete-region (point) (1+ (point)))
-		     (insert "\\M-\\C-" (- char 64)))
-		    ((= char (aref "\M-\\" 0))
-		     (delete-region (point) (1+ (point)))
-		     (insert "\\M-\\\\"))
-		    ((< char 255)
-		     (delete-region (point) (1+ (point)))
-		     (insert "\\M-" (- char 128)))
-		    ((= char 255)
-		     (delete-region (point) (1+ (point)))
-		     (insert "\\M-\\C-?"))))))
+            (prin1-char (following-char))))
       (if (vectorp definition)
 	  (let ((len (length definition)) (i 0) char mods)
 	    (while (< i len)






Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#283; Package emacs. Full text and rfc822 format available.

Acknowledgement sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. Full text and rfc822 format available.

Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#283; Package emacs. Full text and rfc822 format available.

Acknowledgement sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. Full text and rfc822 format available.

Message #20 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Roland Winkler <Roland.Winkler <at> physik.uni-erlangen.de>
Cc: 283 <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
Subject: Re: bug#283: scan-error for keyboard macro
Date: Tue, 20 May 2008 10:39:45 -0400
>> The following piece of code was generated with insert-kbd-macro
>> (fset 'foo
>> [?\C-[ ?f ?\C-[ ?  ?\C-[ ?b ?\C-[ ?w ?\C-x ?o ?\C-x ?\C-v left left ?\C-@ ?\C-r ?/ ?\C-m ?\C-w ?/ ?\C-y ?\C-[ ?y ?\C-m ?\C-x ?o])

>> If you put it into a file and load the file, the macro is available.
>> If you put point at the end of the macro definition and execute
>> C-x C-e (eval-last-sexp) this does not allow you to load the macro
>> (though eval-last-sexp doesn't throw an error, in the end the
>> macro foo is not available). If you put point inside the macro
>> definition and type C-M-x (eval-defun) it throws the error

>> (scan-error "Unbalanced parentheses" 1 145)

> The problem is a known one: the emacs-lisp-mode and its syntax-table
> does not properly recognize all the escaping going on in
> character constants.  E.g. in ?\C-[, the mode thinks this opens a square
> bracket expression.  If you add \ in front of the [ the problem
> will disappear.

> So we could fix it either by improving the Elisp code (i.e. either
> improve syntax.c to be able to understand it, or add
> a font-lock-syntactic-keywords), or by changing the printer code to
> escape those chars with a \.  Can you confirm that the patch below
> fixes it?

I wasn't very awak when I wrote that patch.  The patch below seems to
actually work.  Of course, it only fixes the printing part, so if you
already have the above fest in your .emacs, that won't directly help you.


        Stefan


--- macros.el.~1.54.~	2008-05-11 17:49:20.000000000 -0400
+++ macros.el	2008-05-20 10:37:31.000000000 -0400
@@ -131,41 +131,9 @@
 	      (insert (if (zerop i) ?\[ ?\s))
 	      (setq char (aref definition i)
 		    i (1+ i))
-	      (cond ((not (numberp char))
-		     (prin1 char (current-buffer)))
-		    (t
-		     (insert "?")
-		     (setq mods (event-modifiers char)
-			   char (event-basic-type char))
-		     (while mods
-		       (cond ((eq (car mods) 'control)
-			      (insert "\\C-"))
-			     ((eq (car mods) 'meta)
-			      (insert "\\M-"))
-			     ((eq (car mods) 'hyper)
-			      (insert "\\H-"))
-			     ((eq (car mods) 'super)
-			      (insert "\\s-"))
-			     ((eq (car mods) 'alt)
-			      (insert "\\A-"))
-			     ((and (eq (car mods) 'shift)
-				   (>= char ?a)
-				   (<= char ?z))
-			      (setq char (upcase char)))
-			     ((eq (car mods) 'shift)
-			      (insert "\\S-")))
-		       (setq mods (cdr mods)))
-		     (cond ((= char ?\\)
-			    (insert "\\\\"))
-                           ((= char ?\")
-                            (insert "\\\""))
-			   ((= char ?\;)
-			    (insert "\\;"))
-			   ((= char 127)
-			    (insert "\\C-?"))
-			   ((< char 127)
-			    (insert char))
-			   (t (insert "\\" (format "%o" char)))))))
+	      (if (not (numberp char))
+                  (prin1 char (current-buffer))
+                (princ (prin1-char char) (current-buffer))))
 	    (insert ?\]))
 	(prin1 definition (current-buffer))))
     (insert ")\n")







Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#283; Package emacs. Full text and rfc822 format available.

Acknowledgement sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. Full text and rfc822 format available.

Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#283; Package emacs. Full text and rfc822 format available.

Acknowledgement sent to "Roland Winkler" <Roland.Winkler <at> physik.uni-erlangen.de>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. Full text and rfc822 format available.

Message #30 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):

From: "Roland Winkler" <Roland.Winkler <at> physik.uni-erlangen.de>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 283 <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
Subject: Re: bug#283: scan-error for keyboard macro
Date: Wed, 21 May 2008 04:58:17 +0200
On Tue May 20 2008 Stefan Monnier wrote:
> The problem is a known one: the emacs-lisp-mode and its
> syntax-table does not properly recognize all the escaping going on
> in character constants. E.g. in ?\C-[, the mode thinks this opens
> a square bracket expression. If you add \ in front of the [ the
> problem will disappear.

Thanks a lot, if the backslash in front of the [ can solve this
problem, then this is even an adequate fix for an existing
collection of keyboard macros.

> So we could fix it either by improving the Elisp code (i.e. either
> improve syntax.c to be able to understand it, or add
> a font-lock-syntactic-keywords), or by changing the printer code to
> escape those chars with a \.  Can you confirm that the patch below
> fixes it?
> 
> I wasn't very awak when I wrote that patch. The patch below seems
> to actually work.

I loaded the file that contains my keyboard macros and I created it
again with the patched version of insert-kbd-macro. The only
difference between the old and new file was the \ in front of the [.
So on that level I can say that your patch has fixed my problem with
apparently no undesired side effects.

Thanks a lot,

Roland





Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#283; Package emacs. Full text and rfc822 format available.

Acknowledgement sent to "Roland Winkler" <Roland.Winkler <at> physik.uni-erlangen.de>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. Full text and rfc822 format available.

Reply sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
You have taken responsibility. Full text and rfc822 format available.

Notification sent to "Roland Winkler" <Roland.Winkler <at> physik.uni-erlangen.de>:
bug acknowledged by developer. Full text and rfc822 format available.

Message #40 received at 283-done <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: 283-done <at> debbugs.gnu.org
Subject: Re: bug#283: scan-error for keyboard macro
Date: Wed, 21 May 2008 11:36:16 -0400
>> The problem is a known one: the emacs-lisp-mode and its
>> syntax-table does not properly recognize all the escaping going on
>> in character constants. E.g. in ?\C-[, the mode thinks this opens
>> a square bracket expression. If you add \ in front of the [ the
>> problem will disappear.

> Thanks a lot, if the backslash in front of the [ can solve this
> problem, then this is even an adequate fix for an existing
> collection of keyboard macros.

Yes, that should fix it.

> I loaded the file that contains my keyboard macros and I created it
> again with the patched version of insert-kbd-macro. The only
> difference between the old and new file was the \ in front of the [.
> So on that level I can say that your patch has fixed my problem with
> apparently no undesired side effects.

Thanks, installed,


        Stefan




bug archived. Request was from Debbugs Internal Request <don <at> donarmstrong.com> to internal_control <at> emacsbugs.donarmstrong.com. (Thu, 19 Jun 2008 14:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 17 years and 63 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.