From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Thomas Fitzsimmons Newsgroups: gmane.emacs.bugs Subject: bug#35645: Fix icalendar--add-diary-entry/diary-make-entry interaction Date: Wed, 08 May 2019 23:40:30 -0400 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="22053"; mail-complaints-to="usenet@blaine.gmane.org" To: 35645@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu May 09 05:33:16 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hOZo2-0005Rl-0X for geb-bug-gnu-emacs@m.gmane.org; Thu, 09 May 2019 05:33:14 +0200 Original-Received: from localhost ([127.0.0.1]:47242 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOZo0-0003On-PF for geb-bug-gnu-emacs@m.gmane.org; Wed, 08 May 2019 23:33:12 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:53121) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOZnr-0003Og-8o for bug-gnu-emacs@gnu.org; Wed, 08 May 2019 23:33:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOZnq-0000Tf-2Z for bug-gnu-emacs@gnu.org; Wed, 08 May 2019 23:33:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49164) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOZnp-0000TY-UQ for bug-gnu-emacs@gnu.org; Wed, 08 May 2019 23:33:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hOZnp-0002j2-Qd for bug-gnu-emacs@gnu.org; Wed, 08 May 2019 23:33:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Thomas Fitzsimmons Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 09 May 2019 03:33:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 35645 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.155737276710453 (code B ref -1); Thu, 09 May 2019 03:33:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 9 May 2019 03:32:47 +0000 Original-Received: from localhost ([127.0.0.1]:34475 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hOZna-0002iW-L0 for submit@debbugs.gnu.org; Wed, 08 May 2019 23:32:46 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:38711) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hOZnZ-0002iI-9k for submit@debbugs.gnu.org; Wed, 08 May 2019 23:32:45 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:54535) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hOZnT-0000Ij-Q8 for submit@debbugs.gnu.org; Wed, 08 May 2019 23:32:39 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:53093) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOZnS-0003MS-DF for bug-gnu-emacs@gnu.org; Wed, 08 May 2019 23:32:39 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOZnR-0000Gb-3J for bug-gnu-emacs@gnu.org; Wed, 08 May 2019 23:32:38 -0400 Original-Received: from mail-it1-x12d.google.com ([2607:f8b0:4864:20::12d]:54248) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOZnQ-0000Fx-Kv for bug-gnu-emacs@gnu.org; Wed, 08 May 2019 23:32:37 -0400 Original-Received: by mail-it1-x12d.google.com with SMTP id l10so1227576iti.3 for ; Wed, 08 May 2019 20:32:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fitzsim-org.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:mime-version; bh=PjaQQS2qu4fnk5Yf1seBVh3V/aFwGI9jCrZ8EfYbhyM=; b=rVN+7xGkkqXmZBY+BHFkDNat+Mq2uTXx7X/gsxNCkRcMO8x7o6v+AVn7zjwYYAX9yA K7pYwBfDrs5dBSiIMxwrDKRp6HccYdtPcpUbv9WVda/0b8H8En8iSFhRMXCKs1fWXBu9 g20dkfE2W0OrKGHqk9JD3w3D+8XMb7pEmby5S7nUtS4+NYCpWME7GHY8p1gLRGja8QSw OPZ3irvc4/bsZfBxDmrdCOJXya2pvlJgKqPkY4+N/gUXlqZ2I4glaDXCy3bIOxdEFURH ox5TQ/hHhMrNio1aviRNj4ezE1iLgHMT2lSVsLfYyYVE/6zjp8jwsvC496c//nANEhgg /gDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=PjaQQS2qu4fnk5Yf1seBVh3V/aFwGI9jCrZ8EfYbhyM=; b=cLVbAEJyTT0IYhNXa1LJTe2NKkn9XLYsXbm8nCDnwzCsrIXKYipiB1mfL/sGfwmxWR leNaXhQH8lzXK3B16iWpoYoiteISuoFw/Puj8eOUz3CjQB14TEcqTx7tk9mJzI481ZGL C9YE6PCCgw6yHoCxKFrqbBz6Xy7x9eyu2fSWEkq/vCzXMkNwqctuHOTGdqQnkCC0lqXx Dc2zUB9yUsVqmJsTGijqu2ZVpKg6y14jjt0qlAYWnatPm9Aj40uOhbbfQG/zjXHp3O4r 12gyCGIm9We6BXvO6Ngawdj7Og0kR+N2nhrtWIF6KCHoJolosS0vikkouiPa0XSDO46A UOtA== X-Gm-Message-State: APjAAAX/EoyIgCGL+UeZiu1lFtj7/EaZAt0NU1gxs55XDL58Djf9hZup Dhcd0s3PHgisDkCLrnYYZX8TsfLvfMk= X-Google-Smtp-Source: APXvYqxiMurPBchZuzcAcxWDC648Gj7K0Kf/P/kjpUyB6hVbT4113G7MKZ2zofNelEqcEPVOU6FC3w== X-Received: by 2002:a24:6416:: with SMTP id t22mr1135417itc.176.1557372754650; Wed, 08 May 2019 20:32:34 -0700 (PDT) Original-Received: from localhost.localdomain (69-165-165-189.dsl.teksavvy.com. [69.165.165.189]) by smtp.gmail.com with ESMTPSA id y4sm432256iof.58.2019.05.08.20.32.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 May 2019 20:32:33 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:158967 Archived-At: --=-=-= Content-Type: text/plain For Excorporate's diary integration I had to add some advice to work around the side effects of a diary-make-entry workaround in icalendar--add-diary-entry, and side effects of diary-make-entry itself. I'm filing this bug report to try to eliminate the need for any of these workarounds. diary-make-entry adds a trailing space to its entry. icalendar--add-diary-entry works around this by deleting the trailing space. It saves the window excursion, but diary-make-entry still leaves the diary file where (other-buffer (current-buffer)) will return it, which is a usability bug. The attached patch, icalendar-diary-make-entry-fix-1.patch, adds omit-trailing-space and do-not-show parameters to diary-make-entry to allow it to operate more like a library function and less like an interactive function. To keep the code mostly the same (so that I don't need to factor out another function), I've changed the original logic by adding a with-current-buffer wrapper, as shown in simplified form in diary-make-entry-with-current-buffer.patch. I'm hoping this keeps the default diary-make-entry logic exactly the same, but I'd like confirmation from someone more familiar with the subtleties of window and buffer manipulation. Thanks, Thomas --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename=icalendar-diary-make-entry-fix-1.patch Content-Transfer-Encoding: quoted-printable diff --git a/lisp/calendar/diary-lib.el b/lisp/calendar/diary-lib.el index 1be2a05eee..848ac224fb 100644 --- a/lisp/calendar/diary-lib.el +++ b/lisp/calendar/diary-lib.el @@ -2062,27 +2062,34 @@ diary-remind ;;; Diary insertion functions. =20 ;;;###cal-autoload -(defun diary-make-entry (string &optional nonmarking file) +(defun diary-make-entry (string &optional nonmarking file omit-trailing-sp= ace + do-not-show) "Insert a diary entry STRING which may be NONMARKING in FILE. If omitted, NONMARKING defaults to nil and FILE defaults to -`diary-file'." - (let ((pop-up-frames (or pop-up-frames (window-dedicated-p)))) - (find-file-other-window (or file diary-file))) - (when (eq major-mode (default-value 'major-mode)) (diary-mode)) - (widen) - (diary-unhide-everything) - (goto-char (point-max)) - (when (let ((case-fold-search t)) - (search-backward "Local Variables:" - (max (- (point-max) 3000) (point-min)) - t)) - (beginning-of-line) - (insert "\n") - (forward-line -1)) - (insert - (if (bolp) "" "\n") - (if nonmarking diary-nonmarking-symbol "") - string " ")) +`diary-file'. If OMIT-TRAILING-SPACE is non-nil, then do not add +a trailing space to the entry. If DO-NOT-SHOW is non-nil, do not +show the diary buffer." + (with-current-buffer + (let ((diary-file-name (or file diary-file))) + (if do-not-show + (find-file-noselect diary-file-name) + (let ((pop-up-frames (or pop-up-frames (window-dedicated-p)))) + (find-file-other-window diary-file-name)))) + (when (eq major-mode (default-value 'major-mode)) (diary-mode)) + (widen) + (diary-unhide-everything) + (goto-char (point-max)) + (when (let ((case-fold-search t)) + (search-backward "Local Variables:" + (max (- (point-max) 3000) (point-min)) + t)) + (beginning-of-line) + (insert "\n") + (forward-line -1)) + (insert + (if (bolp) "" "\n") + (if nonmarking diary-nonmarking-symbol "") + string (if omit-trailing-space "" " ")))) =20 ;;;###cal-autoload (defun diary-insert-entry (arg &optional event) diff --git a/lisp/calendar/icalendar.el b/lisp/calendar/icalendar.el index a8fd765129..17316ddbbd 100644 --- a/lisp/calendar/icalendar.el +++ b/lisp/calendar/icalendar.el @@ -2502,20 +2502,10 @@ icalendar--add-diary-entry (when summary (setq non-marking (y-or-n-p (format "Make appointment non-marking? ")))) - (save-window-excursion - (unless diary-filename - (setq diary-filename - (read-file-name "Add appointment to this diary file: "))) - ;; Note: diary-make-entry will add a trailing blank char.... :( - (funcall (if (fboundp 'diary-make-entry) - 'diary-make-entry - 'make-diary-entry) - string non-marking diary-filename))) - ;; W=C3=BCrgaround to remove the trailing blank char - (with-current-buffer (find-file diary-filename) - (goto-char (point-max)) - (if (=3D (char-before) ? ) - (delete-char -1))) + (unless diary-filename + (setq diary-filename + (read-file-name "Add appointment to this diary file: "))) + (diary-make-entry string non-marking diary-filename t t)) ;; return diary-filename in case it has been changed interactively diary-filename) =20 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=diary-make-entry-with-current-buffer.patch diff --git a/lisp/calendar/diary-lib.el b/lisp/calendar/diary-lib.el index 1be2a05eee..c88d04ab21 100644 --- a/lisp/calendar/diary-lib.el +++ b/lisp/calendar/diary-lib.el @@ -2066,8 +2066,9 @@ diary-make-entry "Insert a diary entry STRING which may be NONMARKING in FILE. If omitted, NONMARKING defaults to nil and FILE defaults to `diary-file'." - (let ((pop-up-frames (or pop-up-frames (window-dedicated-p)))) - (find-file-other-window (or file diary-file))) + (with-current-buffer + (let ((pop-up-frames (or pop-up-frames (window-dedicated-p)))) + (find-file-other-window (or file diary-file))) (when (eq major-mode (default-value 'major-mode)) (diary-mode)) (widen) (diary-unhide-everything) @@ -2082,7 +2083,7 @@ diary-make-entry (insert (if (bolp) "" "\n") (if nonmarking diary-nonmarking-symbol "") - string " ")) + string " "))) ;;;###cal-autoload (defun diary-insert-entry (arg &optional event) --=-=-=--