unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#10191: dired-query (in dired-aux.el) fails for certain help-char's, Emacs 23 and 24
@ 2011-12-02  6:27 Christopher Genovese
  2011-12-02  8:36 ` Andreas Schwab
  2011-12-02 14:18 ` Stefan Monnier
  0 siblings, 2 replies; 6+ messages in thread
From: Christopher Genovese @ 2011-12-02  6:27 UTC (permalink / raw)
  To: 10191

[-- Attachment #1: Type: text/plain, Size: 3723 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 10244 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#10191: dired-query (in dired-aux.el) fails for certain help-char's, Emacs 23 and 24
  2011-12-02  6:27 bug#10191: dired-query (in dired-aux.el) fails for certain help-char's, Emacs 23 and 24 Christopher Genovese
@ 2011-12-02  8:36 ` Andreas Schwab
  2011-12-02 13:22   ` Christopher Genovese
  2011-12-02 14:18 ` Stefan Monnier
  1 sibling, 1 reply; 6+ messages in thread
From: Andreas Schwab @ 2011-12-02  8:36 UTC (permalink / raw)
  To: Christopher Genovese; +Cc: 10191

Christopher Genovese <genovese.cr@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@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#10191: dired-query (in dired-aux.el) fails for certain help-char's, Emacs 23 and 24
  2011-12-02  8:36 ` Andreas Schwab
@ 2011-12-02 13:22   ` Christopher Genovese
  0 siblings, 0 replies; 6+ messages in thread
From: Christopher Genovese @ 2011-12-02 13:22 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: 10191

[-- Attachment #1: Type: text/plain, Size: 2362 bytes --]

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@linux-m68k.org> wrote:

> Christopher Genovese <genovese.cr@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@linux-m68k.org
> GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
> "And now for something completely different."
>

[-- Attachment #2: Type: text/html, Size: 2964 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#10191: dired-query (in dired-aux.el) fails for certain help-char's, Emacs 23 and 24
  2011-12-02  6:27 bug#10191: dired-query (in dired-aux.el) fails for certain help-char's, Emacs 23 and 24 Christopher Genovese
  2011-12-02  8:36 ` Andreas Schwab
@ 2011-12-02 14:18 ` Stefan Monnier
  2011-12-02 16:37   ` Andreas Schwab
  1 sibling, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2011-12-02 14:18 UTC (permalink / raw)
  To: Christopher Genovese; +Cc: 10191-done

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






^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#10191: dired-query (in dired-aux.el) fails for certain help-char's, Emacs 23 and 24
  2011-12-02 14:18 ` Stefan Monnier
@ 2011-12-02 16:37   ` Andreas Schwab
  2011-12-02 17:26     ` Glenn Morris
  0 siblings, 1 reply; 6+ messages in thread
From: Andreas Schwab @ 2011-12-02 16:37 UTC (permalink / raw)
  To: 10191

Stefan Monnier <monnier@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@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#10191: dired-query (in dired-aux.el) fails for certain help-char's, Emacs 23 and 24
  2011-12-02 16:37   ` Andreas Schwab
@ 2011-12-02 17:26     ` Glenn Morris
  0 siblings, 0 replies; 6+ messages in thread
From: Glenn Morris @ 2011-12-02 17:26 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: 10191

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.





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-12-02 17:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-02  6:27 bug#10191: dired-query (in dired-aux.el) fails for certain help-char's, Emacs 23 and 24 Christopher Genovese
2011-12-02  8:36 ` Andreas Schwab
2011-12-02 13:22   ` Christopher Genovese
2011-12-02 14:18 ` Stefan Monnier
2011-12-02 16:37   ` Andreas Schwab
2011-12-02 17:26     ` Glenn Morris

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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