[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Support auto-saving notes into it's own file.

From: Michal Nazarewicz
Subject: [PATCH] Support auto-saving notes into it's own file.
Date: Fri, 23 Aug 2013 23:25:32 +0200

From: Michal Nazarewicz <address@hidden>

This change introduces a `remember-notes-auto-save-visited-file-name'
custom variable which, if non-nil, causes the `auto-save-visited-file-name'
variable to be set to t in the notes buffer.  This is done by the
`remember-notes-mode' minor mode.

Moreover, it also modifies the `remember-notes' function so that buffer
whose name is specified by `remember-notes-buffer-name' variable will be
killed, if it exists, for use for the notes buffer.  This is consistant
with the documentation.

Finally, as a minor change, to make `remember-notes' easier to discover,
some of the documentation strings were updated to use a "`remember-notes'
buffer" phrase rather than "notes buffer".  With `remember-notes' being
a hyperlink, this should make it easier for users to go to function's
 lisp/ChangeLog             | 12 ++++++++++++
 lisp/textmodes/remember.el | 38 ++++++++++++++++++++++++++++----------
 2 files changed, 40 insertions(+), 10 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 27242fa..46d8746 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,15 @@
+2013-08-23  Michal Nazarewicz  <address@hidden>
+       * textmodes/remember.el
+       (remember-notes-auto-save-visited-file-name): New custom variable
+       for setting whether user wants to auto-save notes into the notes
+       file itself.
+       (remember-notes-mode): Changed to make use of tho
+       remember-notes-auto-save-visited-file-name variable.
+       (remember-notes): Changed to hijack buffer whose name matches
+       `remember-notes-buffer-name' variable as per variable's and
+       function's documentation.
 2013-08-23  Glenn Morris  <address@hidden>
        * files.el (auto-mode-alist): Use sh-mode for .bash_history.
diff --git a/lisp/textmodes/remember.el b/lisp/textmodes/remember.el
index 39f3acd..411dd60 100644
--- a/lisp/textmodes/remember.el
+++ b/lisp/textmodes/remember.el
@@ -383,8 +383,8 @@ Subject: %s\n\n"
 (defcustom remember-data-file (locate-user-emacs-file "notes" ".notes")
   "The file in which to store unprocessed data.
-When set via customize, visited file of the notes buffer (if it
-exists) might be changed."
+When set via customize, visited file of the `remember-notes' buffer
+\(if it exists) might be changed."
   :type 'file
   :set (lambda (symbol value)
          (let ((buf (find-buffer-visiting (default-value symbol))))
@@ -563,22 +563,36 @@ the data away for latter retrieval, and possible indexing.
 ;; Notes buffer showing the notes:
 (defcustom remember-notes-buffer-name "*notes*"
-  "Name of the notes buffer.
+  "Name of the `remember-notes' buffer.
 Setting it to *scratch* will hijack the *scratch* buffer for the
 purpose of storing notes."
   :type 'string
+  :group 'remember
   :version "24.4")
 (defcustom remember-notes-initial-major-mode nil
-  "Major mode to set to notes buffer when it's created.
+  "Major mode to set to `remember-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)
                 (function :tag "Major mode" text-mode))
+  :group 'remember
   :version "24.4")
 (defcustom remember-notes-bury-on-kill t
-  "Whether to bury notes buffer instead of killing."
+  "Whether to bury `remember-notes' buffer instead of killing."
   :type 'boolean
+  :group 'remember
+  :version "24.4")
+(defcustom remember-notes-auto-save-visited-file-name nil
+  "Whether to auto-save `remember-notes' buffer in the notes file itself.
+If non-nil, the contents of the `remember-notes' buffer will be saved
+in the visited file itself thus avoiding the existence of an auto-save
+file and \"consider M-x recover-this-file\" message.  If set to nil,
+the value of the `auto-save-visited-file-name' variable will take
+  :type 'boolean
+  :group 'remember
   :version "24.4")
 (defun remember-notes-save-and-bury-buffer ()
@@ -589,8 +603,6 @@ Buffer is saved only if `buffer-modified-p' returns 
 (defvar remember-notes-mode-map
   (let ((map (make-sparse-keymap)))
     (define-key map "\C-c\C-c" 'remember-notes-save-and-bury-buffer)
@@ -602,6 +614,8 @@ Buffer is saved only if `buffer-modified-p' returns 
   nil nil nil
+    (when remember-notes-auto-save-visited-file-name
+      (set (make-local-variable 'auto-save-visited-file-name) t))
     (add-hook 'kill-buffer-query-functions
               #'remember-notes--kill-buffer-query nil t)
     (setq buffer-save-without-query t))))
@@ -625,8 +639,8 @@ created by this function), it will be first killed.
 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.
+Function returns notes buffer.  When called interactively, or
+SWITCH-TO is non-nil, 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
@@ -635,7 +649,11 @@ preserve across Emacs restarts.  The notes will be stored 
in the
   (let ((buf (or (find-buffer-visiting remember-data-file)
                  (with-current-buffer (find-file-noselect remember-data-file)
                    (and remember-notes-buffer-name
-                        (not (get-buffer remember-notes-buffer-name))
+                        (not (string-equal remember-notes-buffer-name
+                                           (buffer-name)))
+                        (let ((other (get-buffer remember-notes-buffer-name)))
+                          (or (not other)
+                              (kill-buffer other)))
                         (rename-buffer remember-notes-buffer-name))
                    (funcall (or remember-notes-initial-major-mode

reply via email to

[Prev in Thread] Current Thread [Next in Thread]