1;;; bookmark-w3m.el --- bridging between emacs's bookmark.el and emacs-w3m
2
3;; Copyright (C) 2010, 2019 Masatake YAMATO
4;;
5;; Author: Masatake YAMATO <yamato@redhat.com>
6;;
7
8;;; Commentary:
9;; From version 23.1 bookmark.el of GNU emacs supports the mode own
10;; bookmark mechanism.  This is w3m.el side adapter to the mechanism.
11;; This version of bookmark-w3m.el should work on Emacs 23 and greater.
12;;
13;; To enable the bookmark to work even when emacs-w3m is not loaded,
14;; add the following snippet to the ~/.emacs file:
15;;
16;; (require 'w3m-load)
17
18;;; About copyright:
19;; Most of all codes are derived from man.el of GNU Emacs.
20;; So the same license of man.el is applied to this software.
21;; =========================================================================
22;;; man.el --- browse UNIX manual pages -*- coding: iso-8859-1 -*-
23
24;; Copyright (C) 1993, 1994, 1996, 1997, 2001, 2002, 2003, 2004, 2005,
25;;   2006, 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
26
27;; Author: Barry A. Warsaw <bwarsaw@cen.com>
28;; Maintainer: FSF
29;; Keywords: help
30;; Adapted-By: ESR, pot
31
32;; This file is part of GNU Emacs.
33
34;; GNU Emacs is free software: you can redistribute it and/or modify
35;; it under the terms of the GNU General Public License as published by
36;; the Free Software Foundation, either version 3 of the License, or
37;; (at your option) any later version.
38
39;; GNU Emacs is distributed in the hope that it will be useful,
40;; but WITHOUT ANY WARRANTY; without even the implied warranty of
41;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
42;; GNU General Public License for more details.
43
44;; You should have received a copy of the GNU General Public License
45;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
46
47(defvar bookmark-make-record-function)
48(defvar w3m-current-title)
49(defvar w3m-current-url)
50
51(declare-function bookmark-default-handler "bookmark" (bmk-record))
52(declare-function bookmark-get-bookmark-record "bookmark" (bookmark))
53(declare-function bookmark-make-record-default
54		  "bookmark" (&optional no-file no-context posn))
55(declare-function bookmark-prop-get "bookmark" (bookmark prop))
56(declare-function w3m-goto-url
57		  "w3m" (url &optional reload charset post-data referer handler
58			     element background))
59
60(defun bookmark-w3m-bookmark-make-record ()
61  "Make a emacs bookmark entry for a w3m buffer."
62  `(,w3m-current-title
63    ,@(bookmark-make-record-default 'no-file)
64    (filename . ,w3m-current-url)
65    (url . ,w3m-current-url)
66    (handler . bookmark-w3m-bookmark-jump)))
67
68;;;###autoload
69(defun bookmark-w3m-bookmark-jump (bookmark)
70  "Default bookmark handler for w3m buffers."
71  (let ((w3m-async-exec nil))
72    (w3m-goto-url (bookmark-prop-get bookmark 'url))
73    (let ((buf (current-buffer)))
74      (bookmark-default-handler
75       `("" (buffer . ,buf) . ,(bookmark-get-bookmark-record bookmark))))))
76
77
78(defun bookmark-w3m-prepare ()
79  (interactive)
80  (set (make-local-variable 'bookmark-make-record-function)
81       'bookmark-w3m-bookmark-make-record))
82(add-hook 'w3m-mode-hook 'bookmark-w3m-prepare)
83
84(provide 'bookmark-w3m)
85
86;; bookmark-w3m.el ends here
87