From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Modifying a shared file (was: Extending the ecomplete.el data store) Date: Tue, 06 Feb 2018 16:01:59 -0500 Message-ID: References: <87fu6hcm9r.fsf@red-bean.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1517952392 19873 195.159.176.226 (6 Feb 2018 21:26:32 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 6 Feb 2018 21:26:32 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Feb 06 22:26:28 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ejAkm-000415-N6 for ged-emacs-devel@m.gmane.org; Tue, 06 Feb 2018 22:26:12 +0100 Original-Received: from localhost ([::1]:36371 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejAmo-0005Js-4i for ged-emacs-devel@m.gmane.org; Tue, 06 Feb 2018 16:28:18 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54066) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejAOV-0007eZ-N0 for emacs-devel@gnu.org; Tue, 06 Feb 2018 16:03:12 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ejAOS-0007P1-K1 for emacs-devel@gnu.org; Tue, 06 Feb 2018 16:03:11 -0500 Original-Received: from [195.159.176.226] (port=59974 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ejAOS-0007Kz-Cg for emacs-devel@gnu.org; Tue, 06 Feb 2018 16:03:08 -0500 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1ejAM2-0000Cq-8I for emacs-devel@gnu.org; Tue, 06 Feb 2018 22:00:38 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 45 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:SMY0OVI6jKN1lGd0qDFJcM7Qaeg= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.emacs.devel:222594 Archived-At: >> I haven't used ecomplete very much so far, but I've noticed some issues >> which I think are linked to having multiple Emacs sessions use it at the >> same time. I haven't investigated enough to be sure, but in any case >> it's a use case that should be kept in mind. > Yes, ecomplete should check the modification date and reload the data if > it has changed. [ Plus some kind of locking to avoid modifying the file at the same time. ] I'd welcome some new function (defun update-file (file modification) "Apply MODIFICATION to FILE." ...) tho we'd want to avoid re-reading the file if it hasn't been modified since last time. So maybe we need to first define (cl-defstruct file-contents (file nil :type string) (reader nil :type function) (writer nil :type function) timestamp val) and then (defun file-contents-read (file &optional reader writer) "Return a `file-contents` object representing the contents of FILE." (with-temp-buffer (insert-file-contents file) (make-file-contents :file file :reader reader :writer writer :timestamp ... :val (funcall (or reader #'read)))) (defun file-contents-update (fc modification) "Apply MODIFICATION both to FC and to its file." ...) where `modification` is a function that takes the old value and returns a new value (and it might be called several times). -- Stefan