GNU bug report logs - #10191
dired-query (in dired-aux.el) fails for certain help-char's, Emacs 23 and 24

Previous Next

Package: emacs;

Reported by: Christopher Genovese <genovese.cr <at> gmail.com>

Date: Fri, 2 Dec 2011 06:28:01 UTC

Severity: minor

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 10191 in the body.
You can then email your comments to 10191 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-gnu-emacs <at> gnu.org:
bug#10191; Package emacs. (Fri, 02 Dec 2011 06:28:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Christopher Genovese <genovese.cr <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 02 Dec 2011 06:28:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Christopher Genovese <genovese.cr <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: dired-query (in dired-aux.el) fails for certain help-char's, Emacs 23
	and 24
Date: Fri, 2 Dec 2011 01:27:02 -0500
[Message part 1 (text/plain, inline)]
Whether this is a bug or a ... misunderstanding may be a matter of opinion
because it goes to the nature of help-char. But the problem is easily
fixed in any case.

The function dired-query fails for certain settings of help-char; this
occurs
during the execution of other dired commands (e.g., dired-do-rename-regexp)
without a clear trace of the problem for the user.

For example, I set my help-char to ?\M-\C-h, which works fine in general.
But despite looking like a character, ?\M-\C-h does not satisfy
#'characterp, which causes
the problem. Technically perhaps, help-char should be a character but from
the user's point
of view, both of these should qualify.  While help-event-list can handle
this,
using help-char with such a value works in all the other cases I've seen.

The failure occurs at the following sexp in dired-query (the same code in
23 and 24
despite significant differences in the functions between the two versions):

; original
(if help-form
    (format " [Type yn!q or %s] "
            (key-description
             (char-to-string help-char)))
  " [Type y, n, q or !] ")

When (characterp help-char) is nil, as in my case, char-to-string raises an
error.
Because I find it highly desirable to allow "characters" like ?\M-\C-h for
help-char,
I think this is a bug worth fixing.

Here is a minimal fix for the offending sexp, not my first choice but an
easy change:

; minimal fix
(if (and help-form (characterp help-char))
    (format " [Type yn!q or %s] "
            (key-description
             (char-to-string help-char)))
  " [Type y, n, q or !] ")

Here's a simple fix for the offending sexp that gives better feedback:

; simple fix
(if help-form
    (format " [Type yn!q or %s] "
            (key-description
             (cond
              ((characterp help-char)
               (char-to-string help-char))
              ((eventp help-char)
               (append (event-modifiers help-char)
                       (list (event-basic-type help-char))))
              (t
               "your help char"))))
  " [Type y, n, q or !] ")

Because key-description does not abbreviate symbolic forms of
key modifiers, this gives output like "<control> <meta> h".
For nicer output, the following more elaborate fix could work,
although this *may* be too much for the purpose.

; more (too?) elaborate fix with nicer output
(if help-form
    (format " [Type yn!q or %s] "
            (cond
             ((characterp help-char)
              (key-description (char-to-string help-char)))
             ((eventp help-char)
              (let* ((modifiers
                      (reverse (event-modifiers help-char)))
                     (base
                      (event-basic-type help-char))
                     (mod->str '((meta . "M-")
                                 (control . "C-")
                                 (shift . "S-")
                                 (super . "s-")
                                 (hyper . "H-")
                                 (alt . "A-")
                                 (double . "double-click ")
                                 (triple . "triple-click ")
                                 (drag . "drag ")
                                 (click . "click ")))
                     (modstring  (lambda (mod)
                                   (cdr (assoc mod mod->str)))))
                (apply 'concat
                 (reverse
                  (cons
                    (if (characterp base)
                        (key-description (char-to-string base))
                      (symbol-name base))
                   (mapcar modstring modifiers))))))
             (t
              "your help char")))
  " [Type y, n, q or !] ")


Thanks,

  Chris
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10191; Package emacs. (Fri, 02 Dec 2011 08:37:01 GMT) Full text and rfc822 format available.

Message #8 received at 10191 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Schwab <schwab <at> linux-m68k.org>
To: Christopher Genovese <genovese.cr <at> gmail.com>
Cc: 10191 <at> debbugs.gnu.org
Subject: Re: bug#10191: dired-query (in dired-aux.el) fails for certain
	help-char's, Emacs 23 and 24
Date: Fri, 02 Dec 2011 09:36:26 +0100
Christopher Genovese <genovese.cr <at> gmail.com> writes:

> For example, I set my help-char to ?\M-\C-h, which works fine in general.
> But despite looking like a character, ?\M-\C-h does not satisfy
> #'characterp, which causes
> the problem. Technically perhaps, help-char should be a character but from
> the user's point
> of view, both of these should qualify.

?\M-\C-h isn't a character, it is a character with modifiers, and as
such does not qualify.  A character is something which can be inserted
in a buffer or string as-is, for example.

Andreas.

-- 
Andreas Schwab, schwab <at> linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10191; Package emacs. (Fri, 02 Dec 2011 13:24:01 GMT) Full text and rfc822 format available.

Message #11 received at 10191 <at> debbugs.gnu.org (full text, mbox):

From: Christopher Genovese <genovese.cr <at> gmail.com>
To: Andreas Schwab <schwab <at> linux-m68k.org>
Cc: 10191 <at> debbugs.gnu.org
Subject: Re: bug#10191: dired-query (in dired-aux.el) fails for certain
	help-char's, Emacs 23 and 24
Date: Fri, 2 Dec 2011 08:22:43 -0500
[Message part 1 (text/plain, inline)]
Hi Andreas,

    I understand that and tried to specifically address that point in my
report.
But I could have been clearer.

    I think that a change in this regard, even the minimal one I proposed,
is
worthwhile for at least two reasons. First, because setting help-char to
?\M-\C-h works
in terms of its main functionality (acting as a help character), it seems
unnecessary for
it to break a dired operation because of the formatting of a string.
Second, if the function
is going to be doctrinaire about help-char's type, then it has an
obligation, I think, to recognize
that not everyone uses a help "char" and might use help-event-list instead.
It should
then still do a characterp to avoid an error in those cases, possibly using
the car of
help-event-list for the error message when the characterp call returns
false.
This is not that different from my proposed change, and I'd be happy with
that.

     On the broader question, I would also argue that help-char should be
"help-event"
or "help-keyboard-event".  This is an example of one of the things in emacs
that are
IMHO too closely tied to the default keymap.  I set C-h to
delete-backward-char,
M-h to backward-kill-word, and C-M-h to help char. This is a quite
efficient arrangement
and should not cause breakage in simple services just because it deviates
from
the default. This is Emacs after all. (Also, from the naive user's
viewpoint, there
is not that much difference between specifying ?\M-\C-h and ?\C-h.  They
both *look*
like characters.)

    -- Chris


On Fri, Dec 2, 2011 at 03:36, Andreas Schwab <schwab <at> linux-m68k.org> wrote:

> Christopher Genovese <genovese.cr <at> gmail.com> writes:
>
> > For example, I set my help-char to ?\M-\C-h, which works fine in general.
> > But despite looking like a character, ?\M-\C-h does not satisfy
> > #'characterp, which causes
> > the problem. Technically perhaps, help-char should be a character but
> from
> > the user's point
> > of view, both of these should qualify.
>
> ?\M-\C-h isn't a character, it is a character with modifiers, and as
> such does not qualify.  A character is something which can be inserted
> in a buffer or string as-is, for example.
>
> Andreas.
>
> --
> Andreas Schwab, schwab <at> linux-m68k.org
> GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
> "And now for something completely different."
>
[Message part 2 (text/html, inline)]

Reply sent to Stefan Monnier <monnier <at> IRO.UMontreal.CA>:
You have taken responsibility. (Fri, 02 Dec 2011 14:19:01 GMT) Full text and rfc822 format available.

Notification sent to Christopher Genovese <genovese.cr <at> gmail.com>:
bug acknowledged by developer. (Fri, 02 Dec 2011 14:19:02 GMT) Full text and rfc822 format available.

Message #16 received at 10191-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Christopher Genovese <genovese.cr <at> gmail.com>
Cc: 10191-done <at> debbugs.gnu.org
Subject: Re: bug#10191: dired-query (in dired-aux.el) fails for certain
	help-char's, Emacs 23 and 24
Date: Fri, 02 Dec 2011 09:18:35 -0500
> ; original
> (if help-form
>     (format " [Type yn!q or %s] "
>             (key-description
>              (char-to-string help-char)))
>   " [Type y, n, q or !] ")

> When (characterp help-char) is nil, as in my case, char-to-string raises an
> error.

Thanks.  I've installed the patch below which should fix your problem,


        Stefan


=== modified file 'lisp/dired-aux.el'
--- lisp/dired-aux.el	2011-11-17 09:09:20 +0000
+++ lisp/dired-aux.el	2011-12-02 14:14:09 +0000
@@ -927,8 +927,7 @@
 		 (concat (apply 'format prompt args)
 			 (if help-form
 			     (format " [Type yn!q or %s] "
-				     (key-description
-				      (char-to-string help-char)))
+				     (key-description (vector help-char)))
 			   " [Type y, n, q or !] ")))
 	   (set sym (setq char (read-char-choice prompt char-choices)))
 	   (if (memq char '(?y ?\s ?!)) t)))))





Message #17 received at 10191-done <at> debbugs.gnu.org (full text, mbox):

From: Christopher Genovese <genovese.cr <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 10191-done <at> debbugs.gnu.org
Subject: Re: bug#10191: dired-query (in dired-aux.el) fails for certain
	help-char's, Emacs 23 and 24
Date: Fri, 2 Dec 2011 09:33:15 -0500
[Message part 1 (text/plain, inline)]
Ah, much better.  (Silly of me to forget about the vector; not sure what I
was thinking.)

That's terrific, thanks.

 -- Chris

On Fri, Dec 2, 2011 at 09:18, Stefan Monnier <monnier <at> iro.umontreal.ca>wrote:

>
> Thanks.  I've installed the patch below which should fix your problem,
>
>
>        Stefan
>
>
> === modified file 'lisp/dired-aux.el'
> --- lisp/dired-aux.el   2011-11-17 09:09:20 +0000
> +++ lisp/dired-aux.el   2011-12-02 14:14:09 +0000
> @@ -927,8 +927,7 @@
>                 (concat (apply 'format prompt args)
>                         (if help-form
>                             (format " [Type yn!q or %s] "
> -                                    (key-description
> -                                     (char-to-string help-char)))
> +                                    (key-description (vector help-char)))
>                           " [Type y, n, q or !] ")))
>           (set sym (setq char (read-char-choice prompt char-choices)))
>           (if (memq char '(?y ?\s ?!)) t)))))
>
>
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10191; Package emacs. (Fri, 02 Dec 2011 16:39:02 GMT) Full text and rfc822 format available.

Message #20 received at 10191 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Schwab <schwab <at> linux-m68k.org>
To: 10191 <at> debbugs.gnu.org
Cc: monnier <at> IRO.UMontreal.CA
Subject: Re: bug#10191: dired-query (in dired-aux.el) fails for certain
	help-char's, Emacs 23 and 24
Date: Fri, 02 Dec 2011 17:37:59 +0100
Stefan Monnier <monnier <at> IRO.UMontreal.CA> writes:

>> ; original
>> (if help-form
>>     (format " [Type yn!q or %s] "
>>             (key-description
>>              (char-to-string help-char)))
>>   " [Type y, n, q or !] ")
>
>> When (characterp help-char) is nil, as in my case, char-to-string raises an
>> error.
>
> Thanks.  I've installed the patch below which should fix your problem,

If we want to support keys as values of help-char that should probably
be documented.

Andreas.

-- 
Andreas Schwab, schwab <at> linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10191; Package emacs. (Fri, 02 Dec 2011 17:29:08 GMT) Full text and rfc822 format available.

Message #23 received at 10191 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Andreas Schwab <schwab <at> linux-m68k.org>
Cc: 10191 <at> debbugs.gnu.org
Subject: Re: bug#10191: dired-query (in dired-aux.el) fails for certain
	help-char's, Emacs 23 and 24
Date: Fri, 02 Dec 2011 12:26:54 -0500
Andreas Schwab wrote:

> If we want to support keys as values of help-char that should probably
> be documented.

I agree. There are 13 other places in the Emacs sources that call
(char-to-string help-char). It's only the fact that several are
preloaded, so that customizing help-char has no effect, that prevents
more things from breaking. Eg try loading buff-menu wih the OP's
setting, or reloading help.el. If a help-char setting doesn't work in
help.el, I think it's safe to say it doesn't work.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 31 Dec 2011 12:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 13 years and 178 days ago.

Previous Next


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