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

Re: move to next/previous submit button



From: jidanni@xxxxxxxxxxx
Subject: Re: [emacs-w3m:10518] move to next/previous submit button
Date: Tue, 09 Dec 2008 01:38:40 +0800

>>> Gentlemen, I am unhappy with (info "(emacs-w3m)Moving in a page") >>> .
>>> E.g., I am on
>>> http://radioscanningtw.jidanni.org/index.php?title=%E5%98%89%E7%B >>> E%A9%E7%B8%A3%E6%B6%88%E9%98%B2%E5%B1%80&action=history
>>> and I want to go to the form submit button, but
>>> ] runs the command w3m-next-form
>>> insists on first taking be to each ( ) and (*) checkbox along the
>>> way.
>>> Hmm, maybe deploy
>>> ) is undefined
>>> as a new command, but that needs a SHIFT. Yuck...
>
> NA> How about trying w3m-submit-form() (bounded to C-c C-c, by defa > ult).
> NA> This function submit the current form.
>
> I'm sorry, I don't necessarily want to submit the form. I just want > to
> jump to the next button.

OK. Now, I understand.

> The problem appears to be that emacs-w3m should have different
> commands to distinguish jumping to
> <input type="submit"> vs. <input type="radio">.
> Here I just want to jump to the next of the former, jumping over an > y
> of the latter.
>
> (Indeed, maybe also have an extra command to jump to only "checked" > or
> "unchecked" radio boxes too.)

Maybe you can do what you want by the following.

(defun w3m-goto-form-with-type-sub (type f)
  (let ((current (point))
	(moved (list (point)))
	(regexp (format "/type=%s/" type)))
    (unless (catch 'loop
	      (while t
		(funcall f)
		(let ((p (point))
		      field)
		  (if (memq p moved)
		      (throw 'loop nil)
		    (if (and (setq field (get-text-property p
'w3m-form -field-id))
			     (string-match regexp
					   field))
			(throw 'loop p)
		      (setq moved (cons p moved)))))))
      (goto-char current))
    (or (w3m-print-this-url)
	(w3m-message ""))))

(defvar w3m-form-types
  '("submit" "image" "reset" "hidden" "password"
    "radio" "checkbox" "select" "textarea" "file" "text"))

(defun w3m-next-form-with-type (&optional type)
  (interactive)
  (w3m-goto-form-with-type-sub (or type
(completing-read "type: " w3m-form -types))
			       'w3m-next-form))

(defun w3m-previous-form-with-type (&optional type)
  (interactive)
  (w3m-goto-form-with-type-sub (or type
(completing-read "type: " w3m-form -types))
			       'w3m-previous-form))

(defun w3m-next-submit ()
  (interactive)
  (w3m-next-form-with-type "submit"))

(defun w3m-previous-submit ()
  (interactive)
  (w3m-previous-form-with-type "submit"))

;; or more hacking solution
;; (defalias 'w3m-next-submit 'widget-forward)
;; (defalias 'w3m-previous-submit 'widget-backward)

とりあえず type を指定して form を移動できる関数を書いてみたけれど、
CVS にもいれておくべきでしょうか…? どうにも実装がいまいちな気がするう
えに、 C-u なんかをとれないのが…。

Regards,