From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thien-Thi Nguyen Newsgroups: gmane.emacs.devel Subject: Re: [PATCH updated] Support for filesystem watching (inotify) Date: Sat, 04 Jun 2011 22:10:45 +0200 Message-ID: <8762olmk6y.fsf@ambire.localdomain> References: <201106040034.15598.ruediger@c-plusplus.de> <831uz9esv1.fsf@gnu.org> <201106041913.09203.ruediger@c-plusplus.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1307218572 11798 80.91.229.12 (4 Jun 2011 20:16:12 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 4 Jun 2011 20:16:12 +0000 (UTC) Cc: emacs-devel@gnu.org To: =?utf-8?Q?R=C3=BCdiger?= Sonderfeld Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jun 04 22:16:07 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QSxGR-0007FH-6G for ged-emacs-devel@m.gmane.org; Sat, 04 Jun 2011 22:16:07 +0200 Original-Received: from localhost ([::1]:37380 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSxGQ-0007q2-6Y for ged-emacs-devel@m.gmane.org; Sat, 04 Jun 2011 16:16:06 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:60739) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSxBm-0007Hw-5h for emacs-devel@gnu.org; Sat, 04 Jun 2011 16:11:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QSxBk-0000sw-0e for emacs-devel@gnu.org; Sat, 04 Jun 2011 16:11:17 -0400 Original-Received: from smtp208.alice.it ([82.57.200.104]:54163) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSxBj-0000j2-Gw for emacs-devel@gnu.org; Sat, 04 Jun 2011 16:11:15 -0400 Original-Received: from ambire.localdomain (82.58.3.236) by smtp208.alice.it (8.5.124.08) id 4DE64DF1003EBFCB; Sat, 4 Jun 2011 22:10:55 +0200 Original-Received: from ttn by ambire.localdomain with local (Exim 4.69) (envelope-from ) id 1QSxBG-0001pG-GE; Sat, 04 Jun 2011 22:10:46 +0200 In-Reply-To: <201106041913.09203.ruediger@c-plusplus.de> (=?utf-8?Q?=22R?= =?utf-8?Q?=C3=BCdiger?= Sonderfeld"'s message of "Sat, 4 Jun 2011 19:13:08 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 82.57.200.104 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:140181 Archived-At: () R=C3=BCdiger Sonderfeld () Sat, 4 Jun 2011 19:13:08 +0200 +DEFUN ("file-watch", Ffile_watch, Sfile_watch, 3, MANY, 0, + doc: /* Watch a file or directory. + +file-watch watches the file or directory given in FILENAME. If a chang= e occurs +CALLBACK is called with FILENAME as first argument and a list of change= s as second +argument. FLAGS can be + +:modify -- notify when a file is modified or created. + +:move -- notify when a file/directory is moved. + +:attrib -- notify when attributes change. + +:delete -- notify when a file/directory is deleted. + +:all -- notify for all of the above. I think FLAGS should be symbols, not keywords. Furthermore, "flags" is too generic; maybe something like "aspect" or even "what" would be (slightly) better. Instead of =E2=80=98:all=E2=80=99 (or =E2=80=98all=E2= =80=99), consider using =E2=80=98t=E2=80=99. Also, it's cool if the first line names all the args. How about: "Arrange to call FUNC if ASPECT of FILENAME changes." ? +Watching a directory is not recursive. CALLBACK receives the events as= a list +with each list element being a list containing information about an eve= nt. The +first element is a flag symbol. If a directory is watched the second e= lement is +the name of the file that changed. If a file is moved from or to the d= irectory +the second element is either :from or :to and the third element is the = file +name. A fourth element contains a numeric identifier (cookie) that can= be used +to identify matching move operations if a file is moved inside the dire= ctory. + +Example: +(file-watch "foo" #'(lambda (file event) (message "%s %s" file event)) = :all) + +Use `file-unwatch' to stop watching. + +usage: (file-watch FILENAME CALLBACK &rest FLAGS) */) + (size_t nargs, Lisp_Object *args) For upward-compatability, it is better to not use rest-args for these aspects. You should specify one arg ASPECT, document that it can be "either a symbol, one of: ..., or a list of of these symbols". Style preference: I'd prefer CALLBACK to be last so that long lambda expressions need not be (visually) scanned to determine the aspects watched. Consider: (file-watch "foo" t (lambda (name event) ;; LONG ;; COMPLICATED ;; DRAWN-OUT ;; COMPUTATION )) vs (file-watch "foo" (lambda (name event) ;; LONG ;; COMPLICATED ;; DRAWN-OUT ;; COMPUTATION ) t) No big deal, just sympathy for the lone t. + CHECK_STRING(args[0]); Please insert a space between a function (or macro) and its arg list. Generally, (info "(standards) Formatting"). + else /* TODO: should this be an error? */ Yes. + /* TODO: check if file is already in the watch_list. */ Moreover, you need to decide what to do given, for example: (progn (file-watch "foo" 'modify 'notify-modify) (file-watch "foo" 'move 'notify-move)) Is this OK, is this an error, is this "close to" an error? I think a simple "file is already in" check is insufficient. + watch_list =3D Fcons(Fcons(make_number(watchdesc), Flist(2, args)), w= atch_list); You can use =E2=80=98acons=E2=80=99: (acons K V ALIST) =E2=89=A1 (cons (con= s K V) ALIST).