emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

functions which read by prompting should not add additional chars to pro


From: MON KEY
Subject: functions which read by prompting should not add additional chars to prompt string
Date: Sat, 22 Jan 2011 15:38:25 -0500

Lisp functions which read user input and accept a PROMPT arg should
not append additional characters to the supplied PROMPT string
esp. when no additional arguments are supplied.

---
`read-regexp' lisp/replace.el

When read-regexp's optional arg DEFAULT-VALUE is not true, why are a
colon (char 58) and space (char 32) tacked onto end of PROMPT? e.g.:

 (if default-value
     (format "%s (default %s): " prompt
             (query-replace-descr default-value))
   (format "%s: " prompt))
              ^
This should be:

  (format "%s" prompt)

For a `read-*' style function, the behaviour of `read-regexp' is
annoying b/c its name suggest that it is the public interface for
reading regexps. esp.

Indeed, there are regexp readers in other packages which don't use the
`read-regexp' interface, instead rolling their own readers, e.g.:

 `dired-read-regexp' `ad-read-regexp' `grep-read-regexp'

As such, I would suggest that the `read-regexp' interface might be
adjusted to offer a more conformant behaviour without too much
trouble.

There are eight functions in ./lisp which directly call `read-regexp'.

Of the eight only four supply have provision for a DEFAULT-VALUE:

 `hi-lock-line-face-buffer'   `hi-lock-face-buffer',
 `hi-lock-face-phrase-buffer' `occur-read-primary-arg'

Each of the above rely on the value of (car regexp-history) for
DEFAULT-VALUE.  IOW, even where callers do supply DEFAULT-VALUE there
is no guarantee that the car of `regexp-history' isn't null.

A good fix might be to adjust the existing semantics of `read-regexp's
DEFAULT-VALUE to accept a boolean which when t defaults to whatever is
at the head `regexp-history' e.g.:

 (and (eq default-value t) (setq default-value (car regexp-history)))

Following enumerates the eight functions in ./lisp which rgrep shows
as direct callers of `read-regexp'. I've indicated their
PROPMT and supply annotation as to which provide a DEFAULT-VALUE.

-
lisp/replace.el
No defaulting behaviour:
`keep-lines-read-args'
 ;--> (read-regexp prompt)

With DEFAULT-VALUE supplied but regexp-history may may be nil:
`occur-read-primary-arg'
 ;--> (read-regexp "List lines matching regexp" (car regexp-history))

-
lisp/faces.el
No defaulting behaviour:
`list-faces-display'
 ;--> (read-regexp "List faces matching regexp")

-
lisp/hi-lock.el
Each supplies a DEFAULT-VAULUE, but regexp-history may may be nil:

`hi-lock-line-face-buffer'
 ;--> (read-regexp "Regexp to highlight line" (car regexp-history))

`hi-lock-face-buffer'
 ;--> (read-regexp "Regexp to highlight" (car regexp-history))

`hi-lock-face-phrase-buffer'
 ;--> (read-regexp "Phrase to highlight" (car regexp-history))

-
lisp/misearch.el
No defaulting behavior:
`multi-isearch-read-matching-buffers'
 ;--> (read-regexp "Search in buffers whose names match regexp")

`multi-isearch-read-matching-files'
 ;--> (read-regexp "Search in files whose names match wildcard")

---
Following two functions, `read-face-name' and `read-quoted-char' both
step on the supplied PROMPT and should be fixed:

(read-face-name   "face ")

(read-quoted-char "char ")

`read-quoted-char' behaves has doubly bad by tacking on a "-". Why?

---
`read-buffer' may step on the PROMPT string only when DEF is non-nil:

(read-buffer "buffer ")

However her buddy `read-buffer-to-switch' has non-standard prompt
string defaulting behavior similiar to that of `read-regexp'.

Though, unlike `read-regexp' which is implemented in lisp,
`read-buffer-to-switch' is a lisp wrapper around the C primitive
`read-buffer' defined in src/minibuf.c `read-buffer' will acknowledge
`read-buffer-function' when non-nil and allows callers to override its
own non standard prompt string defaulting.

(read-buffer-to-switch "switch to buffer ")

---
For comparsion, following is a list of "reading" functions which do
not not step on a supplied PROMPT string by tacking on additional
characters:

(read-minibuffer            "lispy thing ")
(read-from-minibuffer       "string ")
(read-string                "string ")
(read-no-blanks-input       "no spaces please ")
(read-number                "number ")
(read-passwd                "password ")
(read-event                 "event ")
(read-key-sequence          "key sequence ")
(read-key-sequence-vector   "key sequence ")
(read-variable              "variable ")
(read-command               "command ")
(read-file-name             "file ")
(read-directory-name        "directory ")
(read-color                 "color ")
(read-envvar-name           "envvar ")
(read-shell-command         "shell-command ")
(read-char                  "char ")
(read-char-by-name          "char-name ")
(read-char-exclusive        "char ")
(read-charset               "charset ")
(read-file-modes            "modes ")
(read-multilingual-string   "string ")
(read-non-nil-coding-system "coding system ")
(read-input-method-name     "input method ")
(read-language-name         'documentation "lang ")
(read-coding-system         "coding sytem ")

--
/s_P\



reply via email to

[Prev in Thread] Current Thread [Next in Thread]