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

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

[emacs-wiki-discuss] planner-bookmark.el


From: Dryice Liu
Subject: [emacs-wiki-discuss] planner-bookmark.el
Date: Thu, 16 Dec 2004 12:29:49 +0800
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (berkeley-unix)

Thanks Frederik for the great idea of integrating bookmark.el to
planner. The good thing is I only need to take care of the URL
handling, and bookmark.el will take care of the rest :)

Attached is the code. Note this is my second lisp (see, I'm growing :))
so welcome and comments :)

======================================================================
;;; planner-bookmark.el --- bookmark URL support for the Emacs planner
;;

;; Keywords: emacs planner bookmark remember note
;; Author: Dryice Liu <dryice AT liu DOT com DOT cn>
;; Description: use bookmark.el in Emacs planner

;; This file is not part of GNU Emacs.

;; Copyright (C) 2004 Dryice Dong Liu . All rights reserved.

;; This 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 2, or (at your option) any later
;; version.
;;
;; This 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., 59 Temple Place - Suite 330, Boston,
;; MA 02111-1307, USA.

;;; Commentary:
;;
;; Place planner-bookmark.el in your load path and add this to your .emacs:
;;
;;    (require 'planner-bookmark)
;;
;; Annotations will be of the form
;; [[bookmark://bookmark-name][bookmark-description]]
;; bookmark-description will use bookmark-annotation if available,
;; else bookmark-name will be used.
;;
;; Note this file advice `bookmark-set'. If you don't want to take a
;; note everytime you set a bookmark, set
;; `planner-bookmark-take-note-after-set-bookmark-flag' to nil

;;; CODE

(require 'planner)
(require 'bookmark)
(require 'remember)

;;; User variables

(defgroup planner-bookmark nil
  "Bookmark URL support for planner.el."
  :prefix "planner-timeclock-summary"
  :group 'planner)

(defcustom planner-bookmark-take-note-after-set-bookmark-flag
  t
  "Non-nil means popup a remember buffer to take note after set a new bookmark."
  :type 'boolean
  :group 'planner-bookmark)

;;;; User variables stop here

(defadvice bookmark-set (after planner-bookmark activate)
  "set a bookmark, and take a note of it if
`planner-bookmark-take-note-after-set-bookmark-flag' is set."
  (if planner-bookmark-take-note-after-set-bookmark-flag
      ;; bookmark can take us where we want. we don't need two URLs
      (let ((remember-annotation-functions nil))
        (remember (concat "\n\n" (planner-bookmark-make-url
                                  bookmark-current-bookmark))))))

;;;###autoload
(defun planner-bookmark-annotation-from-bookmark ()
  "If called from a bookmark buffer, return an annotation.
Suitable for use in `planner-annotation-functions'."
  (if (and (eq major-mode 'bookmark-bmenu-mode)
           (bookmark-bmenu-check-position))
      (planner-bookmark-make-url (bookmark-bmenu-bookmark))))

(defun planner-bookmark-make-url (bookmark-name)
  "make the bookmark URL by given bookmark-name."
  (let (bookmark-annotation)
    (setq bookmark-annotation (bookmark-get-annotation
                               bookmark-name))
    (if (and bookmark-annotation (string-equal bookmark-annotation ""))
        (setq bookmark-annotation nil))
    (concat "[[bookmark://" bookmark-name "][" 
            (if bookmark-annotation
                bookmark-annotation
              bookmark-name)
            "]]")))

;;;###autoload
(defun planner-bookmark-browse-url (url)
  "If this is a bookmark URL, jump to it."
  (when (string-match "^bookmark:/?/?\\(.+\\)" url)
    (bookmark-jump (match-string 1 url))
    t))

;;;###autoload
(defun planner-bookmark-resolve-url (id)
  "bookmark URL doesn't mean much when publishing, so just return nil."
          nil)

(planner-add-protocol "bookmark" 'planner-bookmark-browse-url 
'planner-bookmark-resolve-url)
(add-hook 'planner-annotation-functions 
'planner-bookmark-annotation-from-bookmark)
(custom-add-option 'planner-annotation-functions 
'planner-bookmark-annotation-from-bookmark)

(provide 'planner-bookmark)
======================================================================

-- 
Cheers,
Dryice

http://dryice.3322.org





reply via email to

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