[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
download contents after submitting form
- From: Naohiro Aota <nao.aota@xxxxxxxxx>
- Date: Mon, 30 Jul 2007 22:57:09 +0900 (JST)
- X-ml-name: emacs-w3m
- X-mail-count: 09561
こんばんは、青田です。
formのsubmit先をdownloadできたら便利(パスワードつきのダウンロードなど)ではないかな
と思いパッチを書いてみました。
- w3m-form-new-sessionと同様にw3m-form-downloadという変数を追加
- w3m-download-this-urlでw3m-form-downloadをtに拘束してw3m-form-submitを呼び出し
-- 一応、w3m-view-this-url、w3m-submit-formでw3m-form-downloadをnilに拘束(不必要?)
- w3m-form-downloadがtならw3m-form-submitからw3m-downloadを呼び出し
- POSTメソッドに対応するためw3m-downloadにpost-dataという引数を追加
というふうにしています。
;; ところで、2007-07-23のChangeLogのw3m-session-selecはtypoではないでしょうか?
Index: ChangeLog
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/ChangeLog,v
retrieving revision 1.3029
diff -u -r1.3029 ChangeLog
--- ChangeLog 30 Jul 2007 02:06:13 -0000 1.3029
+++ ChangeLog 30 Jul 2007 13:48:33 -0000
@@ -1,3 +1,17 @@
+2007-07-30 Naohiro Aota <nao.aota@xxxxxxxxx>
+
+ * w3m-form.el: Changes to download contents after submitting form.
+ (w3m-form-download): New variable.
+ (w3m-fontify-textareas, w3m-form-parse-and-fontify): Combine the above
+ variable into expressions which represent form actions.
+ (w3m-form-submit): Accept and optional argument `download'.
+
+ * w3m.el: Changes to download contents after submitting form.
+ (w3m-download): Accept and optional argument `post-data'.
+ (w3m-download-this-url): `w3m-form-download' is binded locally.
+ (w3m-view-this-url): Ditto.
+ (w3m-submit-form): Ditto.
+
2007-07-30 Katsumi Yamaoka <yamaoka@xxxxxxx>
* w3m-ucs.el (font-ccl-encoder-alist): Bind it for XEmacs 21.5.
Index: w3m-form.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m-form.el,v
retrieving revision 1.161
diff -u -r1.161 w3m-form.el
--- w3m-form.el 17 Jul 2007 22:46:35 -0000 1.161
+++ w3m-form.el 30 Jul 2007 13:48:41 -0000
@@ -155,6 +155,10 @@
"Specify non-nil value to create a new session after sending form.
It is useful to bind this variable with `let', but do not set it globally.")
+(defvar w3m-form-download nil
+ "Specify non-nil value to download contents after sending form.
+It is useful to bind this variable with `let', but do not set it globally.")
+
;;; w3m-form structure:
(defsubst w3m-form-normalize-action (action url)
@@ -565,7 +569,8 @@
w3m-action (w3m-form-input-textarea ,form ,hseq)
w3m-submit (w3m-form-submit ,form ,id ,name
(w3m-form-get ,form ,id)
- w3m-form-new-session)
+ w3m-form-new-session
+ w3m-form-download)
w3m-form-hseq ,hseq
w3m-anchor-sequence ,abs-hseq
w3m-form-id ,id
@@ -706,10 +711,12 @@
`(w3m-form-field-id
,(format "fid=%d/type=%s/name=%s/id=%d" fid type name id)
w3m-action (w3m-form-submit ,form ,id ,name ,value
- w3m-form-new-session)
+ w3m-form-new-session
+ w3m-form-download)
w3m-submit (w3m-form-submit ,form ,id ,name
(w3m-form-get ,form ,id)
- w3m-form-new-session)
+ w3m-form-new-session
+ w3m-form-download)
w3m-anchor-sequence ,abs-hseq))))
((string= type "reset")
(w3m-form-make-button
@@ -745,7 +752,8 @@
w3m-action (w3m-form-input-textarea ,form ,hseq)
w3m-submit (w3m-form-submit ,form ,id ,name
(w3m-form-get ,form ,id)
- w3m-form-new-session)
+ w3m-form-new-session
+ w3m-form-download)
w3m-textarea-rows ,rows
w3m-form-hseq ,hseq
w3m-anchor-sequence ,abs-hseq
@@ -768,7 +776,8 @@
w3m-action (w3m-form-input-select ,form ,id ,name)
w3m-submit (w3m-form-submit ,form ,id ,name
(w3m-form-get ,form ,id)
- w3m-form-new-session)
+ w3m-form-new-session
+ w3m-form-download)
w3m-anchor-sequence ,abs-hseq))))
((string= type "password")
(w3m-add-face-property start end 'w3m-form)
@@ -779,7 +788,8 @@
w3m-action (w3m-form-input-password ,form ,id ,name)
w3m-submit (w3m-form-submit ,form ,id ,name
(w3m-form-get ,form ,id)
- w3m-form-new-session)
+ w3m-form-new-session
+ w3m-form-download)
w3m-anchor-sequence ,abs-hseq)))
((string= type "checkbox")
(let ((cvalue (w3m-form-get form id)))
@@ -795,7 +805,8 @@
w3m-action (w3m-form-input-checkbox ,form ,id ,name ,value)
w3m-submit (w3m-form-submit ,form ,id ,name
(w3m-form-get ,form ,id)
- w3m-form-new-session)
+ w3m-form-new-session
+ w3m-form-download)
w3m-anchor-sequence ,abs-hseq)))
((string= type "radio")
;; Radio button input, one name has one value
@@ -809,7 +820,8 @@
w3m-action (w3m-form-input-radio ,form ,id ,name ,value)
w3m-submit (w3m-form-submit ,form ,id ,name
(w3m-form-get-by-name ,form ,name)
- w3m-form-new-session)
+ w3m-form-new-session
+ w3m-form-download)
w3m-anchor-sequence ,abs-hseq)))
((string= type "file")
(w3m-add-face-property start end 'w3m-form)
@@ -820,7 +832,8 @@
w3m-action (w3m-form-input-file ,form ,id ,name ,value)
w3m-submit (w3m-form-submit ,form ,id ,name
(w3m-form-get ,form ,id)
- w3m-form-new-session)
+ w3m-form-new-session
+ w3m-form-download)
w3m-anchor-sequence ,abs-hseq)))
(t
(w3m-form-put form
@@ -836,7 +849,8 @@
,width ,maxlength ,value)
w3m-submit (w3m-form-submit ,form ,id ,name
(w3m-form-get ,form ,id)
- w3m-form-new-session)
+ w3m-form-new-session
+ w3m-form-download)
w3m-anchor-sequence ,abs-hseq)))))))))
;; Process <internal> tag.
(when (search-forward "<internal>" nil t)
@@ -1733,7 +1747,7 @@
(setq files (cons file files))))
files)))
-(defun w3m-form-submit (form &optional id name value new-session)
+(defun w3m-form-submit (form &optional id name value new-session download)
(if (w3m-anchor (point))
;; cf SA17565
(w3m-goto-url (w3m-anchor (point)))
@@ -1758,16 +1772,22 @@
;; we use the `post' method according to the proposal
;; of RFC2070.
(eq 'multipart/form-data (w3m-form-enctype form)))
- (funcall (if new-session
- 'w3m-goto-url-new-session
- 'w3m-goto-url)
- url 'reload nil
- (w3m-form-make-form-data form)
- w3m-current-url))
+ (if download
+ (funcall 'w3m-download
+ url nil nil nil
+ (w3m-form-make-form-data form))
+ (funcall (if new-session
+ 'w3m-goto-url-new-session
+ 'w3m-goto-url)
+ url 'reload nil
+ (w3m-form-make-form-data form)
+ w3m-current-url)))
((eq 'get (w3m-form-method form))
- (funcall (if new-session
- 'w3m-goto-url-new-session
- 'w3m-goto-url)
+ (funcall (if download
+ 'w3m-download
+ (if new-session
+ 'w3m-goto-url-new-session
+ 'w3m-goto-url))
(concat url "?" (w3m-form-make-form-data form))))
(t
(w3m-message "This form's method has not been supported: %s"
Index: w3m.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m.el,v
retrieving revision 1.1291
diff -u -r1.1291 w3m.el
--- w3m.el 26 Jul 2007 07:28:06 -0000 1.1291
+++ w3m.el 30 Jul 2007 13:49:08 -0000
@@ -5251,7 +5251,7 @@
file)))))))
;;;###autoload
-(defun w3m-download (url &optional filename no-cache handler)
+(defun w3m-download (url &optional filename no-cache handler post-data)
(interactive
(let* ((url (w3m-input-url "Download URL (default HOME): "
(when (stringp w3m-current-url)
@@ -5279,7 +5279,7 @@
(type (progn
(w3m-clear-local-variables)
(setq w3m-current-url url)
- (w3m-retrieve url t no-cache nil nil handler)))
+ (w3m-retrieve url t no-cache post-data nil handler)))
(if type
(let ((buffer-file-coding-system 'binary)
(coding-system-for-write 'binary)
@@ -6109,7 +6109,8 @@
act url)
(cond
((setq act (w3m-action))
- (let ((w3m-form-new-session new-session))
+ (let ((w3m-form-new-session new-session)
+ (w3m-form-download nil))
(eval act)))
((setq url (w3m-url-valid (w3m-anchor)))
(w3m-view-this-url-1 url arg new-session))
@@ -6192,7 +6193,8 @@
(if (and submit
w3m-current-url
(w3m-url-valid w3m-current-url))
- (let ((w3m-form-new-session new-session))
+ (let ((w3m-form-new-session new-session)
+ (w3m-form-download nil))
(eval submit))
(w3m-message "Can't submit form at this point"))))
@@ -6326,21 +6328,26 @@
(defun w3m-download-this-url ()
"Download the file or the page pointed to by the link under point."
(interactive)
- (let ((url (or (w3m-anchor) (w3m-image))))
- (if (w3m-url-valid url)
- (lexical-let ((pos (point-marker))
- (curl w3m-current-url))
- (w3m-process-with-null-handler
- (w3m-process-do
- (success (w3m-download url nil nil handler))
- (and success
- (buffer-name (marker-buffer pos))
- (save-excursion
- (set-buffer (marker-buffer pos))
- (when (equal curl w3m-current-url)
- (goto-char pos)
- (w3m-refontify-anchor)))))))
- (w3m-message "No URL at point"))))
+ (let ((url (or (w3m-anchor) (w3m-image))) act)
+ (cond
+ ((w3m-url-valid url)
+ (lexical-let ((pos (point-marker))
+ (curl w3m-current-url))
+ (w3m-process-with-null-handler
+ (w3m-process-do
+ (success (w3m-download url nil nil handler))
+ (and success
+ (buffer-name (marker-buffer pos))
+ (save-excursion
+ (set-buffer (marker-buffer pos))
+ (when (equal curl w3m-current-url)
+ (goto-char pos)
+ (w3m-refontify-anchor))))))))
+ ((setq act (w3m-action))
+ (let ((w3m-form-download t))
+ (eval act)))
+ (t
+ (w3m-message "No URL at point")))))
(defun w3m-print-current-url ()
"Display the current url in the echo area and put it into `kill-ring'."