[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: `g' and `G' do not provide current url as the initial minibuffer contents
- From: Michael Heerdegen <michael_heerdegen@xxxxxx>
- Date: Thu, 31 Jul 2014 18:12:10 +0200
- X-ml-name: emacs-w3m
- X-mail-count: 12370
- References: <86a97xvd4v.fsf@xxxxxxxxxxxxxxxxxxxx> <878une21jz.fsf@xxxxxx> <b4mzjfu5pzg.fsf@xxxxxxx> <8638dlve9x.fsf@xxxxxxxxxxxxxxxxxxxx> <b4ma97thrbm.fsf@xxxxxxx> <86zjfs1ii9.fsf@xxxxxxxxxxxxxxxxxxxx> <b4mbns7sqew.fsf@xxxxxxx> <8761if3w8p.fsf@xxxxxx> <b4md2cmulqn.fsf@xxxxxxx>
Katsumi Yamaoka <yamaoka@xxxxxxx> writes:
> I tried to use `minibuffer-default-add-function' first, but
> failed. The custom function set to it didn't seem to be called.
> What I did was:
>
> (defun w3m-input-url-default-add-completions ()
> "Use the current url string (if any) as the next history by default.
> This function is used as `minibuffer-default-add-function'."
> (w3m-static-when (fboundp 'minibuffer-default-add-completions)
> (let ((minibuffer-default
> (or (with-current-buffer
> (window-buffer (minibuffer-selected-window))
> (or (w3m-active-region-or-url-at-point) w3m-current-url))
> minibuffer-default)))
> (minibuffer-default-add-completions))))
It actually is called, but I think it is just written in an illegitimate
way and doesn't work correctly.
You must not shadow the variable `minibuffer-default', because it is
already bound to the DEFAULT-VALUE argument of `read-from-minibuffer,
e.g. "about:". Rebinding this variable obviously confuses Emacs. Here
is a version that works for me:
--8<---------------cut here---------------start------------->8---
(defun w3m-input-url-default-add-completions ()
"Use the current url string (if any) as the next history by default.
This function is used as `minibuffer-default-add-function'."
(w3m-static-when (fboundp 'minibuffer-default-add-completions)
(let ((to-add (with-current-buffer
(window-buffer (minibuffer-selected-window))
(or (w3m-active-region-or-url-at-point) w3m-current-url)))
(def minibuffer-default)
(all (all-completions ""
minibuffer-completion-table
minibuffer-completion-predicate))
(listify (lambda (thing) (if (listp thing) thing (list thing)))))
(append (funcall listify def)
(funcall listify to-add)
all))))
--8<---------------cut here---------------end--------------->8---
There is probably no sane solution that calls
`minibuffer-default-add-completions' and avoids code duplication.
Note that in the list returned by
`w3m-input-url-default-add-completions' the current value of
`minibuffer-default' must be the first element; else, the thing doesn't
work.
So, if you want the current url to be the first candidate when hitting
M-n, you must make it the DEFAULT-VALUE of `read-from-minibuffer'.
> (defun w3m-input-url (...)
That part should be ok.
BTW, which Emacs versions do we need to support? Because, starting with
Emacs 23, the DEFAULT-VALUE argument of `read-from-minibuffer' is
allowed to be a list of several defaults. When we would use this
feature, everything would become trivially simple.
Regards,
Michael.