Subject: bug#10191: closed (Re: bug#10191: dired-query (in dired-aux.el) fails for certain help-char's, Emacs 23 and 24)

From: [email-masked] (GNU bug Tracking System)
Date: Fri, 02 Dec 2011 14:19:02 +0000

Your bug report

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

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
10191: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=10191
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#10191: dired-query (in dired-aux.el) fails for certain help-char's, Emacs 23 and 24
From: Stefan Monnier <[email-masked]>
To: Christopher Genovese <[email-masked]>
Cc: [email-masked]
Date: Fri, 02 Dec 2011 09:18:35 -0500
List-Id: <debbugs-submit.debbugs.gnu.org>

> ; 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)))))

Subject: dired-query (in dired-aux.el) fails for certain help-char's, Emacs 23 and 24
From: Christopher Genovese <[email-masked]>
To: [email-masked]
Date: Fri, 2 Dec 2011 01:27:02 -0500
List-Id: <debbugs-submit.debbugs.gnu.org>

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