emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] trunk r113239: Add `remember-notes' function to store rand


From: Stefan Monnier
Subject: [Emacs-diffs] trunk r113239: Add `remember-notes' function to store random notes across Emacs
Date: Sun, 30 Jun 2013 22:29:32 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 113239
revision-id: address@hidden
parent: address@hidden
author: Michal Nazarewicz <address@hidden>
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Sun 2013-06-30 18:29:23 -0400
message:
  Add `remember-notes' function to store random notes across Emacs
  restarts.
  * remember.el (remember-data-file): Add :set callback to affect
  notes buffer (if any).
  (remember-notes): New command.
  (remember-notes-buffer-name, bury-remember-notes-on-kill):
  New defcustoms for the `remember-notes' function.
  (remember-notes-save-and-bury-buffer): New command.
  (remember-notes-mode-map): New variable.
  (remember-mode): New minor mode.
  (remember-notes--kill-buffer-query): New function.
  * lisp/startup.el (initial-buffer-choice): Add notes to custom type.
  * src/buffer.c (FKill_buffer): Run `kill-buffer-query-functions'
  before checking whether buffer is modified.  This lets
  `kill-buffer-query-functions' cancel killing of the buffer or save
  its content before `kill-buffer' asks user the "Buffer %s
  modified; kill anyway?" question.
  
  * remember.el (remember-append-to-file):
  Don't mix `find-buffer-visiting' and `get-file-buffer'.
  
  * lisp/files.el (find-file-noselect): Simplify conditional expression.
modified:
  doc/lispref/buffers.texi       
buffers.texi-20091113204419-o5vbwnq5f7feedwu-6164
  etc/NEWS                       news-20100311060928-aoit31wvzf25yr1z-1
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/files.el                  files.el-20091113204419-o5vbwnq5f7feedwu-265
  lisp/startup.el                startup.el-20091113204419-o5vbwnq5f7feedwu-260
  lisp/textmodes/remember.el     
remember.el-20091113204419-o5vbwnq5f7feedwu-7584
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/buffer.c                   buffer.c-20091113204419-o5vbwnq5f7feedwu-264
  src/xdisp.c                    xdisp.c-20091113204419-o5vbwnq5f7feedwu-240
=== modified file 'doc/lispref/buffers.texi'
--- a/doc/lispref/buffers.texi  2013-06-29 03:24:22 +0000
+++ b/doc/lispref/buffers.texi  2013-06-30 22:29:23 +0000
@@ -1065,7 +1065,7 @@
 @end deffn
 
 @defvar kill-buffer-query-functions
-After confirming unsaved changes, @code{kill-buffer} calls the functions
+Before confirming unsaved changes, @code{kill-buffer} calls the functions
 in the list @code{kill-buffer-query-functions}, in order of appearance,
 with no arguments.  The buffer being killed is the current buffer when
 they are called.  The idea of this feature is that these functions will

=== modified file 'etc/NEWS'
--- a/etc/NEWS  2013-06-30 15:10:33 +0000
+++ b/etc/NEWS  2013-06-30 22:29:23 +0000
@@ -90,6 +90,14 @@
 ** `initial-buffer-choice' can now specify a function to set up the
 initial buffer.
 
+** `remember-notes' creates a buffer whose content is saved on kill-emacs.
+You may think of it as a *scratch* buffer whose content is preserved.
+In fact, it was designed as a replacement for *scratch* buffer and can
+be used that way by setting `initial-buffer-choice' to `remember-notes'
+and `remember-notes-buffer-name' to "*scratch*".  Without the second
+change, *scratch* buffer will still be there for notes that do not
+need to be preserved.
+
 ** `write-region-inhibit-fsync' now defaults to t in batch mode.
 
 ** ACL support has been added.

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-06-30 14:49:33 +0000
+++ b/lisp/ChangeLog    2013-06-30 22:29:23 +0000
@@ -1,18 +1,37 @@
+2013-06-30  Michal Nazarewicz  <address@hidden>
+
+       * files.el (find-file-noselect): Simplify conditional expression.
+
+       * remember.el (remember-append-to-file):
+       Don't mix `find-buffer-visiting' and `get-file-buffer'.
+
+       Add `remember-notes' function to store random notes across Emacs
+       restarts.
+       * remember.el (remember-data-file): Add :set callback to affect
+       notes buffer (if any).
+       (remember-notes): New command.
+       (remember-notes-buffer-name, bury-remember-notes-on-kill):
+       New defcustoms for the `remember-notes' function.
+       (remember-notes-save-and-bury-buffer): New command.
+       (remember-notes-mode-map): New variable.
+       (remember-mode): New minor mode.
+       (remember-notes--kill-buffer-query): New function.
+       * startup.el (initial-buffer-choice): Add notes to custom type.
+
 2013-06-30  Eli Zaretskii  <address@hidden>
 
        * bindings.el (right-char, left-char): Don't call sit-for, this is
        no longer needed.  Use arithmetic comparison only for numerical
        arguments.
 
-       * international/mule-cmds.el (select-safe-coding-system): Handle
-       the case of FROM being a string correctly.  (Bug#14755)
+       * international/mule-cmds.el (select-safe-coding-system):
+       Handle the case of FROM being a string correctly.  (Bug#14755)
 
 2013-06-30  Lars Magne Ingebrigtsen  <address@hidden>
 
        * net/shr.el (shr-make-table-1): Add a sanity check that allows
        progression on degenerate tables.
-       (shr-rescale-image): ImageMagick animated images currently doesn't
-       work.
+       (shr-rescale-image): ImageMagick animated images currently don't work.
 
 2013-06-30  Juanma Barranquero  <address@hidden>
 
@@ -28,8 +47,8 @@
 
 2013-06-30  Dmitry Gutov  <address@hidden>
 
-       * progmodes/ruby-mode.el (ruby-syntax-propertize-function): Don't
-       start heredoc inside a string or comment.
+       * progmodes/ruby-mode.el (ruby-syntax-propertize-function):
+       Don't start heredoc inside a string or comment.
 
 2013-06-29  Eli Zaretskii  <address@hidden>
 
@@ -80,7 +99,7 @@
 
 2013-06-27  Lars Magne Ingebrigtsen  <address@hidden>
 
-       * net/shr.el (add-face-text-property): Removed compat definition.
+       * net/shr.el (add-face-text-property): Remove compat definition.
 
 2013-06-27  Stephen Berman  <address@hidden>
 

=== modified file 'lisp/files.el'
--- a/lisp/files.el     2013-05-21 07:25:14 +0000
+++ b/lisp/files.el     2013-06-30 22:29:23 +0000
@@ -1859,13 +1859,12 @@
                      (setq buffer-read-only read-only)))
                  (setq buffer-file-read-only read-only))
 
-               (when (and (not (eq (not (null rawfile))
-                                   (not (null find-file-literally))))
-                          (not nonexistent)
-                          ;; It is confusing to ask whether to visit
-                          ;; non-literally if they have the file in
-                          ;; hexl-mode or image-mode.
-                          (not (memq major-mode '(hexl-mode image-mode))))
+               (unless (or (eq (null rawfile) (null find-file-literally))
+                           nonexistent
+                           ;; It is confusing to ask whether to visit
+                           ;; non-literally if they have the file in
+                           ;; hexl-mode or image-mode.
+                           (memq major-mode '(hexl-mode image-mode)))
                  (if (buffer-modified-p)
                      (if (y-or-n-p
                           (format

=== modified file 'lisp/startup.el'
--- a/lisp/startup.el   2013-06-17 15:33:52 +0000
+++ b/lisp/startup.el   2013-06-30 22:29:23 +0000
@@ -53,7 +53,8 @@
          (const     :tag "Startup screen" nil)
          (directory :tag "Directory" :value "~/")
          (file      :tag "File" :value "~/.emacs")
-          (function  :tag "Function")
+         (const     :tag "Notes buffer" remember-notes)
+         (function  :tag "Function")
          (const     :tag "Lisp scratch buffer" t))
   :version "24.4"
   :group 'initialization)

=== modified file 'lisp/textmodes/remember.el'
--- a/lisp/textmodes/remember.el        2013-05-09 01:40:20 +0000
+++ b/lisp/textmodes/remember.el        2013-06-30 22:29:23 +0000
@@ -382,8 +382,18 @@
 ;; Remembering to plain files
 
 (defcustom remember-data-file (locate-user-emacs-file "notes" ".notes")
-  "The file in which to store unprocessed data."
+  "The file in which to store unprocessed data.
+When set via customize, visited file of the notes buffer (if it
+exists) might be changed."
   :type 'file
+  :set (lambda (symbol value)
+         (let ((buf (find-buffer-visiting (default-value symbol))))
+           (set-default symbol value)
+           (when (buffer-live-p buf)
+             (with-current-buffer buf
+               (set-visited-file-name
+                (expand-file-name remember-data-file))))))
+  :initialize 'custom-initialize-default
   :group 'remember)
 
 (defcustom remember-leader-text "** "
@@ -393,21 +403,20 @@
 
 (defun remember-append-to-file ()
   "Remember, with description DESC, the given TEXT."
-  (let ((text (buffer-string))
-        (desc (remember-buffer-desc)))
-    (with-temp-buffer
-      (insert "\n" remember-leader-text (current-time-string)
-              " (" desc ")\n\n" text)
-      (if (not (bolp))
-          (insert "\n"))
-      (if (find-buffer-visiting remember-data-file)
-          (let ((remember-text (buffer-string)))
-            (set-buffer (get-file-buffer remember-data-file))
-            (save-excursion
-              (goto-char (point-max))
-              (insert remember-text)
-              (when remember-save-after-remembering (save-buffer))))
-        (append-to-file (point-min) (point-max) remember-data-file)))))
+  (let* ((text (buffer-string))
+         (desc (remember-buffer-desc))
+         (remember-text (concat "\n" remember-leader-text (current-time-string)
+                                " (" desc ")\n\n" text
+                                (save-excursion (goto-char (point-max))
+                                                (if (bolp) nil "\n"))))
+         (buf (find-buffer-visiting remember-data-file)))
+    (if buf
+        (with-current-buffer buf
+          (save-excursion
+            (goto-char (point-max))
+            (insert remember-text))
+          (if remember-save-after-remembering (save-buffer)))
+      (append-to-file remember-text nil remember-data-file))))
 
 (defun remember-region (&optional beg end)
   "Remember the data from BEG to END.
@@ -551,4 +560,96 @@
 \\{remember-mode-map}"
   (set-keymap-parent remember-mode-map nil))
 
+;; Notes buffer showing the notes:
+
+(defcustom remember-notes-buffer-name "*notes*"
+  "Name of the notes buffer.
+Setting it to *scratch* will hijack the *scratch* buffer for the
+purpose of storing notes."
+  :type 'string
+  :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)
+                (function :tag "Major mode" text-mode))
+  :version "24.4")
+
+(defcustom remember-notes-bury-on-kill t
+  "Whether to bury 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."
+  (interactive)
+  (when (buffer-modified-p)
+    (save-buffer))
+  (bury-buffer))
+
+
+
+(defvar remember-notes-mode-map
+  (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.")
+
+(define-minor-mode remember-notes-mode
+  "Minor mode for the `remember-notes' buffer."
+  nil nil nil
+  (cond
+   (remember-notes-mode
+    (add-hook 'kill-buffer-query-functions
+              #'remember-notes--kill-buffer-query nil t)
+    (setq buffer-save-without-query t))))
+
+;;;###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'."
+  (interactive "p")
+  (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))
+                        (rename-buffer remember-notes-buffer-name))
+                   (funcall (or remember-notes-initial-major-mode
+                                initial-major-mode))
+                   (remember-notes-mode 1)
+                   (current-buffer)))))
+    (when switch-to
+      (switch-to-buffer buf))
+    buf))
+
+(defun remember-notes--kill-buffer-query ()
+  (when (buffer-modified-p)
+    (save-buffer))
+  (if remember-notes-bury-on-kill
+      (bury-buffer)
+    t))
+
 ;;; remember.el ends here

=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-06-30 16:38:26 +0000
+++ b/src/ChangeLog     2013-06-30 22:29:23 +0000
@@ -1,3 +1,11 @@
+2013-06-30  Michal Nazarewicz  <address@hidden>
+
+       * buffer.c (FKill_buffer): Run `kill-buffer-query-functions'
+       before checking whether buffer is modified.  This lets
+       `kill-buffer-query-functions' cancel killing of the buffer or save
+       its content before `kill-buffer' asks user the "Buffer %s
+       modified; kill anyway?" question.
+
 2013-06-30  Jan Djärv  <address@hidden>
 
        * nsfns.m (handlePanelKeys): Don't process Command+Function keys.
@@ -59,6 +67,24 @@
        :prefer-utf-8.
        (syms_of_coding): Adjust for coding_arg_undecided_max.
 
+2013-06-28  Kenichi Handa  <address@hidden>
+
+       * coding.h (define_coding_undecided_arg_index): New enum.
+       (coding_attr_index): New members
+       coding_attr_undecided_inhibit_null_byte_detection,
+       coding_attr_undecided_inhibit_iso_escape_detection,
+       coding_attr_undecided_prefer_utf_8.
+       (undecided_spec): New struct.
+       (struct coding_system): New member `undecided' of the member `spec'.
+
+       * coding.c (setup_coding_system): Handle CODING->spec.undecided.
+       (detect_coding): Likewise.
+       (detect_coding_system): Likewise.
+       (Fdefine_coding_system_internal): New coding system properties
+       :inhibit-null-byte-detection, :inhibit-iso-escape-detection, and
+       :prefer-utf-8.
+       (syms_of_coding): Adjust for coding_arg_undecided_max.
+
 2013-06-28  Paul Eggert  <address@hidden>
 
        * image.c (x_from_xcolors): Remove unused local.
@@ -75,8 +101,8 @@
        (x_clear_image_1): New arg `flags' instead of 3 bools `pixmap_p',
        `mask_p', and `colors_p'.  All uses changed.
        (x_clear_image_1) [HAVE_X_WINDOWS]: Destroy `ximg' and `mask_img'.
-       (CLEAR_IMAGE_PIXMAP, CLEAR_IMAGE_MASK, CLEAR_IMAGE_COLORS): New
-       macros for `flags' arg to x_clear_image_1.
+       (CLEAR_IMAGE_PIXMAP, CLEAR_IMAGE_MASK, CLEAR_IMAGE_COLORS):
+       New macros for `flags' arg to x_clear_image_1.
        (postprocess_image, xpm_load_image, x_build_heuristic_mask)
        (png_load_body): Use x_clear_image_1 instead of Free_Pixmap.
        (ZPixmap, XGetImage) [HAVE_NS]: Remove.
@@ -343,7 +369,7 @@
        * textprop.c (property_set_type): New enum.
        (add_properties): Allow appending/prepending text properties.
        (add_text_properties_1): Factored out of Fadd_text_properties.
-       (Fadd_text_properties): Moved all the code into
+       (Fadd_text_properties): Move all the code into
        add_text_properties_1.
        (Fadd_face_text_property): New function that calls
        add_text_properties_1.
@@ -914,7 +940,7 @@
        (Fxw_color_values): Use EmacsCGFloat
        (Fns_display_monitor_attributes_list): Only get screen number for
        Cocoa.
-       (getDirectory, getFilename): Removed from EmacsOpenPanel and
+       (getDirectory, getFilename): Remove from EmacsOpenPanel and
        EmacsSavePanel.
        (EmacsOpenPanel:ok:): Use ns_filename_from_panel and
        ns_directory_from_panel.

=== modified file 'src/buffer.c'
--- a/src/buffer.c      2013-06-17 06:03:19 +0000
+++ b/src/buffer.c      2013-06-30 22:29:23 +0000
@@ -1734,18 +1734,6 @@
   if (!BUFFER_LIVE_P (b))
     return Qnil;
 
-  /* Query if the buffer is still modified.  */
-  if (INTERACTIVE && !NILP (BVAR (b, filename))
-      && BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
-    {
-      GCPRO1 (buffer);
-      tem = do_yes_or_no_p (format2 ("Buffer %s modified; kill anyway? ",
-                                    BVAR (b, name), make_number (0)));
-      UNGCPRO;
-      if (NILP (tem))
-       return Qnil;
-    }
-
   /* Run hooks with the buffer to be killed the current buffer.  */
   {
     ptrdiff_t count = SPECPDL_INDEX ();
@@ -1761,6 +1749,22 @@
     if (NILP (tem))
       return unbind_to (count, Qnil);
 
+    /* Query if the buffer is still modified.  */
+    if (INTERACTIVE && !NILP (BVAR (b, filename))
+       && BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
+      {
+        GCPRO1 (buffer);
+        tem = do_yes_or_no_p (format2 ("Buffer %s modified; kill anyway? ",
+                                      BVAR (b, name), make_number (0)));
+       UNGCPRO;
+       if (NILP (tem))
+         return unbind_to (count, Qnil);
+      }
+
+    /* If the hooks have killed the buffer, exit now.  */
+    if (!BUFFER_LIVE_P (b))
+      return unbind_to (count, Qt);
+
     /* Then run the hooks.  */
     Frun_hooks (1, &Qkill_buffer_hook);
     unbind_to (count, Qnil);

=== modified file 'src/xdisp.c'
--- a/src/xdisp.c       2013-06-30 15:10:33 +0000
+++ b/src/xdisp.c       2013-06-30 22:29:23 +0000
@@ -20110,7 +20110,7 @@
              w->cursor.vpos = -1;
              return make_number (PT);
            }
-         else if (!INTEGERP (g->object) && g->object != gpt->object)
+         else if (!INTEGERP (g->object) && !EQ (g->object, gpt->object))
            {
              ptrdiff_t new_pos;
 


reply via email to

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