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

Re: `g' and `G' do not provide current url as the initial minibuffer contents

In [emacs-w3m : No.12367]
	On Wed, 30 Jul 2014 13:46:14 +0200, Michael Heerdegen wrote:
> But sadly, it doesn't work with helm-mode - M-n is also bound in
> helm-map, so your M-n binding is shadowed.

> Is there a reason why you prefer rebinding M-n over using
> `minibuffer-default-add-function' (which is intended for use cases
> exactly like this one)?

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:

--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 ((minibuffer-default
	   (or (with-current-buffer
		   (window-buffer (minibuffer-selected-window))
		 (or (w3m-active-region-or-url-at-point) w3m-current-url))

(defun w3m-input-url (...)
  (setq url (let ((minibuffer-setup-hook
		   (append minibuffer-setup-hook
			   (list (lambda ()
				   (if (looking-at "[a-z]+:\\(?:/+\\)?")
				       (goto-char (match-end 0)))))))
	      (read-from-minibuffer ...)
--8<---------------cut here---------------end--------------->8---

Do you see what I missed?


P.S. My Cygwin is being in semi-malfunction since yesterday;
  some commands don't work properly (Emacs is not an exception).
  So, I'll focus on restoring the system for a while...