Convert consecutive FSF copyright years to ranges.
[bpt/emacs.git] / lisp / org / org-macs.el
index 1f4ec10..7376682 100644 (file)
@@ -1,12 +1,12 @@
 ;;; org-macs.el --- Top-level definitions for Org-mode
 
-;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
+;; Copyright (C) 2004-2011
 ;;   Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <carsten at orgmode dot org>
 ;; Keywords: outlines, hypermedia, calendar, wp
 ;; Homepage: http://orgmode.org
-;; Version: 6.33c
+;; Version: 7.4
 ;;
 ;; This file is part of GNU Emacs.
 ;;
     (defmacro declare-function (fn file &optional arglist fileonly))))
 
 (declare-function org-add-props "org-compat" (string plist &rest props))
+(declare-function org-string-match-p "org-compat" (&rest args))
+
+(defmacro org-called-interactively-p (&optional kind)
+  `(if (featurep 'xemacs)
+       (interactive-p)
+     (if (or (> emacs-major-version 23)
+            (and (>= emacs-major-version 23)
+                 (>= emacs-minor-version 2)))
+        (with-no-warnings (called-interactively-p ,kind)) ;; defined with no argument in <=23.1
+       (interactive-p))))
+
+(if (and (not (fboundp 'with-silent-modifications))
+        (or (< emacs-major-version 23)
+            (and (= emacs-major-version 23)
+                 (< emacs-minor-version 2))))
+    (defmacro with-silent-modifications (&rest body)
+      `(org-unmodified ,@body)))
 
 (defmacro org-bound-and-true-p (var)
   "Return the value of symbol VAR if it is bound, else nil."
   `(and (boundp (quote ,var)) ,var))
 
+(defun org-string-nw-p (s)
+  "Is S a string with a non-white character?"
+  (and (stringp s)
+       (org-string-match-p "\\S-" s)
+       s))
+
+(defun org-not-nil (v)
+  "If V not nil, and also not the string \"nil\", then return V.
+Otherwise return nil."
+  (and v (not (equal v "nil")) v))
+
 (defmacro org-unmodified (&rest body)
   "Execute body without changing `buffer-modified-p'.
 Also, do not record undo information."
@@ -63,6 +91,8 @@ Also, do not record undo information."
            (setq ss (replace-match "a-zA-Z0-9" t t ss)))
          (while (string-match "\\[:alpha:\\]" ss)
            (setq ss (replace-match "a-zA-Z" t t ss)))
+         (while (string-match "\\[:punct:\\]" ss)
+           (setq ss (replace-match "\001-@[-`{-~" t t ss)))
          ss))
     s))
 
@@ -85,7 +115,7 @@ Also, do not record undo information."
 
 (defmacro org-maybe-intangible (props)
   "Add '(intangible t) to PROPS if Emacs version is earlier than Emacs 22.
-In emacs 21, invisible text is not avoided by the command loop, so the
+In Emacs 21, invisible text is not avoided by the command loop, so the
 intangible property is needed to make sure point skips this text.
 In Emacs 22, this is not necessary.  The intangible text property has
 led to problems with flyspell.  These problems are fixed in flyspell.el,
@@ -123,6 +153,14 @@ We use a macro so that the test can happen at compilation time."
      ,@body))
 (put 'org-if-unprotected-at 'lisp-indent-function 1)
 
+(defun org-re-search-forward-unprotected (&rest args)
+  "Like re-search-forward, but stop only in unprotected places."
+  (catch 'exit
+    (while t
+      (unless (apply 're-search-forward args)
+       (throw 'exit nil))
+      (unless (get-text-property (match-beginning 0) 'org-protected)
+       (throw 'exit (point))))))
 
 (defmacro org-with-remote-undo (_buffer &rest _body)
   "Execute BODY while recording undo information in two buffers."
@@ -152,7 +190,8 @@ We use a macro so that the test can happen at compilation time."
   `(let ((inhibit-read-only t)) ,@body))
 
 (defconst org-rm-props '(invisible t face t keymap t intangible t mouse-face t
-                                  rear-nonsticky t mouse-map t fontified t)
+                                  rear-nonsticky t mouse-map t fontified t
+                                  org-emphasis t)
   "Properties to remove when a string without properties is wanted.")
 
 (defsubst org-match-string-no-properties (num &optional string)
@@ -260,7 +299,6 @@ This is in contrast to merely setting it to 0."
       (setq plist (cddr plist)))
     p))
 
-
 (defun org-replace-match-keep-properties (newtext &optional fixedcase
                                                  literal string)
   "Like `replace-match', but add the text properties found original text."
@@ -268,6 +306,25 @@ This is in contrast to merely setting it to 0."
                                        (match-beginning 0) string)))
   (replace-match newtext fixedcase literal string))
 
+(defmacro org-save-outline-visibility (use-markers &rest body)
+  "Save and restore outline visibility around BODY.
+If USE-MARKERS is non-nil, use markers for the positions.
+This means that the buffer may change while running BODY,
+but it also means that the buffer should stay alive
+during the operation, because otherwise all these markers will
+point nowhere."
+  (declare (indent 1))
+  `(let ((data (org-outline-overlay-data ,use-markers)))
+     (unwind-protect
+        (progn
+          ,@body
+          (org-set-outline-overlay-data data))
+       (when ,use-markers
+        (mapc (lambda (c)
+                (and (markerp (car c)) (move-marker (car c) nil))
+                (and (markerp (cdr c)) (move-marker (cdr c) nil)))
+              data)))))
+
 (defmacro org-with-limited-levels (&rest body)
   "Execute BODY with limited number of outline levels."
   `(let* ((outline-regexp (org-get-limited-outline-regexp)))
@@ -277,7 +334,7 @@ This is in contrast to merely setting it to 0."
 (defvar org-inlinetask-min-level) ; defined in org-inlinetask.el
 (defun org-get-limited-outline-regexp ()
   "Return outline-regexp with limited number of levels.
-The number of levels is controlled by "
+The number of levels is controlled by `org-inlinetask-min-level'"
   (if (or (not (org-mode-p)) (not (featurep 'org-inlinetask)))
 
       outline-regexp
@@ -287,6 +344,5 @@ The number of levels is controlled by "
 
 (provide 'org-macs)
 
-;; arch-tag: 7e6a73ce-aac9-4fc0-9b30-ce6f89dc6668
 
 ;;; org-macs.el ends here