From mboxrd@z Thu Jan 1 00:00:00 1970 From: Richard Riley Subject: Re: w3m integration for yanking w3m buffers into org Date: Fri, 10 Oct 2008 16:44:00 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KoJEd-0002sy-Mx for emacs-orgmode@gnu.org; Fri, 10 Oct 2008 10:44:55 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KoJEb-0002s7-JF for emacs-orgmode@gnu.org; Fri, 10 Oct 2008 10:44:53 -0400 Received: from [199.232.76.173] (port=37599 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KoJEb-0002s0-85 for emacs-orgmode@gnu.org; Fri, 10 Oct 2008 10:44:53 -0400 Received: from main.gmane.org ([80.91.229.2]:41908 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KoJEa-0007bo-Dh for emacs-orgmode@gnu.org; Fri, 10 Oct 2008 10:44:52 -0400 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1KoJEX-00016S-MZ for emacs-orgmode@gnu.org; Fri, 10 Oct 2008 14:44:49 +0000 Received: from f054125067.adsl.alicedsl.de ([78.54.125.67]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 10 Oct 2008 14:44:49 +0000 Received: from rileyrgdev by f054125067.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 10 Oct 2008 14:44:49 +0000 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Richard Riley writes: > I'm not fully aware of the steps needed to integrate new stuff but for > those using gnus and w3m to read html emails or newsletters then the > following code might interest you for saving portions into org > tasks/items. Let me know if there are any issues - it works well for me! > > I have the first code saved as manatee.el and "require" it in. A small follow up to this, possibly related to using emacs 23 I dont know, but I had some load order issues with the keybinding for the w3m buffer. The following solved it: ,---- | (eval-after-load "w3m" '(load "manatee")) `---- Where "manatee" is the code below. ,---- | ;; Code to integrate the w3m article buffer in gnus with org-mode. | ;; Kudos to Andy Stewart (ManateeLazyCat on #emacs IRC) for provding | ;; the code following a request. Can now paste w3m regions showing html | ;; emails and newsletters directly into org-mode buffers with the URLs | ;; transformed into org links. There is a default M-w key binding included. | ;; | ;; manatee.el for now prior to any integration. | ;; | ;; Oct 2008, rgr. | | (defun w3m-get-buffer-with-org-style () | "Get current buffer content with `org-mode' style. | This function will encode `link-title' and `link-location' with `org-make-link-string'. | And move buffer content to lastest of kill ring. | So you can yank in `org-mode' buffer to get `org-mode' style content." | (interactive) | (let (transform-start | transform-end | return-content | link-location | link-title) | (if mark-active | (progn | (setq transform-start (region-beginning)) | (setq transform-end (region-end)) | (deactivate-mark)) | (progn | (setq transform-start (point-min)) | (setq transform-end (point-max)))) | (message "Start transform link to `org-mode' style, please wait...") | (save-excursion | (goto-char transform-start) | ;; (goto-char (point-min)) | (while (and (< (point) transform-end) | (not (w3m-no-next-link-p))) ;if have next link in current buffer | (if (not (w3m-anchor (point))) ;don't move when current point have a valid url | ;; get content between two links. | (setq return-content (concat return-content (buffer-substring (point) (w3m-get-next-link-start))))) | ;; get link location at current point. | (setq link-location (w3m-anchor (point))) | ;; get link title at current point. | (setq link-title (buffer-substring (point) (w3m-get-anchor-end))) | ;; concat `org-mode' style url to `return-content'. | (setq return-content (concat return-content (org-make-link-string link-location link-title)))) | ;; concat rest context of current buffer | (setq return-content (concat return-content (buffer-substring (point) transform-end))) | (kill-new return-content) | (message "Transform link completed. You can get it from lastest kill ring.")))) | | (defun w3m-get-anchor-start () | "Move and return `point' for thst start of the current anchor." | (interactive) | (goto-char (or (previous-single-property-change (point) 'w3m-anchor-sequence) ;get start position of anchor | (point))) ;or current point | (point)) | | (defun w3m-get-anchor-end () | "Move and return `point' after the end of current anchor." | (interactive) | (goto-char (or (next-single-property-change (point) 'w3m-anchor-sequence) ;get end position of anchor | (point))) ;or current point | (point)) | | (defun w3m-get-next-link-start () | "Move and return `point' for that start of the current link." | (interactive) | (catch 'reach | (while (next-single-property-change (point) 'w3m-anchor-sequence) ;jump to next anchor | (goto-char (next-single-property-change (point) 'w3m-anchor-sequence)) | (when (w3m-anchor (point)) ;return point when current is valid link | (throw 'reach nil)))) | (point)) | | (defun w3m-get-prev-link-start () | "Move and return `point' for that end of the current link." | (interactive) | (catch 'reach | (while (previous-single-property-change (point) 'w3m-anchor-sequence) ;jump to previous anchor | (goto-char (previous-single-property-change (point) 'w3m-anchor-sequence)) | (when (w3m-anchor (point)) ;return point when current is valid link | (throw 'reach nil)))) | (point)) | | | (defun w3m-no-next-link-p () | "Return t if no next link after cursor. | Otherwise, return nil." | (save-excursion | (equal (point) (w3m-get-next-link-start)))) | | (defun w3m-no-prev-link-p () | "Return t if no prevoius link after cursor. | Otherwise, return nil." | (save-excursion | (equal (point) (w3m-get-prev-link-start)))) | | (define-key w3m-minor-mode-map (kbd "M-w") 'w3m-get-buffer-with-org-style) | | (provide 'manatee) `----