unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCHv4 0/4] Add `remember-notes' function
@ 2013-06-24 12:35 Michal Nazarewicz
  2013-06-24 12:35 ` [PATCHv4 1/4] `kill-buffer' runs query functions before checking buffer modification Michal Nazarewicz
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Michal Nazarewicz @ 2013-06-24 12:35 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Most importantly, compared to version 3, this version removes the
`notes-file' defucstom and replaces loading of the notes file with
a call to `find-file-noselect' (both suggested by Stefan).  I've also
ripped out auto-save handlling since `find-file-noselect' should now
handle this like it does with other files.

The second and fourth patch are unrelated to the remember-notes
function and are just things that I've noticed while looking through
the code.

Michal Nazarewicz (4):
  `kill-buffer' runs query functions before checking buffer
    modification.
  `remember-append-to-file' appending to buffer bug fix
  Add `remember-notes' function to store notes across Emacs restarts.
  Simplify conditional expression in `find-file-noselect'.

 etc/NEWS                   |   8 +++
 lisp/ChangeLog             |  31 +++++++++++
 lisp/files.el              |  13 +++--
 lisp/startup.el            |   3 +-
 lisp/textmodes/remember.el | 129 ++++++++++++++++++++++++++++++++++++++++-----
 lisp/window.el             |   8 +++
 src/ChangeLog              |   8 +++
 src/buffer.c               |  24 ++++-----
 8 files changed, 192 insertions(+), 32 deletions(-)

-- 
1.8.3.1




^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCHv4 1/4] `kill-buffer' runs query functions before checking buffer modification.
  2013-06-24 12:35 [PATCHv4 0/4] Add `remember-notes' function Michal Nazarewicz
@ 2013-06-24 12:35 ` Michal Nazarewicz
  2013-06-24 17:05   ` martin rudalics
  2013-06-24 12:35 ` [PATCHv4 2/4] `remember-append-to-file' appending to buffer bug fix Michal Nazarewicz
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 12+ messages in thread
From: Michal Nazarewicz @ 2013-06-24 12:35 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: martin rudalics, emacs-devel

* 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.
---
 src/ChangeLog |  8 ++++++++
 src/buffer.c  | 24 ++++++++++++------------
 2 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 6357491..50802fc 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,11 @@
+2013-06-24  Michal Nazarewicz  <mina86@mina86.com>
+
+	* 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-23  Paul Eggert  <eggert@cs.ucla.edu>
 
 	A more-conservative workaround for Cygwin SIGCHLD issues (Bug#14569).
diff --git a/src/buffer.c b/src/buffer.c
index 08299da..066b31d 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1734,18 +1734,6 @@ cleaning up all windows currently displaying the buffer to be killed. */)
   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,18 @@ cleaning up all windows currently displaying the buffer to be killed. */)
     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);
+      }
+
     /* Then run the hooks.  */
     Frun_hooks (1, &Qkill_buffer_hook);
     unbind_to (count, Qnil);
-- 
1.8.3.1




^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCHv4 2/4] `remember-append-to-file' appending to buffer bug fix
  2013-06-24 12:35 [PATCHv4 0/4] Add `remember-notes' function Michal Nazarewicz
  2013-06-24 12:35 ` [PATCHv4 1/4] `kill-buffer' runs query functions before checking buffer modification Michal Nazarewicz
@ 2013-06-24 12:35 ` Michal Nazarewicz
  2013-06-24 12:35 ` [PATCHv4 3/4] Add `remember-notes' function to store notes across Emacs restarts Michal Nazarewicz
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: Michal Nazarewicz @ 2013-06-24 12:35 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

* remember.el (remember-append-to-file): Function used
`find-buffer-visiting' to check whether a file visiting
`remember-data-file` existed but then `get-buffer-visiting' to
retrieve it.  However, the latter requires exact string match so
it could return nil even though the former found a buffer.
Storing result of the `find-buffer-visiting' fixes the issue (and
saves one lookup).
---
 lisp/ChangeLog             | 10 ++++++++++
 lisp/textmodes/remember.el | 25 ++++++++++++++-----------
 2 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 784415f..75b9533 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,13 @@
+2013-06-24  Michal Nazarewicz  <mina86@mina86.com>
+
+	* remember.el (remember-append-to-file): Function used
+	`find-buffer-visiting' to check whether a file visiting
+	`remember-data-file` existed but then `get-buffer-visiting' to
+	retrieve it.  However, the latter requires exact string match so
+	it could return nil even though the former found a buffer.
+	Storing result of the `find-buffer-visiting' fixes the issue (and
+	saves one lookup).
+
 2013-06-24  Daiki Ueno  <ueno@gnu.org>
 
 	* epg.el (epg-make-context): Check if PROTOCOL is valid; embed the
diff --git a/lisp/textmodes/remember.el b/lisp/textmodes/remember.el
index 5782f25..a14a34c 100644
--- a/lisp/textmodes/remember.el
+++ b/lisp/textmodes/remember.el
@@ -395,19 +395,22 @@ Subject: %s\n\n"
   "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))
+    (let ((buf (find-buffer-visiting remember-data-file)))
+      (if buf
+          (with-current-buffer buf
             (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)))))
+              (insert "\n" remember-leader-text (current-time-string)
+                      " (" desc ")\n\n" text)
+              (unless (bolp)
+                (insert "\n")))
+            (if remember-save-after-remembering (save-buffer)))
+        (with-temp-buffer
+          (insert "\n" remember-leader-text (current-time-string)
+                  " (" desc ")\n\n" text)
+          (unless (bolp)
+            (insert "\n"))
+          (append-to-file (point-min) (point-max) remember-data-file))))))
 
 (defun remember-region (&optional beg end)
   "Remember the data from BEG to END.
-- 
1.8.3.1




^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCHv4 3/4] Add `remember-notes' function to store notes across Emacs restarts.
  2013-06-24 12:35 [PATCHv4 0/4] Add `remember-notes' function Michal Nazarewicz
  2013-06-24 12:35 ` [PATCHv4 1/4] `kill-buffer' runs query functions before checking buffer modification Michal Nazarewicz
  2013-06-24 12:35 ` [PATCHv4 2/4] `remember-append-to-file' appending to buffer bug fix Michal Nazarewicz
@ 2013-06-24 12:35 ` Michal Nazarewicz
  2013-06-24 12:35 ` [PATCHv4 4/4] Simplify conditional expression in `find-file-noselect' Michal Nazarewicz
  2013-06-30 22:29 ` [PATCHv4 0/4] Add `remember-notes' function Stefan Monnier
  4 siblings, 0 replies; 12+ messages in thread
From: Michal Nazarewicz @ 2013-06-24 12:35 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

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 'notes an
`notes-buffer-name' to "*scratch*".  Without the second
change, *scratch* buffer will still be there for notes that do not
need to be preserved.

Add `remember-notes' function to store random notes across Emacs
restarts.
* remember.el (remember-data-file): Added :set callback to affect
notes buffer (if any).
(remember-notes, toggle-remember-notes): New functions for showing
the notes buffer.
(remember-notes-buffer-name, bury-remember-notes-on-kill): New
defcustoms for the `remember-notes' function.
(remember-notes--buffer, remember-notes-map): New variables for
the `remember-notes' function.
(remember-notes--kill-buffer-query): New helper functions.
* startup.el (initial-buffer-choice): Added notes to custom type.
* window.el (save-and-bury-buffer): New function doing what the
name says.
---
 etc/NEWS                   |   8 ++++
 lisp/ChangeLog             |  17 ++++++++
 lisp/startup.el            |   3 +-
 lisp/textmodes/remember.el | 104 ++++++++++++++++++++++++++++++++++++++++++++-
 lisp/window.el             |   8 ++++
 5 files changed, 138 insertions(+), 2 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index d736454..6a2d3f2 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -87,6 +87,14 @@ simply disabling Transient Mark mode does the same thing.
 ** `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.
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 75b9533..a7b8fd1 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,22 @@
 2013-06-24  Michal Nazarewicz  <mina86@mina86.com>
 
+	Add `remember-notes' function to store random notes across Emacs
+	restarts.
+	* remember.el (remember-data-file): Added :set callback to affect
+	notes buffer (if any).
+	(remember-notes, toggle-remember-notes): New functions for showing
+	the notes buffer.
+	(remember-notes-buffer-name, bury-remember-notes-on-kill): New
+	defcustoms for the `remember-notes' function.
+	(remember-notes--buffer, remember-notes-map): New variables for
+	the `remember-notes' function.
+	(remember-notes--kill-buffer-query): New helper functions.
+	* startup.el (initial-buffer-choice): Added notes to custom type.
+	* window.el (save-and-bury-buffer): New function doing what the
+	name says.
+
+2013-06-24  Michal Nazarewicz  <mina86@mina86.com>
+
 	* remember.el (remember-append-to-file): Function used
 	`find-buffer-visiting' to check whether a file visiting
 	`remember-data-file` existed but then `get-buffer-visiting' to
diff --git a/lisp/startup.el b/lisp/startup.el
index 77b2bce..44eea77 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -53,7 +53,8 @@ or directory when no target file is specified."
 	  (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)
diff --git a/lisp/textmodes/remember.el b/lisp/textmodes/remember.el
index a14a34c..aa10aeb 100644
--- a/lisp/textmodes/remember.el
+++ b/lisp/textmodes/remember.el
@@ -381,9 +381,22 @@ Subject: %s\n\n"
 
 ;; Remembering to plain files
 
+(defvar remember-notes--buffer nil
+  "The notes buffer.")
+
 (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) is changed.  This is only of importance if you are using
+`remember-notes'."
   :type 'file
+  :set (lambda (symbol value)
+	 (set-default symbol value)
+	 (when (buffer-live-p remember-notes--buffer)
+	   (with-current-buffer remember-notes--buffer
+	     (setq buffer-file-name
+		   (expand-file-name remember-data-file)))))
+  :initialize 'custom-initialize-default
   :group 'remember)
 
 (defcustom remember-leader-text "** "
@@ -554,4 +567,93 @@ the data away for latter retrieval, and possible indexing.
 \\{remember-mode-map}"
   (set-keymap-parent remember-mode-map nil))
 
+;; 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
+  :group 'remember)
+
+(defcustom initial-remember-notes-major-mode t
+  "Major mode to set to notes buffer when it's created.
+If set to t will use the same mode as `initial-major-mode'."
+  :type '(choice (const    :tag "Same as `initial-major-mode'" t)
+		 (function :tag "Major mode" text-mode))
+  :group 'remember)
+
+(defcustom bury-remember-notes-on-kill t
+  "Whether to bury notes buffer instead of killing."
+  :type 'boolean
+  :group 'remember)
+
+(defvar remember-notes-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map "\C-c\C-c" 'save-and-bury-buffer)
+    map)
+  "A keymap used in notes buffer.")
+
+;;;###autoload
+(defun remember-notes ()
+  "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-map>
+`remember-notes-map' 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)
+  (unless (buffer-live-p remember-notes--buffer)
+    (setq remember-notes--buffer (find-file-noselect remember-data-file))
+    (with-current-buffer remember-notes--buffer
+      (let ((buf (get-buffer remember-notes-buffer-name)))
+	(if (or (not buf) (kill-buffer buf))
+	    (rename-buffer remember-notes-buffer-name)))
+      (funcall (if (eq initial-remember-notes-major-mode t)
+		   initial-major-mode
+		 initial-remember-notes-major-mode))
+      (setq buffer-save-without-query t)
+      (add-hook 'kill-buffer-query-functions 'remember-notes--kill-buffer-query)
+      (setq minor-mode-overriding-map-alist
+	    (cons (cons 'remember-notes--buffer remember-notes-map)
+		  minor-mode-overriding-map-alist))))
+  (when (called-interactively-p 'all)
+    (switch-to-buffer remember-notes--buffer))
+  remember-notes--buffer)
+
+;;;###autoload
+(defun toggle-remember-notes ()
+  "Switches to notes buffer unless already there in which case buries it.
+For more information about notes buffer see `remember-notes' function."
+  (interactive)
+  (if (eq (current-buffer) remember-notes--buffer)
+      (bury-buffer)
+    (switch-to-buffer (remember-notes))))
+
+(defun remember-notes--kill-buffer-query ()
+  (if (not (eq (current-buffer) remember-notes--buffer))
+      t
+    (when (buffer-modified-p)
+      (save-buffer))
+    (if bury-remember-notes-on-kill
+	(bury-buffer)
+      t)))
+
 ;;; remember.el ends here
diff --git a/lisp/window.el b/lisp/window.el
index 5b00198..7eda7ea 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -3429,6 +3429,14 @@ displayed there."
     ;; Always return nil.
     nil))
 
+(defun 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))
+
 (defun unbury-buffer ()
   "Switch to the last buffer in the buffer list."
   (interactive)
-- 
1.8.3.1




^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCHv4 4/4] Simplify conditional expression in `find-file-noselect'.
  2013-06-24 12:35 [PATCHv4 0/4] Add `remember-notes' function Michal Nazarewicz
                   ` (2 preceding siblings ...)
  2013-06-24 12:35 ` [PATCHv4 3/4] Add `remember-notes' function to store notes across Emacs restarts Michal Nazarewicz
@ 2013-06-24 12:35 ` Michal Nazarewicz
  2013-06-30 22:29 ` [PATCHv4 0/4] Add `remember-notes' function Stefan Monnier
  4 siblings, 0 replies; 12+ messages in thread
From: Michal Nazarewicz @ 2013-06-24 12:35 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

First of all, (null foo) always returns nil or t, and not is synonym
of null anywaya, so (eq (not (null foo)) (not (null bar))) can be
simplified to (eq (null foo) (null bar)).

Second of all, (and (not foo) (not bar) (not baz)) is the same as (not
(or foo bar baz)).

And then, finally, (when (not foo) bar...) is the same as (unless foo
bar...).
---
 lisp/ChangeLog |  4 ++++
 lisp/files.el  | 13 ++++++-------
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index a7b8fd1..eefceac 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,9 @@
 2013-06-24  Michal Nazarewicz  <mina86@mina86.com>
 
+	* files.el (find-file-noselect): Simplify conditional expression.
+
+2013-06-24  Michal Nazarewicz  <mina86@mina86.com>
+
 	Add `remember-notes' function to store random notes across Emacs
 	restarts.
 	* remember.el (remember-data-file): Added :set callback to affect
diff --git a/lisp/files.el b/lisp/files.el
index 871a4b0..e59a9ac 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1859,13 +1859,12 @@ the various files."
 		      (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
-- 
1.8.3.1




^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCHv4 1/4] `kill-buffer' runs query functions before checking buffer modification.
  2013-06-24 12:35 ` [PATCHv4 1/4] `kill-buffer' runs query functions before checking buffer modification Michal Nazarewicz
@ 2013-06-24 17:05   ` martin rudalics
  2013-06-24 18:31     ` Michal Nazarewicz
  0 siblings, 1 reply; 12+ messages in thread
From: martin rudalics @ 2013-06-24 17:05 UTC (permalink / raw)
  To: Michal Nazarewicz; +Cc: Stefan Monnier, emacs-devel

 > * 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.

We probably should guard against the case that the query functions
manage to kill the buffer prematurely.

martin



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCHv4 1/4] `kill-buffer' runs query functions before checking buffer modification.
  2013-06-24 17:05   ` martin rudalics
@ 2013-06-24 18:31     ` Michal Nazarewicz
  2013-06-24 20:57       ` martin rudalics
  0 siblings, 1 reply; 12+ messages in thread
From: Michal Nazarewicz @ 2013-06-24 18:31 UTC (permalink / raw)
  To: martin rudalics; +Cc: Stefan Monnier, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1199 bytes --]

On Mon, Jun 24 2013, martin rudalics wrote:
>  > * 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.
>
> We probably should guard against the case that the query functions
> manage to kill the buffer prematurely.

Except this would exactly defeat the purposes of this change.  Unless
I don't understand what you mean by “prematurely”.  I'm assuming you
want to prevent a function from doing:

  (set-buffer-modified-p nil)
  (let (kill-buffer-query-functions)
    (kill-buffer (current-buffer)))

or just that part without let.  But (set-buffer-modified-p nil) is
exactly what remember-notes--kill-buffer-query wants to do (admittedly
saving the contents prior).

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +----<email/xmpp: mpn@google.com>--------------ooO--(_)--Ooo--

[-- Attachment #2.1: Type: text/plain, Size: 0 bytes --]



[-- Attachment #2.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 835 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCHv4 1/4] `kill-buffer' runs query functions before checking buffer modification.
  2013-06-24 18:31     ` Michal Nazarewicz
@ 2013-06-24 20:57       ` martin rudalics
  2013-06-24 22:35         ` Michal Nazarewicz
  0 siblings, 1 reply; 12+ messages in thread
From: martin rudalics @ 2013-06-24 20:57 UTC (permalink / raw)
  To: Michal Nazarewicz; +Cc: Stefan Monnier, emacs-devel

 >> We probably should guard against the case that the query functions
 >> manage to kill the buffer prematurely.
 >
 > Except this would exactly defeat the purposes of this change.  Unless
 > I don't understand what you mean by “prematurely”.  I'm assuming you
 > want to prevent a function from doing:
 >
 >   (set-buffer-modified-p nil)
 >   (let (kill-buffer-query-functions)
 >     (kill-buffer (current-buffer)))
 >
 > or just that part without let.  But (set-buffer-modified-p nil) is
 > exactly what remember-notes--kill-buffer-query wants to do (admittedly
 > saving the contents prior).

Sure.  What I meant is that `kill-buffer' should return immediately when
the buffer is dead after calling the query functions instead of entering
the do_yes_or_no_p stuff with a dead buffer.  Or did I miss something?

martin




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCHv4 1/4] `kill-buffer' runs query functions before checking buffer modification.
  2013-06-24 20:57       ` martin rudalics
@ 2013-06-24 22:35         ` Michal Nazarewicz
  2013-06-25  6:47           ` martin rudalics
  0 siblings, 1 reply; 12+ messages in thread
From: Michal Nazarewicz @ 2013-06-24 22:35 UTC (permalink / raw)
  To: martin rudalics; +Cc: Stefan Monnier, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1101 bytes --]

On Mon, Jun 24 2013, martin rudalics wrote:
> Sure.  What I meant is that `kill-buffer' should return immediately when
> the buffer is dead after calling the query functions instead of entering
> the do_yes_or_no_p stuff with a dead buffer.  Or did I miss something?

Ah, right.  Changing the 

    if (INTERACTIVE && !NILP (BVAR (b, filename))
	&& BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))

condition to

    if (INTERACTIVE && BUFFER_LIVE_P (b) && !NILP (BVAR (b, filename))
	&& BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))

would solve the issue.  Either that or adding

  if (!BUFFER_LIVE_P (b))
    return unbind_to (count, Qt);

just prior to the whole if statement which has the side effect of not
calling kill-buffer-hook if any of the kill-buffer-query-functions kills
the buffer, which actually may be desired.

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +----<email/xmpp: mpn@google.com>--------------ooO--(_)--Ooo--

[-- Attachment #2.1: Type: text/plain, Size: 0 bytes --]



[-- Attachment #2.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 835 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCHv4 1/4] `kill-buffer' runs query functions before checking buffer modification.
  2013-06-24 22:35         ` Michal Nazarewicz
@ 2013-06-25  6:47           ` martin rudalics
  0 siblings, 0 replies; 12+ messages in thread
From: martin rudalics @ 2013-06-25  6:47 UTC (permalink / raw)
  To: Michal Nazarewicz; +Cc: Stefan Monnier, emacs-devel

 > Changing the
 >
 >     if (INTERACTIVE && !NILP (BVAR (b, filename))
 > 	&& BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
 >
 > condition to
 >
 >     if (INTERACTIVE && BUFFER_LIVE_P (b) && !NILP (BVAR (b, filename))
 > 	&& BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
 >
 > would solve the issue.  Either that or adding
 >
 >   if (!BUFFER_LIVE_P (b))
 >     return unbind_to (count, Qt);
 >
 > just prior to the whole if statement which has the side effect of not
 > calling kill-buffer-hook if any of the kill-buffer-query-functions kills
 > the buffer, which actually may be desired.

It's the early return I had in mind but changing the condition looks
equally well to me.  Note that we also have to change the Elisp info
entry of `kill-buffer-query-functions'.

martin



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCHv4 0/4] Add `remember-notes' function
  2013-06-24 12:35 [PATCHv4 0/4] Add `remember-notes' function Michal Nazarewicz
                   ` (3 preceding siblings ...)
  2013-06-24 12:35 ` [PATCHv4 4/4] Simplify conditional expression in `find-file-noselect' Michal Nazarewicz
@ 2013-06-30 22:29 ` Stefan Monnier
  2013-07-04 12:56   ` Michal Nazarewicz
  4 siblings, 1 reply; 12+ messages in thread
From: Stefan Monnier @ 2013-06-30 22:29 UTC (permalink / raw)
  To: Michal Nazarewicz; +Cc: emacs-devel

Installed with some changes:
- The setter of remember-data-file uses set-visited-file-name and
  find-buffer-visiting.
- Don't add toggle-remember-notes (not sure why such a command would be
  useful/needed, and it doesn't follow the "remember-" prefix).
- Remove code duplication in remember-append-to-file.
- Add remember-notes--kill-buffer-query only to the affected buffer.
- Don't add remember-notes--buffer.
- Use a new remember-notes-mode minor mode.
- Use nil as special value for remember-notes-initial-major-mode
  (renamed from initial-remember-notes-major-mode to obey the
  "remember-" prefix).
- remember-notes-bury-on-kill renamed from bury-remember-notes-on-kill.
- remember-notes-save-and-bury-buffer, moved and renamed from window.el
  (maybe we should have such a global command, but then I'd like to see
  other uses for it and it should be moved to simple,el, not window.el).


        Stefan



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCHv4 0/4] Add `remember-notes' function
  2013-06-30 22:29 ` [PATCHv4 0/4] Add `remember-notes' function Stefan Monnier
@ 2013-07-04 12:56   ` Michal Nazarewicz
  0 siblings, 0 replies; 12+ messages in thread
From: Michal Nazarewicz @ 2013-07-04 12:56 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 370 bytes --]

On Mon, Jul 01 2013, Stefan Monnier wrote:
> Installed with some changes:  […]

Great!  Thanks!

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +----<email/xmpp: mpn@google.com>--------------ooO--(_)--Ooo--

[-- Attachment #2.1: Type: text/plain, Size: 0 bytes --]



[-- Attachment #2.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 835 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2013-07-04 12:56 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-24 12:35 [PATCHv4 0/4] Add `remember-notes' function Michal Nazarewicz
2013-06-24 12:35 ` [PATCHv4 1/4] `kill-buffer' runs query functions before checking buffer modification Michal Nazarewicz
2013-06-24 17:05   ` martin rudalics
2013-06-24 18:31     ` Michal Nazarewicz
2013-06-24 20:57       ` martin rudalics
2013-06-24 22:35         ` Michal Nazarewicz
2013-06-25  6:47           ` martin rudalics
2013-06-24 12:35 ` [PATCHv4 2/4] `remember-append-to-file' appending to buffer bug fix Michal Nazarewicz
2013-06-24 12:35 ` [PATCHv4 3/4] Add `remember-notes' function to store notes across Emacs restarts Michal Nazarewicz
2013-06-24 12:35 ` [PATCHv4 4/4] Simplify conditional expression in `find-file-noselect' Michal Nazarewicz
2013-06-30 22:29 ` [PATCHv4 0/4] Add `remember-notes' function Stefan Monnier
2013-07-04 12:56   ` Michal Nazarewicz

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).