Subject: Re: bug#14405: 24.3.50; read-regexp-defaults-function

From: Juri Linkov <[email-masked]>
Date: Thu, 16 May 2013 01:58:33 +0300

> There are pending enhancements to create a single option to define
> the same defaulting behavior for all regexp-reading commands
> and to group the existing defaults to separate functions
> that can be overridden by customizing that option.

But note that the option `read-regexp-defaults-function' has
limited usefulness.  For example, in case when someone wants
`M-x man' to provide the default value not an entry near point
but the last element from the history, there is no way to do
this by customizing a common option because `man' uses the
specific variable `Man-topic-history'.

I see the only way to customize this by using `advice' like:

  (advice-add 'Man-default-man-entry :override
              (lambda () (car Man-topic-history)))

or even two default values (the last history and the original):

  (advice-add 'Man-default-man-entry :filter-return
              (lambda (r) (delq nil (list (car Man-topic-history) r))))

If advices are the preferable method of customization then the
design goal would be to add more functions returning default values
that users can customize using advices.  For example, for `grep'
there is already `grep-tag-default' that could be customized like:

  (advice-add 'grep-tag-default :override
              (lambda () (car grep-regexp-history)))

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

Other commands require adding more functions for advice-based customization
like `occur-read-regexp-defaults' and `hi-lock-read-regexp-defaults'.