emacs-diffs
[Top][All Lists]
Advanced

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

Re: [Emacs-diffs] /srv/bzr/emacs/trunk r111878: * lisp/replace.el (read-


From: Jambunathan K
Subject: Re: [Emacs-diffs] /srv/bzr/emacs/trunk r111878: * lisp/replace.el (read-regexp): Let-bind `default' to the first
Date: Thu, 28 Feb 2013 15:00:55 +0530
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

emacs -Q
M-s h r

I find the following error

,----
| Debugger entered--Lisp error: (error "Regexp cannot match an empty string")
|   signal(error ("Regexp cannot match an empty string"))
|   error("Regexp cannot match an empty string")
|   hi-lock-regexp-okay("")
|   byte-code("address@hidden"!\304 D\207" [regexp-history hi-lock-regexp-okay 
read-regexp "Regexp to highlight" hi-lock-read-face-name] 4)
|   call-interactively(highlight-regexp nil nil)
|   command-execute(highlight-regexp)
`----

So, if one does 
        (read-regexp something) ;; something is nil or evals to nil

what should the interpretation be.

With your change, a `nil' default will provide an empty string as input
and force user to enter a regexp or rely on M-n.

We seem to be bumping in to each other in this area.  Comments ...?

,---- Stefan @ http://debbugs.gnu.org/cgi/bugreport.cgi?bug=13687#11
| I disagree: read-regexp is a generic function which can be used in
| various contexts, some of which might not care at all about the text
| around point.  So the caller should have control over the first default
| (of course, it's perfectly fine to always add the current tag in the
| subsequent defaults).
| 
| This said your patch seems to leave the caller's provided `defaults' at
| the beginning of the minibuffer's `defaults', so I think your patch is
| fine, feel free to install it.
`----

I am wondering how we can resolve the contex-free read-regexp and
context-dependent regexp.  Any suggestions?



Juri Linkov <address@hidden> writes:

> ------------------------------------------------------------
> revno: 111878
> fixes bug: http://debbugs.gnu.org/13805
> committer: Juri Linkov <address@hidden>
> branch nick: trunk
> timestamp: Mon 2013-02-25 22:57:44 +0200
> message:
>   * lisp/replace.el (read-regexp): Let-bind `default' to the first
>   element of `defaults' if it's a list, otherwise it should be
>   a string or nil.  Let-bind `suggestions' to `defaults' if it's
>   a list, otherwise make a list with the string value.  Doc fix.
> modified:
>   lisp/ChangeLog
>   lisp/replace.el
>
> === modified file 'lisp/ChangeLog'
> --- a/lisp/ChangeLog  2013-02-25 17:36:03 +0000
> +++ b/lisp/ChangeLog  2013-02-25 20:57:44 +0000
> @@ -1,3 +1,11 @@
> +2013-02-25  Juri Linkov  <address@hidden>
> +
> +     * replace.el (read-regexp): Let-bind `default' to the first
> +     element of `defaults' if it's a list, otherwise it should be
> +     a string or nil.  Let-bind `suggestions' to `defaults' if it's
> +     a list, otherwise make a list with the string value.  Doc fix.
> +     (Bug#13805)
> +
>  2013-02-25  Eli Zaretskii  <address@hidden>
>  
>       * emacs-lisp/bytecomp.el (byte-recompile-directory): Reject files
>
> === modified file 'lisp/replace.el'
> --- a/lisp/replace.el 2013-02-22 17:13:05 +0000
> +++ b/lisp/replace.el 2013-02-25 20:57:44 +0000
> @@ -583,34 +583,39 @@
>  (defun read-regexp (prompt &optional defaults history)
>    "Read and return a regular expression as a string.
>  When PROMPT doesn't end with a colon and space, it adds a final \": \".
> -If DEFAULTS is non-nil, it displays the first default in the prompt.
> +If the first element of DEFAULTS is non-nil, it's added to the prompt.
>  
> -Optional arg DEFAULTS is a string or a list of strings that are
> -prepended to a list of standard default values, which include the
> -tag at point, the last isearch regexp, the last isearch string,
> +Optional arg DEFAULTS has the form (DEFAULT . SUGGESTIONS)
> +or simply DEFAULT where DEFAULT, if non-nil, should be a string that
> +is returned as the default value when the user enters empty input.
> +SUGGESTIONS is a list of strings that can be inserted into
> +the minibuffer using \\<minibuffer-local-map>\\[next-history-element].  \
> +The values supplied in SUGGESTIONS
> +are prepended to the list of standard suggestions that include
> +the tag at point, the last isearch regexp, the last isearch string,
>  and the last replacement regexp.
>  
> -Non-nil HISTORY is a symbol to use for the history list.
> +Optional arg HISTORY is a symbol to use for the history list.
>  If HISTORY is nil, `regexp-history' is used."
> -  (let* ((defaults
> -        (append
> -         (if (listp defaults) defaults (list defaults))
> -         (list
> -          ;; Regexp for tag at point.
> -          (let* ((tagf (or find-tag-default-function
> -                                 (get major-mode 'find-tag-default-function)
> -                                 'find-tag-default))
> -                 (tag (funcall tagf)))
> -            (cond ((not tag) "")
> -                  ((eq tagf 'find-tag-default)
> -                   (format "\\_<%s\\_>" (regexp-quote tag)))
> -                  (t (regexp-quote tag))))
> -               (car regexp-search-ring)
> -               (regexp-quote (or (car search-ring) ""))
> -               (car (symbol-value
> -                     query-replace-from-history-variable)))))
> -      (defaults (delete-dups (delq nil (delete "" defaults))))
> -      (default (car defaults))
> +  (let* ((default     (if (consp defaults) (car defaults) defaults))
> +      (suggestions (if (listp defaults) defaults (list defaults)))
> +      (suggestions
> +       (append
> +        suggestions
> +        (list
> +         ;; Regexp for tag at point.
> +         (let* ((tagf (or find-tag-default-function
> +                          (get major-mode 'find-tag-default-function)
> +                          'find-tag-default))
> +                (tag (funcall tagf)))
> +           (cond ((not tag) "")
> +                 ((eq tagf 'find-tag-default)
> +                  (format "\\_<%s\\_>" (regexp-quote tag)))
> +                 (t (regexp-quote tag))))
> +         (car regexp-search-ring)
> +         (regexp-quote (or (car search-ring) ""))
> +         (car (symbol-value query-replace-from-history-variable)))))
> +      (suggestions (delete-dups (delq nil (delete "" suggestions))))
>        ;; Do not automatically add default to the history for empty input.
>        (history-add-new-input nil)
>        (input (read-from-minibuffer
> @@ -621,9 +626,11 @@
>                                (query-replace-descr default)))
>                      (t
>                       (format "%s: " prompt)))
> -              nil nil nil (or history 'regexp-history) defaults t)))
> +              nil nil nil (or history 'regexp-history) suggestions t)))
>      (if (equal input "")
> +     ;; Return the default value when the user enters empty input.
>       (or default input)
> +      ;; Otherwise, add non-empty input to the history and return input.
>        (prog1 input
>       (add-to-history (or history 'regexp-history) input)))))
>  
>
>

-- 



reply via email to

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