gnu-emacs-sources
[Top][All Lists]
Advanced

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

Bookmarks in doc-view -- dv-bmk.el


From: thorne
Subject: Bookmarks in doc-view -- dv-bmk.el
Date: Mon, 24 Dec 2007 01:41:57 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.50 (gnu/linux)

This should be taken mostly in the spirit of a feature request, though
for what it does, this works so far in my Emacs.

;;; dv-bkm.el --- primitive bookmarks for doc-view.el

;; Copyright (C) 2007 Evans Winner 

;; Author: Evans Winner <address@hidden>
;; Keywords: convenience

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.

;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.

;;; Commentary:

;; This implements a very quick and primitive bookmarking facility to
;; Tassilo Horn's `doc-view.el'.  This happens to be the one little
;; thing i needed to make doc-view a killer app for me.

;; This does not hook into Emacs' built-in bookmarking facility (which
;; would be nice, but is over my head).  You can not list bookmarks,
;; or edit them conveniently or jump to them from outside the file in
;; question.  (My hope is that this file may be useful--even more,
;; though, my hope is that a real lisp hacker will write a better
;; version i can use :-) )

;; What you can do is, after loading a .pdf or .ps file with doc-view,
;; use `b' to set a bookmark on the current page, or `j' to jump to a
;; set bookmark.

;; You can customize the name of the file used to save the bookmarks:
;; `doc-view-bookmark-file'.

;; To use, put it in your load-path and maybe do something like:

;; (add-hook 'doc-view-mode-hook (lambda () (load-library "dv-bmk")))

;;; Code:

(defcustom doc-view-bookmark-file "~/.doc-view.bmk"
  "*Default file name for the doc-view bookmark file."
  :type '(string)
  :group 'doc-view)

(defun doc-view-read-bookmarks ()
  "Load the contents of the doc-view bookmark file.
Return nil if the file cannot be loaded."
  (if (file-exists-p doc-view-bookmark-file)
      (load-file doc-view-bookmark-file) nil))

(defun doc-view-write-bookmarks ()
  "Save the doc-view bookmark variable."
(write-region
 (concat "\(setq doc-view-bookmarks \'"
         (prin1-to-string doc-view-bookmarks)
         "\)") t doc-view-bookmark-file))

(defun doc-view-bookmark-set ()
  "Set a doc-view bookmark for the current page."
  (interactive)
  (if (and (not (null 'doc-view-bookmarks))
           (boundp 'doc-view-bookmarks))
      (if (not (assoc buffer-file-name doc-view-bookmarks))
          (setq doc-view-bookmarks
                (acons buffer-file-name 
                       buffer-file-name doc-view-bookmarks))
        (setf (cdr (assoc buffer-file-name doc-view-bookmarks))
              doc-view-current-page))
    (setq doc-view-bookmarks
          `(,buffer-file-name
            ,doc-view-current-page)))
  (doc-view-write-bookmarks))

(defun doc-view-bookmark-jump ()
  "Jump to the saved doc-view bookmark for this file."
  (interactive)
  (doc-view-read-bookmarks)
  (doc-view-goto-page
   (or (cdr (assoc buffer-file-name doc-view-bookmarks)) 1)))

(define-key doc-view-mode-map (kbd "b") 'doc-view-bookmark-set)
(define-key doc-view-mode-map (kbd "j") 'doc-view-bookmark-jump)

(provide 'dv-bmk)
;;; dv-bmk.el ends here



reply via email to

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