(require 'w3) ;(defvar w3-edit-login-name "foo") ;(defvar w3-edit-your-site "www.foo.ac.jp") (defun w3-edit-document (arg) "Edit this document's source" (interactive "P") (if (or (not w3-edit-login-name) (not w3-edit-your-site)) (message "Set w3-edit-login-name and w3-edit-your-site") (let* ((obj url-current-object) (name w3-edit-login-name) (site w3-edit-your-site) (len (length name)) file) (cond ((equal (aref obj 0) "file") (find-file-other-window (aref obj 5))) ((and (equal (aref obj 0) "http") (equal (aref obj 3) site) (equal (substring (aref obj 5) 2 (+ 2 len)) name)) (setq file (concat "~/public_html" (substring (aref obj 5) (+ 2 len)))) (find-file-other-window file)) (t (message "Maybe you can not edit the source file.")))))) (defun w3-edit-document-at-point () "Edit source to the document pointed at by link under the point" (interactive) (let ((url (w3-view-this-url)) (length (length w3-edit-login-name)) fil file name) (if (not w3-edit-login-name) (message "Set w3-edit-login-name to your login-name string.") (cond ((if (not url) (message "No link found under the point."))) ((string-match "file:" url) (setq fil (substring url 5)) (if (string-match "\\([^#]+\\)#\\([^#]+\\)" fil) (setq name (match-string 2 fil) fil (match-string 1 fil))) (find-file-other-window fil) (if name (re-search-forward (concat "\\(NAME\\|name\\)=\"" name "\"") nil t))) ((string-match "^#\\([^#]+\\)" url) (setq file (aref url-current-object 5) name (match-string 1 url)) (find-file-other-window file) (re-search-forward (concat "\\(NAME\\|name\\)=\"" name "\"") nil t)) ((equal (substring fil 0 (+ 2 length)) (concat "/~" w3-edit-login-name)) (setq file (concat "~/public_html" (substring fil (+ 2 length)))) (find-file-other-window file)) (t (message "Maybe you can not edit the source file.")))))) ;;; w3-edit.el ends here.