From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michal Nazarewicz Newsgroups: gmane.emacs.devel Subject: [PATCHv4 2/4] `remember-append-to-file' appending to buffer bug fix Date: Mon, 24 Jun 2013 14:35:46 +0200 Message-ID: References: NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1372077400 24107 80.91.229.3 (24 Jun 2013 12:36:40 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 24 Jun 2013 12:36:40 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jun 24 14:36:41 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Ur60f-0003Xg-BL for ged-emacs-devel@m.gmane.org; Mon, 24 Jun 2013 14:36:41 +0200 Original-Received: from localhost ([::1]:36356 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ur60e-0000JU-Nw for ged-emacs-devel@m.gmane.org; Mon, 24 Jun 2013 08:36:40 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46492) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ur60T-0008Ti-JW for emacs-devel@gnu.org; Mon, 24 Jun 2013 08:36:36 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ur60O-0004b8-HR for emacs-devel@gnu.org; Mon, 24 Jun 2013 08:36:29 -0400 Original-Received: from mail-la0-x22b.google.com ([2a00:1450:4010:c03::22b]:38900) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ur60O-0004ZH-79 for emacs-devel@gnu.org; Mon, 24 Jun 2013 08:36:24 -0400 Original-Received: by mail-la0-f43.google.com with SMTP id gw10so10398788lab.30 for ; Mon, 24 Jun 2013 05:36:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:in-reply-to:references; bh=mnIIXhBi1ghTyLPicPUaCpChHgnMiU8wAztXpm52NnM=; b=L9nsLifMQIKsaxbHM/9MAy58B5PTH8lK9MEIe4Mb0B0rwV+zrzHRx0zZCD6V680tsD vqg6HZyxrHRdkYOVWxJ+k5xRzQYERdjNsB5T/TdaVrgmF5MuZUO1ltFcJkfuKn448OID 1ifvSl0WSawRYd7uHv7bmENI8JYcyohbpGFP7sxq28KGna/qcmkYIYbbWIl5E+b79Il3 Lnt2pLjBrbXUv2/ytUOjXmHZxvXK3OWjmjFZ8Z2ABR1mTHjH8t5FNIgProjxp5X/tRIJ 6l7HMtNSrdCyAflS6i2NsHar9n+eEbiVQb3U2o7Gb9640JB9FIsLaRqGovruFz6ajpGc OZmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:in-reply-to:references:x-gm-message-state; bh=mnIIXhBi1ghTyLPicPUaCpChHgnMiU8wAztXpm52NnM=; b=IME8Bpfo7sfRsVJ2ammoJVk4Sd0PFWLpV3AStPE8LDNFRGoEbJBBo07Rrfue6pRfmM yxt/cYQ5t8UUPVyTfvADB936Z66vgeXi4lTi8GfN68AMpKSKCbr5bSUuhMwPKxs1cuxi 5FuvGUkYDaHYO5oxG/vPz6Hj6gZisgmVqdeyhpDcrJvIzMihlfdtVfhbykWbmr3cE/T9 Q1zggKYedSrTGA8PdYpj2NBhZTAOUBQgXDpI/gLPkYGwKfBpjAouu/OMLN20pnrkI+OR 57a3oY854KNXiI/IU5lYtYsNWOBEU11IhvaAUaeJWD3gQm6pxFvyxp+piWWVo4ADZe92 ANkQ== X-Received: by 10.112.204.231 with SMTP id lb7mr12828046lbc.4.1372077383187; Mon, 24 Jun 2013 05:36:23 -0700 (PDT) Original-Received: from mpn-glaptop.corp.google.com ([2620:0:105f:301:2ddc:c978:be37:615e]) by mx.google.com with ESMTPSA id u1sm6672296lag.5.2013.06.24.05.36.21 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 24 Jun 2013 05:36:22 -0700 (PDT) X-Mailer: git-send-email 1.8.3.1 In-Reply-To: In-Reply-To: Original-References: X-Gm-Message-State: ALoCoQknyu3UvrekRwVhVq1oViEhH7HQ19sfdYX7ZGM2+LNeBsVcSC8pYitUHn00PTICI0TvYvwbxdVahOZ28ODBjIjJ1Pa0SzARXCbbrWlNzF98RY4yUwpM+Yq5/VLMdWmDIIx0uegBaHdKCByihT1bFRLTlRZzzelLzPaSMvftZTLR+gBg66N0DE3cCXpDTgV13UMoJ7da X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::22b X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:160932 Archived-At: * 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 + + * 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 * 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