]> code.delx.au - gnu-emacs/blobdiff - lisp/textmodes/remember.el
* lisp/textmodes/flyspell.el: Use lexical-binding and cl-lib.
[gnu-emacs] / lisp / textmodes / remember.el
index ceecbd9ba37b7d8047794ffe10b8478abb8aca86..35eaffa9284b07218159fe919c1464c5597f560e 100644 (file)
@@ -1,8 +1,9 @@
 ;;; remember --- a mode for quickly jotting down things to remember
 
-;; Copyright (C) 1999-2001, 2003-2014 Free Software Foundation, Inc.
+;; Copyright (C) 1999-2001, 2003-2015 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
+;; Maintainer: emacs-devel@gnu.org
 ;; Created: 29 Mar 1999
 ;; Version: 2.0
 ;; Keywords: data memory todo pim
 ;;
 ;; * Using "remember"
 ;;
-;; As a rough beginning, what I do is to keep my .notes file in
+;; As a rough beginning, what I do is to keep my `remember-data-file' in
 ;; outline-mode format, with a final entry called "* Raw data".  Then,
 ;; at intervals, I can move the data that gets appended there into
 ;; other places.  But certainly this should evolve into an intuitive
 
 ;;; Code:
 
-(provide 'remember)
-
 (defconst remember-version "2.0"
   "This version of remember.")
 
@@ -230,6 +229,8 @@ recorded somewhere by that function."
   :type 'boolean
   :group 'remember)
 
+;; See below for more user variables.
+
 ;;; Internal Variables:
 
 (defvar remember-buffer "*Remember*"
@@ -276,7 +277,7 @@ With a prefix or a visible region, use the region as INITIAL."
                         transient-mark-mode))
            (buffer-substring (region-beginning) (region-end)))))
   (funcall (if remember-in-new-frame
-               #'frame-configuration-to-register
+               #'frameset-to-register
              #'window-configuration-to-register) remember-register)
   (let* ((annotation
           (if remember-run-all-annotation-functions-flag
@@ -318,9 +319,7 @@ With a prefix or a visible region, use the region as INITIAL."
 
 (defsubst remember-mail-date (&optional rfc822-p)
   "Return a simple date.  Nothing fancy."
-  (if rfc822-p
-      (format-time-string "%a, %e %b %Y %T %z" (current-time))
-    (format-time-string "%a %b %e %T %Y" (current-time))))
+  (format-time-string (if rfc822-p "%a, %e %b %Y %T %z" "%a %b %e %T %Y")))
 
 (defun remember-buffer-desc ()
   "Using the first line of the current buffer, create a short description."
@@ -386,6 +385,7 @@ Subject: %s\n\n"
   "The file in which to store unprocessed data.
 When set via customize, visited file of the notes buffer (if it
 exists) might be changed."
+  :version "24.4"                       ; added locate-user-emacs-file
   :type 'file
   :set (lambda (symbol value)
          (let ((buf (find-buffer-visiting (default-value symbol))))
@@ -441,23 +441,25 @@ If you want to remember a region, supply a universal prefix to
       (remember-destroy))))
 
 (defcustom remember-data-directory "~/remember"
-  "The directory in which to store remember data as files."
+  "The directory in which to store remember data as files.
+Used by `remember-store-in-files'."
   :type 'directory
   :version "24.4"
   :group 'remember)
 
 (defcustom remember-directory-file-name-format "%Y-%m-%d_%T-%z"
-  "Format string for the file name in which to store unprocessed data."
+  "Format string for the file name in which to store unprocessed data.
+This is passed to `format-time-string'.
+Used by `remember-store-in-files'."
   :type 'string
   :version "24.4"
   :group 'remember)
 
 (defun remember-store-in-files ()
   "Store remember data in a file in `remember-data-directory'.
-The file is named after `remember-directory-file-name-format' fed through
-`format-time-string'."
-  (let ((name (format-time-string
-              remember-directory-file-name-format (current-time)))
+The file is named by calling `format-time-string' using
+`remember-directory-file-name-format' as the format string."
+  (let ((name (format-time-string remember-directory-file-name-format))
         (text (buffer-string)))
     (with-temp-buffer
       (insert text)
@@ -494,6 +496,8 @@ If this is nil, then `diary-file' will be used instead."
   :type '(choice (const :tag "diary-file" nil) file)
   :group 'remember)
 
+(defvar calendar-date-style)            ; calendar.el
+
 (defun remember-diary-convert-entry (entry)
   "Translate MSG to an entry readable by diary."
   (save-match-data
@@ -506,23 +510,17 @@ If this is nil, then `diary-file' will be used instead."
           ;; which requires calendar.
           (require 'calendar)
           (replace-match
-           (let ((style (if (boundp 'calendar-date-style)
-                            calendar-date-style
-                          ;; Don't complain about obsolescence.
-                          (if (with-no-warnings european-calendar-style)
-                              'european
-                            'american))))
-             (cond ((eq style 'european)
-                    (concat (match-string 3 entry) "/"
-                            (match-string 2 entry) "/"
-                            (match-string 1 entry)))
-                   ((eq style 'iso)
-                    (concat (match-string 1 entry) "-"
+           (cond ((eq calendar-date-style 'european)
+                  (concat (match-string 3 entry) "/"
+                          (match-string 2 entry) "/"
+                          (match-string 1 entry)))
+                 ((eq calendar-date-style 'iso)
+                  (concat (match-string 1 entry) "-"
                             (match-string 2 entry) "-"
                             (match-string 3 entry)))
-                   (t (concat (match-string 2 entry) "/"
-                              (match-string 3 entry) "/"
-                              (match-string 1 entry)))))
+                 (t (concat (match-string 2 entry) "/"
+                            (match-string 3 entry) "/"
+                            (match-string 1 entry))))
            t t entry))
       entry)))
 
@@ -549,7 +547,7 @@ If this is nil, then `diary-file' will be used instead."
     (define-key map "\C-c\C-c" 'remember-finalize)
     (define-key map "\C-c\C-k" 'remember-destroy)
     map)
-  "Keymap used in Remember mode.")
+  "Keymap used in `remember-mode'.")
 
 (define-derived-mode remember-mode indented-text-mode "Remember"
   "Major mode for output from \\[remember].
@@ -571,20 +569,19 @@ purpose of storing notes."
   :version "24.4")
 
 (defcustom remember-notes-initial-major-mode nil
-  "Major mode to set to notes buffer when it's created.
-If set to nil will use the same mode as `initial-major-mode'."
-  :type '(choice (const    :tag "Same as `initial-major-mode'" nil)
+  "Major mode to use in the notes buffer when it's created.
+If this is nil, use `initial-major-mode'."
+  :type '(choice (const    :tag "Use `initial-major-mode'" nil)
                 (function :tag "Major mode" text-mode))
   :version "24.4")
 
 (defcustom remember-notes-bury-on-kill t
-  "Whether to bury notes buffer instead of killing."
+  "Non-nil means `kill-buffer' will bury the notes buffer instead of killing."
   :type 'boolean
   :version "24.4")
 
 (defun remember-notes-save-and-bury-buffer ()
-  "Saves and buries current buffer.
-Buffer is saved only if `buffer-modified-p' returns non-nil."
+  "Save (if it is modified) and bury the current buffer."
   (interactive)
   (when (buffer-modified-p)
     (save-buffer))
@@ -596,10 +593,14 @@ Buffer is saved only if `buffer-modified-p' returns non-nil."
   (let ((map (make-sparse-keymap)))
     (define-key map "\C-c\C-c" 'remember-notes-save-and-bury-buffer)
     map)
-  "Keymap used in remember-notes mode.")
+  "Keymap used in `remember-notes-mode'.")
 
 (define-minor-mode remember-notes-mode
-  "Minor mode for the `remember-notes' buffer."
+  "Minor mode for the `remember-notes' buffer.
+This sets `buffer-save-without-query' so that `save-some-buffers' will
+save the notes buffer without asking.
+
+\\{remember-notes-mode-map}"
   nil nil nil
   (cond
    (remember-notes-mode
@@ -609,29 +610,25 @@ Buffer is saved only if `buffer-modified-p' returns non-nil."
 
 ;;;###autoload
 (defun remember-notes (&optional switch-to)
-  "Creates notes buffer and switches to it if called interactively.
-
-If a notes buffer created by a previous invocation of this
-function already exist, it will be returned.  Otherwise a new
-buffer will be created whose content will be read from file
-pointed by `remember-data-file'.  If a buffer visiting this file
-already exist, that buffer will be used instead of creating a new
-one (see `find-file-noselect' function for more details).
-
-Name of the created buffer is taken from `remember-notes-buffer-name'
-variable and if a buffer with that name already exist (but was not
-created by this function), it will be first killed.
-\\<remember-notes-mode-map>
-`remember-notes-mode' is active in the notes buffer which by default
-contains only one \\[save-and-bury-buffer] binding which saves and
-buries the buffer.
-
-Function returns notes buffer.  When called interactively,
-switches to it as well.
-
-Notes buffer is meant for keeping random notes which you'd like to
-preserve across Emacs restarts.  The notes will be stored in the
-`remember-data-file'."
+  "Return the notes buffer, creating it if needed, and maybe switch to it.
+This buffer is for notes that you want to preserve across Emacs sessions.
+The notes are saved in `remember-data-file'.
+
+If a buffer is already visiting that file, just return it.
+
+Otherwise, create the buffer, and rename it to `remember-notes-buffer-name',
+unless a buffer of that name already exists.  Set the major mode according
+to `remember-notes-initial-major-mode', and enable `remember-notes-mode'
+minor mode.
+
+Use \\<remember-notes-mode-map>\\[remember-notes-save-and-bury-buffer] to save and bury the notes buffer.
+
+Interactively, or if SWITCH-TO is non-nil, switch to the buffer.
+Return the buffer.
+
+Set `initial-buffer-choice' to `remember-notes' to visit your notes buffer
+when Emacs starts.  Set `remember-notes-buffer-name' to \"*scratch*\"
+to turn the *scratch* buffer into your notes buffer."
   (interactive "p")
   (let ((buf (or (find-buffer-visiting remember-data-file)
                  (with-current-buffer (find-file-noselect remember-data-file)
@@ -647,10 +644,18 @@ preserve across Emacs restarts.  The notes will be stored in the
     buf))
 
 (defun remember-notes--kill-buffer-query ()
+  "Function that `remember-notes-mode' adds to `kill-buffer-query-functions'.
+Save the current buffer if modified.  If `remember-notes-bury-on-kill'
+is non-nil, bury it and return nil; otherwise return t."
   (when (buffer-modified-p)
     (save-buffer))
   (if remember-notes-bury-on-kill
-      (bury-buffer)
+      (progn
+        ;; bury-buffer always returns nil, but let's be explicit.
+        (bury-buffer)
+        nil)
     t))
 
+(provide 'remember)
+
 ;;; remember.el ends here