]> code.delx.au - gnu-emacs/blobdiff - lisp/org/org-remember.el
Revert last change to org-lparse.el
[gnu-emacs] / lisp / org / org-remember.el
index fd3064a709c059bb433b9c2de2012d5ee6f2b68e..dd493749295f4380045e2d5e97c1ed145caae365 100644 (file)
@@ -1,11 +1,10 @@
 ;;; org-remember.el --- Fast note taking in Org-mode
 
-;; Copyright (C) 2004-201 Free Software Foundation, Inc.
+;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <carsten at orgmode dot org>
 ;; Keywords: outlines, hypermedia, calendar, wp
 ;; Homepage: http://orgmode.org
-;; Version: 7.4
 ;;
 ;; This file is part of GNU Emacs.
 ;;
 (eval-when-compile
   (require 'cl))
 (require 'org)
+(require 'org-compat)
 (require 'org-datetree)
 
 (declare-function remember-mode "remember" ())
 (declare-function remember "remember" (&optional initial))
 (declare-function remember-buffer-desc "remember" ())
 (declare-function remember-finalize "remember" ())
+(declare-function org-pop-to-buffer-same-window
+                 "org-compat" (&optional buffer-or-name norecord label))
+
 (defvar remember-save-after-remembering)
 (defvar remember-register)
 (defvar remember-buffer)
@@ -61,7 +64,7 @@ and `org-remember-default-headline'.  To force prompting anyway, use
 \\[universal-argument] \\[org-remember-finalize] to file the note.
 
 When this variable is nil, \\[org-remember-finalize] gives you the prompts, and
-\\[universal-argument] \\[org-remember-finalize] triggers the fasttrack."
+\\[universal-argument] \\[org-remember-finalize] triggers the fast track."
   :group 'org-remember
   :type 'boolean)
 
@@ -186,22 +189,22 @@ calendar           |  %:type %:date"
                (character :tag "Selection Key")
                (string :tag "Template")
                (choice :tag "Destination file"
-                (file :tag "Specify")
-                (function :tag "Function")
-                (const :tag "Use `org-default-notes-file'" nil))
+                       (file :tag "Specify")
+                       (function :tag "Function")
+                       (const :tag "Use `org-default-notes-file'" nil))
                (choice :tag "Destin. headline"
-                (string :tag "Specify")
-                (function :tag "Function")
-                (const :tag "Use `org-remember-default-headline'" nil)
-                (const :tag "At beginning of file" top)
-                (const :tag "At end of file" bottom)
-                (const :tag "In a date tree" date-tree))
+                       (string :tag "Specify")
+                       (function :tag "Function")
+                       (const :tag "Use `org-remember-default-headline'" nil)
+                       (const :tag "At beginning of file" top)
+                       (const :tag "At end of file" bottom)
+                       (const :tag "In a date tree" date-tree))
                (choice :tag "Context"
-                (const :tag "Use in all contexts" nil)
-                (const :tag "Use in all contexts" t)
-                (repeat :tag "Use only if in major mode"
-                        (symbol :tag "Major mode"))
-                (function :tag "Perform a check against function")))))
+                       (const :tag "Use in all contexts" nil)
+                       (const :tag "Use in all contexts" t)
+                       (repeat :tag "Use only if in major mode"
+                               (symbol :tag "Major mode"))
+                       (function :tag "Perform a check against function")))))
 
 (defcustom org-remember-delete-empty-lines-at-end t
   "Non-nil means clean up final empty lines in remember buffer."
@@ -214,11 +217,7 @@ The remember buffer is still current when this hook runs."
   :group 'org-remember
   :type 'hook)
 
-(defvar org-remember-mode-map
-  (let ((map (make-sparse-keymap)))
-    (define-key map "\C-c\C-c" 'org-remember-finalize)
-    (define-key map "\C-c\C-k" 'org-remember-kill)
-    map)
+(defvar org-remember-mode-map (make-sparse-keymap)
   "Keymap for `org-remember-mode', a minor mode.
 Use this map to set additional keybindings for when Org-mode is used
 for a Remember buffer.")
@@ -227,7 +226,10 @@ for a Remember buffer.")
 
 (define-minor-mode org-remember-mode
   "Minor mode for special key bindings in a remember buffer."
-  nil " Rem" org-remember-mode-map)
+  nil " Rem" org-remember-mode-map
+  (run-hooks 'org-remember-mode-hook))
+(define-key org-remember-mode-map "\C-c\C-c" 'org-remember-finalize)
+(define-key org-remember-mode-map "\C-c\C-k" 'org-remember-kill)
 
 (defcustom org-remember-clock-out-on-exit 'query
   "Non-nil means stop the clock when exiting a clocking remember buffer.
@@ -275,9 +277,6 @@ opposite case, the default, t, is more useful."
   :group 'org-remember
   :type 'boolean)
 
-(defvar annotation) ; from remember.el, dynamically scoped in `remember-mode'
-(defvar initial)    ; from remember.el, dynamically scoped in `remember-mode'
-
 ;;;###autoload
 (defun org-remember-insinuate ()
   "Setup remember.el for use with Org-mode."
@@ -295,7 +294,7 @@ conventions in Org-mode.  This function returns such a link."
   (org-store-link nil))
 
 (defconst org-remember-help
-"Select a destination location for the note.
+  "Select a destination location for the note.
 UP/DOWN=headline   TAB=cycle visibility  [Q]uit   RET/<left>/<right>=Store
 RET on headline   -> Store as sublevel entry to current headline
 RET at beg-of-buf -> Append to file as level 2 headline
@@ -399,8 +398,7 @@ RET at beg-of-buf -> Append to file as level 2 headline
 This function should be placed into `remember-mode-hook' and in fact requires
 to be run from that hook to function properly."
   (when (and (boundp 'initial) (stringp initial))
-    (setq initial (org-no-properties initial))
-    (remove-text-properties 0 (length initial) '(read-only t) initial))
+    (setq initial (org-no-properties initial)))
   (if org-remember-templates
       (let* ((entry (org-select-remember-template use-char))
             (ct (or org-overriding-default-time (org-current-time)))
@@ -429,10 +427,10 @@ to be run from that hook to function properly."
             ;; `initial' and `annotation' are bound in `remember'.
             ;; But if the property list has them, we prefer those values
             (v-i (or (plist-get org-store-link-plist :initial)
-                     (and (boundp 'initial) initial)
+                     (and (boundp 'initial) (symbol-value 'initial))
                      ""))
             (v-a (or (plist-get org-store-link-plist :annotation)
-                     (and (boundp 'annotation) annotation)
+                     (and (boundp 'annotation) (symbol-value 'annotation))
                      ""))
             ;; Is the link empty?  Then we do not want it...
             (v-a (if (equal v-a "[[]]") "" v-a))
@@ -447,7 +445,7 @@ to be run from that hook to function properly."
                    v-a))
             (v-n user-full-name)
             (v-k (if (marker-buffer org-clock-marker)
-                     (org-substring-no-properties org-clock-heading)))
+                     (org-no-properties org-clock-heading)))
             (v-K (if (marker-buffer org-clock-marker)
                      (org-make-link-string
                       (buffer-file-name (marker-buffer org-clock-marker))
@@ -474,7 +472,7 @@ to be run from that hook to function properly."
        (erase-buffer)
        (insert (substitute-command-keys
                 (format
-"## %s  \"%s\" -> \"* %s\"
+                 "## %s  \"%s\" -> \"* %s\"
 ## C-u C-c C-c  like C-c C-c, and immediately visit note at target location
 ## C-0 C-c C-c  \"%s\" -> \"* %s\"
 ## %s  to select file and header location interactively.
@@ -503,18 +501,20 @@ to be run from that hook to function properly."
                                       filename error)))))))
        ;; Simple %-escapes
        (goto-char (point-min))
-       (while (re-search-forward "%\\([tTuUaiAcxkKI]\\)" nil t)
-         (unless (org-remember-escaped-%)
-           (when (and initial (equal (match-string 0) "%i"))
-             (save-match-data
-               (let* ((lead (buffer-substring
-                             (point-at-bol) (match-beginning 0))))
-                 (setq v-i (mapconcat 'identity
-                                      (org-split-string initial "\n")
-                                      (concat "\n" lead))))))
-           (replace-match
-            (or (eval (intern (concat "v-" (match-string 1)))) "")
-            t t)))
+       (let ((init (and (boundp 'initial)
+                        (symbol-value 'initial))))
+         (while (re-search-forward "%\\([tTuUaiAcxkKI]\\)" nil t)
+           (unless (org-remember-escaped-%)
+             (when (and init (equal (match-string 0) "%i"))
+               (save-match-data
+                 (let* ((lead (buffer-substring
+                               (point-at-bol) (match-beginning 0))))
+                   (setq v-i (mapconcat 'identity
+                                        (org-split-string init "\n")
+                                        (concat "\n" lead))))))
+             (replace-match
+              (or (eval (intern (concat "v-" (match-string 1)))) "")
+              t t))))
 
        ;; %() embedded elisp
        (goto-char (point-min))
@@ -534,10 +534,10 @@ to be run from that hook to function properly."
        (when plist-p
          (goto-char (point-min))
          (while (re-search-forward "%\\(:[-a-zA-Z]+\\)" nil t)
-         (unless (org-remember-escaped-%)
-           (and (setq x (or (plist-get org-store-link-plist
-                                       (intern (match-string 1))) ""))
-                (replace-match x t t)))))
+           (unless (org-remember-escaped-%)
+             (and (setq x (or (plist-get org-store-link-plist
+                                         (intern (match-string 1))) ""))
+                  (replace-match x t t)))))
 
        ;; Turn on org-mode in the remember buffer, set local variables
        (let ((org-inhibit-startup t)) (org-mode) (org-remember-mode 1))
@@ -597,7 +597,7 @@ to be run from that hook to function properly."
                                                     (car clipboards))))))
             ((equal char "p")
              (let*
-                 ((prop (org-substring-no-properties prompt))
+                 ((prop (org-no-properties prompt))
                   (pall (concat prop "_ALL"))
                   (allowed
                    (with-current-buffer
@@ -785,7 +785,7 @@ The user is queried for the template."
       (setq heading org-remember-default-headline))
     (setq visiting (org-find-base-buffer-visiting file))
     (if (not visiting) (find-file-noselect file))
-    (switch-to-buffer (or visiting (get-file-buffer file)))
+    (org-pop-to-buffer-same-window (or visiting (get-file-buffer file)))
     (widen)
     (goto-char (point-min))
     (if (re-search-forward
@@ -941,7 +941,7 @@ See also the variable `org-reverse-note-order'."
        (throw 'quit t))
       ;; Find the file
       (with-current-buffer (or visiting (find-file-noselect file))
-       (unless (or (org-mode-p) (member heading '(top bottom)))
+       (unless (or (derived-mode-p 'org-mode) (member heading '(top bottom)))
          (error "Target files for notes must be in Org-mode if not filing to top/bottom"))
        (save-excursion
          (save-restriction
@@ -951,7 +951,7 @@ See also the variable `org-reverse-note-order'."
            ;; Find the default location
            (when heading
              (cond
-              ((not (org-mode-p))
+              ((not (derived-mode-p 'org-mode))
                (if (eq heading 'top)
                    (goto-char (point-min))
                  (goto-char (point-max))
@@ -993,7 +993,7 @@ See also the variable `org-reverse-note-order'."
            (cond
             ((and fastp (memq heading '(top bottom)))
              (setq spos org-goto-start-pos
-                         exitcmd (if (eq heading 'top) 'left nil)))
+                   exitcmd (if (eq heading 'top) 'left nil)))
             (fastp (setq spos org-goto-start-pos
                          exitcmd 'return))
             ((eq org-remember-interactive-interface 'outline)
@@ -1004,7 +1004,7 @@ See also the variable `org-reverse-note-order'."
             ((eq org-remember-interactive-interface 'outline-path-completion)
              (let ((org-refile-targets '((nil . (:maxlevel . 10))))
                    (org-refile-use-outline-path t))
-               (setq spos (org-refile-get-location "Heading")
+               (setq spos (org-refile-get-location "Heading")
                      exitcmd 'return
                      spos (nth 3 spos))))
             (t (error "This should not happen")))
@@ -1012,7 +1012,7 @@ See also the variable `org-reverse-note-order'."
                                        ; not handle this note
            (and visitp (run-with-idle-timer 0.01 nil 'org-remember-visit-immediately))
            (goto-char spos)
-           (cond ((org-on-heading-p t)
+           (cond ((org-at-heading-p t)
                   (org-back-to-heading t)
                   (setq level (funcall outline-level))
                   (cond
@@ -1072,7 +1072,7 @@ See also the variable `org-reverse-note-order'."
                   (save-restriction
                     (widen)
                     (goto-char (point-min))
-                    (re-search-forward "^\\*+ " nil t)
+                    (re-search-forward org-outline-regexp-bol nil t)
                     (beginning-of-line 1)
                     (org-paste-subtree 1 txt)
                     (and org-auto-align-tags (org-set-tags nil t))
@@ -1149,6 +1149,4 @@ See also the variable `org-reverse-note-order'."
 
 (provide 'org-remember)
 
-
 ;;; org-remember.el ends here
-