From: Michal Nazarewicz <mina86@mina86.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: [PATCHv4 2/4] `remember-append-to-file' appending to buffer bug fix
Date: Mon, 24 Jun 2013 14:35:46 +0200 [thread overview]
Message-ID: <fd708f3f8a87676c82bf8abc3196386c5f8e048d.1372076606.git.mina86@mina86.com> (raw)
In-Reply-To: <cover.1372076606.git.mina86@mina86.com>
In-Reply-To: <cover.1372076606.git.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).
---
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
next prev parent reply other threads:[~2013-06-24 12:35 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Michal Nazarewicz [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fd708f3f8a87676c82bf8abc3196386c5f8e048d.1372076606.git.mina86@mina86.com \
--to=mina86@mina86.com \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).