]> code.delx.au - gnu-emacs/blobdiff - lisp/org/org-macs.el
Merge Org 7.9.3e (commit b07a9bb).
[gnu-emacs] / lisp / org / org-macs.el
index daeea715789e554ace29175b9f12f9e75a08bb45..ceee30601bdb310c513668e5f0d2fdc96a7d1993 100644 (file)
@@ -1,6 +1,6 @@
 ;;; org-macs.el --- Top-level definitions for Org-mode
 
-;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
+;; Copyright (C) 2004-2013 Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <carsten at orgmode dot org>
 ;; Keywords: outlines, hypermedia, calendar, wp
 
 (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))))
+      `(interactive-p)
+    (if (or (> emacs-major-version 23)
+           (and (>= emacs-major-version 23)
+                (>= emacs-minor-version 2)))
+       ;; defined with no argument in <=23.1
+       `(with-no-warnings (called-interactively-p ,kind))
+      `(interactive-p))))
 (def-edebug-spec org-called-interactively-p (&optional ("quote" symbolp)))
 
 (when (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))
-    (def-edebug-spec with-silent-modifications (body)))
+          (or (< emacs-major-version 23)
+              (and (= emacs-major-version 23)
+                   (< emacs-minor-version 2))))
+  (defmacro with-silent-modifications (&rest body)
+    `(org-unmodified ,@body))
+  (def-edebug-spec with-silent-modifications (body)))
 
 (defmacro org-bound-and-true-p (var)
   "Return the value of symbol VAR if it is bound, else nil."
@@ -92,7 +93,7 @@ Also, do not record undo information."
   `(set-buffer-modified-p
     (prog1 (buffer-modified-p)
       (let ((buffer-undo-list t)
-           before-change-functions after-change-functions)
+           (inhibit-modification-hooks t))
        ,@body))))
 (def-edebug-spec org-unmodified (body))
 
@@ -125,19 +126,28 @@ Also, do not record undo information."
         (org-move-to-column ,col)))))
 (def-edebug-spec org-preserve-lc (body))
 
+;; Copied from bookmark.el
+(defmacro org-with-buffer-modified-unmodified (&rest body)
+  "Run BODY while preserving the buffer's `buffer-modified-p' state."
+  (org-with-gensyms (was-modified)
+    `(let ((,was-modified (buffer-modified-p)))
+       (unwind-protect
+           (progn ,@body)
+         (set-buffer-modified-p ,was-modified)))))
+
 (defmacro org-without-partial-completion (&rest body)
   `(if (and (boundp 'partial-completion-mode)
            partial-completion-mode
            (fboundp 'partial-completion-mode))
-     (unwind-protect
-        (progn
-          (partial-completion-mode -1)
-          ,@body)
-       (partial-completion-mode 1))
+       (unwind-protect
+          (progn
+            (partial-completion-mode -1)
+            ,@body)
+        (partial-completion-mode 1))
      ,@body))
 (def-edebug-spec org-without-partial-completion (body))
 
-;; FIXME: Slated for removal. Current Org mode does not support Emacs < 22
+;; FIXME: Slated for removal.  Current Org mode does not support Emacs < 22
 (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
@@ -238,10 +248,15 @@ We use a macro so that the test can happen at compilation time."
        s)
     (match-string-no-properties num string)))
 
-(defsubst org-no-properties (s)
+(defsubst org-no-properties (s &optional restricted)
+  "Remove all text properties from string S.
+When RESTRICTED is non-nil, only remove the properties listed
+in `org-rm-props'."
   (if (fboundp 'set-text-properties)
       (set-text-properties 0 (length s) nil s)
-    (remove-text-properties 0 (length s) org-rm-props s))
+    (if restricted
+       (remove-text-properties 0 (length s) org-rm-props s)
+      (set-text-properties 0 (length s) nil s)))
   s)
 
 (defsubst org-get-alist-option (option key)
@@ -363,18 +378,19 @@ point nowhere."
 (def-edebug-spec org-save-outline-visibility (form body))
 
 (defmacro org-with-wide-buffer (&rest body)
- "Execute body while temporarily widening the buffer."
- `(save-excursion
-    (save-restriction
 "Execute body while temporarily widening the buffer."
 `(save-excursion
+     (save-restriction
        (widen)
        ,@body)))
 (def-edebug-spec org-with-wide-buffer (body))
 
 (defmacro org-with-limited-levels (&rest body)
   "Execute BODY with limited number of outline levels."
-  `(let* ((org-outline-regexp (org-get-limited-outline-regexp))
+  `(let* ((org-called-with-limited-levels t)
+         (org-outline-regexp (org-get-limited-outline-regexp))
          (outline-regexp org-outline-regexp)
-         (org-outline-regexp-at-bol (concat "^" org-outline-regexp)))
+         (org-outline-regexp-bol (concat "^" org-outline-regexp)))
      ,@body))
 (def-edebug-spec org-with-limited-levels (body))
 
@@ -384,14 +400,14 @@ point nowhere."
 (defun org-get-limited-outline-regexp ()
   "Return outline-regexp with limited number of levels.
 The number of levels is controlled by `org-inlinetask-min-level'"
-  (if (or (not (eq major-mode 'org-mode)) (not (featurep 'org-inlinetask)))
+  (if (or (not (derived-mode-p 'org-mode)) (not (featurep 'org-inlinetask)))
       org-outline-regexp
     (let* ((limit-level (1- org-inlinetask-min-level))
           (nstars (if org-odd-levels-only (1- (* limit-level 2)) limit-level)))
       (format "\\*\\{1,%d\\} " nstars))))
 
 (defun org-format-seconds (string seconds)
-  "Compatibility function replacing format-seconds"
+  "Compatibility function replacing format-seconds."
   (if (fboundp 'format-seconds)
       (format-seconds string seconds)
     (format-time-string string (seconds-to-time seconds))))
@@ -403,12 +419,12 @@ The number of levels is controlled by `org-inlinetask-min-level'"
 
 (defun org-make-parameter-alist (flat)
   "Return alist based on FLAT.
-FLAT is a list with alternating symbol names and values. The
+FLAT is a list with alternating symbol names and values.  The
 returned alist is a list of lists with the symbol name in car and
 the value in cdr."
   (when flat
     (cons (list (car flat) (cadr flat))
-         (org-make-parameter-alist (cddr flat)))))
+         (org-make-parameter-alist (cddr flat)))))
 
 (provide 'org-macs)