emacs-wiki-discuss
[Top][All Lists]
Advanced

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

[emacs-wiki-discuss] Re: webpages organize in planner?


From: Sacha Chua
Subject: [emacs-wiki-discuss] Re: webpages organize in planner?
Date: Fri, 08 Apr 2005 15:02:54 +0800
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/21.3.50 (gnu/linux)

<address@hidden> writes:

> I use sacha's sacha/w3m-mirror-current-page in w3m-config.el to mirror
> webpages.  What I want is to add two link in a note, like this:

Oooh, that one! I nearly forgot about that! =)

Add the following code to your ~/.emacs or planner configuration and
set the value of sacha/w3m-mirror-directory. I set mine to
"/home/sacha/notebook/mirrors". Then evaluate the code. You can mirror
a page by calling sacha/w3m-mirror-current-page (I bind this to ! in
my w3m-config). You can then create tasks and notes based on it.

Seems to work with browse-url set to Mozilla over here... For w3m,
though, you may end up having to specify the MIME type (text/html).
Also, it doesn't guess index page filenames properly, so you may have
to select them from the directory. Does anyone know a way around these
issues?

Anyway, it mostly works. =)

----------------------------------------------------------------
(defvar sacha/w3m-mirror-directory nil "*Directory where my files are 
mirrored.")

(defun sacha/w3m-mirror-current-page (url &optional recursive)
  "Download specified URL to my mirrors directory.
If called interactively, mirrors current page.
If prefix argument RECURSIVE is non-nil, recurse into subdirectories."
  (interactive (list w3m-current-url current-prefix-arg))
  (with-temp-buffer
    (message "Getting %s" url)
    (cd sacha/w3m-mirror-directory)
    (apply 'start-process "wget"
           (format "*wget %s*" w3m-current-url)
           "wget"
           "--non-verbose"
           "-x"
           "--random-wait"
           "-k"
           "-p"
           url
           (if recursive
               (list "-r" "--no-parent" "-N" "-nw")))))

(defun sacha/planner-w3m-annotation-from-mirror ()
  "Return an annotation to a mirror, if it exists."
  (when (and sacha/w3m-mirror-directory
             (eq major-mode 'w3m-mode))
    (let ((url w3m-current-url)
          file
          escaped)
      (when (string-match "^\\([^:]+\\):[^/]*//" url)
        (setq file (substring url (match-end 0)))
        (setq url (replace-match "mirror://" nil t url)))
      (if (file-exists-p
           (expand-file-name file sacha/w3m-mirror-directory))
          (concat (planner-make-link w3m-current-url w3m-current-title t)
                  " "
                  (planner-make-link url "mirror" t))
        (planner-make-link w3m-current-url w3m-current-title t)))))

(defun sacha/planner-w3m-mirror-browse-url (url)
  "Browse to the mirrored URL."
  (when (string-match "^mirror://" url)
    (setq url (replace-match
               (concat "file://"
                       (file-name-as-directory
                        (expand-file-name sacha/w3m-mirror-directory)))
               nil t url))
    (setq url (emacs-wiki-replace-regexp-in-string "\\?" "%3F" url))
    (let ((w3m-local-find-file-function nil))
      (browse-url url))))

(add-to-list 'planner-annotation-functions 
'sacha/planner-w3m-annotation-from-mirror)
(planner-add-protocol "mirror" 'sacha/planner-w3m-mirror-browse-url nil)
      
-- 
Sacha Chua <address@hidden> - open source geekette
http://sacha.free.net.ph/ - PGP Key ID: 0xE7FDF77C
interests: emacs, gnu/linux, personal information management, CS ed
sachac on irc.freenode.net#emacs . YM: sachachua83




reply via email to

[Prev in Thread] Current Thread [Next in Thread]