GNU bug report logs - #13687
24.3.50; `read-regexp' should provide regex for symbol at point as defaults

Previous Next

Package: emacs;

Reported by: Jambunathan K <kjambunathan <at> gmail.com>

Date: Mon, 11 Feb 2013 06:30:02 UTC

Severity: wishlist

Found in version 24.3.50

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Juri Linkov <juri <at> jurta.org>
To: Jambunathan K <kjambunathan <at> gmail.com>
Cc: 13687 <at> debbugs.gnu.org
Subject: bug#13687: /srv/bzr/emacs/trunk r111878: * lisp/replace.el (read-regexp): Let-bind `default' to the first
Date: Sun, 03 Mar 2013 11:31:04 +0200
> So the question is: should the default value in the caller
> `highlight-regexp' be changed from `(car regexp-history)'
> to code that gets the tag at point?  You could propose
> such a change, but since it changes the long-standing behavior,
> expect some disagreement (not from me :-)

There are surprisingly many users who prefer the previous item from the
history instead of the tag at point as the default value of `occur',
`highlight-regexp', `rgrep'.  They got `(car regexp-history)' hard-coded
into core Emacs for `occur' and `highlight-regexp', but not for `rgrep',
so they raise the questions how to do the same for `rgrep', and get such
horribly ugly solutions as this one:

http://stackoverflow.com/questions/15161592/make-emacs-rgrep-default-to-last-search-term-rather-than-word-at-point

This situation suggests that the default values should be customizable.
Possible variants:

1. Put a special value on the command's symbol like:
   (put 'highlight-regexp 'default 'history)
   (put 'highlight-regexp 'default 'tag-at-point)
   checked on `this-command' in minibuffer-reading functions.
   Cons: Not easy to use.

2. Add a new defcustom like:
   (defcustom minibuffer-defaults '((highlight-regexp-default . tag-at-point)
                                    (rgrep . history)
                                    (occur . tag-at-point)
                                    (how-many . history)
                                    ...))
   Cons: Too large list of commands for one option.

3. In the DEFAULT arg of minibuffer-reading calls
   specify a function that returns default values:

   (defun highlight-regexp (regexp &optional face)
     (interactive
      (list
       (read-regexp "Regexp to highlight" 'highlight-regexp-default)
       ...

   (defun highlight-regexp-default ()
     (car regexp-history))

   where users can override it with another function:

   (defun highlight-regexp-default ()
     (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)))))

   Pros: Flexible and easy to configure.




This bug report was last modified 12 years and 68 days ago.

Previous Next


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