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

w3m-next-form|w3m-previous-form



大和です。

web page内のlinkやformの個所に迅速に移動したい場合が多々あります。
linkについてはmigemoのおかげで極めて迅速移動できて快適なのですが、
text fieldなどのformについては、migemoによる検索で移動したくても、
そこに検索する文字列が存在しないので移動できません。"[ "を検索文
字列に使えなくはないですが、実際にtext fieldに入力するには、移動
したのちReturnを2回押す必要があります。

そこで、w3m-next-anchor/w3m-previous-anchorがanchorの間を移動でき
るようにformだけを移動できるコマンドを作ってみました。「作た」とい
う程ではないですが。
下記のパッチを適用して
 "]" を押すとポイントよりも先にあるフォームへ移動します。
 "[" を押すとポイントよりも前にあるフォームへ移動します。

; w3m-goto-anchor-histの使い方が間違っているかもしれません。
どんなもんでしょうか。

Index: w3m.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m.el,v
retrieving revision 1.503
diff -u -r1.503 w3m.el
--- w3m.el	2001/11/18 06:31:59	1.503
+++ w3m.el	2001/11/18 12:18:15
@@ -3399,7 +3399,79 @@
 		    w3m-goto-anchor-hist))))
     (w3m-print-this-url)))
 
+(defun w3m-goto-next-form ()
+  ;; move to the end of the current form
+  (when (w3m-action (point))
+    (goto-char (next-single-property-change (point) 'w3m-action)))
+  ;; find the next form
+  (or (w3m-action (point))
+      (let ((pos (next-single-property-change (point) 'w3m-action)))
+	(when pos
+	  (goto-char pos)
+	  t))))
 
+(defun w3m-next-form (&optional arg)
+  "Move cursor to the next form."
+  (interactive "p")
+  (unless arg (setq arg 1))
+  (if (null (memq last-command '(w3m-next-form w3m-previous-form)))
+      (setq w3m-goto-anchor-hist
+	    (list (get-text-property (point) 'w3m-action)))
+    (if (eq last-command 'w3m-previous-form)
+	(setq w3m-goto-anchor-hist (list (car w3m-goto-anchor-hist)))))
+  (if (< arg 0)
+      (w3m-previous-form (- arg))
+    (while (> arg 0)
+      (unless (w3m-goto-next-form)
+	;; search from the beginning of the buffer
+	(setq w3m-goto-anchor-hist nil)
+	(goto-char (point-min))
+	(w3m-goto-next-form))
+      (setq arg (1- arg))
+      (if (member (w3m-action) w3m-goto-anchor-hist)
+	  (setq arg (1+ arg))
+	(setq w3m-goto-anchor-hist
+	      (cons (get-text-property (point) 'w3m-action)
+		    w3m-goto-anchor-hist))))
+    (w3m-print-this-url)))
+
+(defun w3m-goto-previous-form ()
+  ;; move to the beginning of the current form
+  (when (w3m-action (point))
+    (goto-char (previous-single-property-change (1+ (point))
+						'w3m-action)))
+  ;; find the previous form
+  (let ((pos (previous-single-property-change (point) 'w3m-action)))
+    (if pos
+	(goto-char
+	 (if (w3m-action pos) pos
+	   (previous-single-property-change pos 'w3m-action))))))
+
+(defun w3m-previous-form (&optional arg)
+  "Move cursor to the previous form."
+  (interactive "p")
+  (unless arg (setq arg 1))
+  (if (null (memq last-command '(w3m-next-form w3m-previous-form)))
+      (setq w3m-goto-anchor-hist
+	    (list (get-text-property (point) 'w3m-action)))
+    (if (eq last-command 'w3m-next-form)
+	(setq w3m-goto-anchor-hist (list (car w3m-goto-anchor-hist)))))
+  (if (< arg 0)
+      (w3m-next-form (- arg))
+    (while (> arg 0)
+      (unless (w3m-goto-previous-form)
+	;; search from the end of the buffer
+	(setq w3m-goto-anchor-hist nil)
+	(goto-char (point-max))
+	(w3m-goto-previous-form))
+      (setq arg (1- arg))
+      (if (member (w3m-action) w3m-goto-anchor-hist)
+	  (setq arg (1+ arg))
+	(setq w3m-goto-anchor-hist
+	      (cons (get-text-property (point) 'w3m-action)
+		    w3m-goto-anchor-hist))))
+    (w3m-print-this-url)))
+
 (defun w3m-copy-buffer (&optional buf newname and-pop empty)
   "Create a copy of the buffer BUF which defaults to the current buffer.
 If NEWNAME is nil, it defaults to the current buffer's name.
@@ -3548,6 +3620,8 @@
     (define-key map "\M-a" 'w3m-bookmark-add-this-url)
     (define-key map "a" 'w3m-bookmark-add-current-url)
     (define-key map "+" 'w3m-antenna-add-current-url)
+    (define-key map "]" 'w3m-next-form)
+    (define-key map "[" 'w3m-previous-form)
     (define-key map "H" 'w3m-gohome)
     (define-key map "A" 'w3m-antenna)
     (define-key map "W" 'w3m-weather)
@@ -3654,6 +3728,8 @@
     (define-key map "<" 'w3m-scroll-right)
     (define-key map "." 'beginning-of-buffer)
     (define-key map "^" 'w3m-view-parent-page)
+    (define-key map "]" 'w3m-next-form)
+    (define-key map "[" 'w3m-previous-form)
     (define-key map "\C-c\C-c" 'w3m-submit-form)
     (define-key map "\C-c\C-g" 'w3m-process-stop)
     (setq w3m-info-like-map map)))