Merge from emacs-23; up to 2010-06-16T23:27:20Z!jay.p.belanger@gmail.com.
[bpt/emacs.git] / lisp / org / org-id.el
index d16e5d8..b979097 100644 (file)
@@ -1,11 +1,11 @@
 ;;; org-id.el --- Global identifiers for Org-mode entries
 ;;
-;; Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+;; Copyright (C) 2008-2011 Free Software Foundation, Inc.
 ;;
 ;; Author: Carsten Dominik <carsten at orgmode dot org>
 ;; Keywords: outlines, hypermedia, calendar, wp
 ;; Homepage: http://orgmode.org
-;; Version: 7.01
+;; Version: 7.4
 ;;
 ;; This file is part of GNU Emacs.
 ;;
@@ -519,7 +519,8 @@ When CHECK is given, prepare detailed information about duplicate IDs."
     (puthash id (abbreviate-file-name file) org-id-locations)
     (add-to-list 'org-id-files (abbreviate-file-name file))))
 
-(add-hook 'kill-emacs-hook 'org-id-locations-save)
+(unless noninteractive
+  (add-hook 'kill-emacs-hook 'org-id-locations-save))
 
 (defun org-id-hash-to-alist (hash)
   "Turn an org-id hash into an alist, so that it can be written to a file."
@@ -596,18 +597,22 @@ optional argument MARKERP, return the position as a new marker."
 ;; Calling the following function is hard-coded into `org-store-link',
 ;; so we do have to add it to `org-store-link-functions'.
 
+;;;###autoload
 (defun org-id-store-link ()
   "Store a link to the current entry, using its ID."
   (interactive)
-  (let* ((link (org-make-link "id:" (org-id-get-create)))
-        (case-fold-search nil)
-        (desc (save-excursion
-                (org-back-to-heading t)
-                (or (and (looking-at org-complex-heading-regexp)
-                         (if (match-end 4) (match-string 4) (match-string 0)))
-                    link))))
-    (org-store-link-props :link link :description desc :type "id")
-    link))
+  (when (and (buffer-file-name (buffer-base-buffer)) (org-mode-p))
+    (let* ((link (org-make-link "id:" (org-id-get-create)))
+          (case-fold-search nil)
+          (desc (save-excursion
+                  (org-back-to-heading t)
+                  (or (and (looking-at org-complex-heading-regexp)
+                           (if (match-end 4)
+                               (match-string 4)
+                             (match-string 0)))
+                      link))))
+      (org-store-link-props :link link :description desc :type "id")
+      link)))
 
 (defun org-id-open (id)
   "Go to the entry with id ID."
@@ -638,6 +643,5 @@ optional argument MARKERP, return the position as a new marker."
 
 ;;; org-id.el ends here
 
-;; arch-tag: e5abaca4-e16f-4b25-832a-540cfb63a712