1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-02 08:22:22 +00:00

; Format files from last commit

This commit is contained in:
Michael Albinus 2017-03-26 09:42:40 +02:00
parent 158bb8555d
commit 74129db63d
2 changed files with 26 additions and 27 deletions

View File

@ -42,7 +42,8 @@ could use another implementation.")
(cl-defstruct (file-notify--watch
(:constructor nil)
(:constructor file-notify--watch-make (directory filename callback)))
(:constructor
file-notify--watch-make (directory filename callback)))
;; Watched directory
directory
;; Watched relative filename, nil if watching the directory.
@ -61,14 +62,13 @@ could use another implementation.")
"Hash table for registered file notification descriptors.
A key in this hash table is the descriptor as returned from
`inotify', `kqueue', `gfilenotify', `w32notify' or a file name
handler. The value in the hash table is file-notify--watch
handler. The value in the hash table is `file-notify--watch'
struct.")
(defun file-notify--rm-descriptor (descriptor)
"Remove DESCRIPTOR from `file-notify-descriptors'.
DESCRIPTOR should be an object returned by
`file-notify-add-watch'. If it is registered in
`file-notify-descriptors', a stopped event is sent."
DESCRIPTOR should be an object returned by `file-notify-add-watch'.
If it is registered in `file-notify-descriptors', a stopped event is sent."
(when-let (watch (gethash descriptor file-notify-descriptors))
;; Send `stopped' event.
(unwind-protect
@ -123,8 +123,7 @@ This is available in case a file has been moved."
(and (stringp (nth 3 event))
(directory-file-name
(expand-file-name
(nth 3 event)
(file-notify--watch-directory watch))))))
(nth 3 event) (file-notify--watch-directory watch))))))
;; Cookies are offered by `inotify' only.
(defun file-notify--event-cookie (event)
@ -187,11 +186,13 @@ EVENT is the cadr of the event in `file-notify-handle-event'
((memq action '(attrib link)) 'attribute-changed)
((memq action '(create added)) 'created)
((memq action '(modify modified write)) 'changed)
((memq action '(delete delete-self move-self removed)) 'deleted)
((memq action
'(delete delete-self move-self removed)) 'deleted)
;; Make the event pending.
((memq action '(moved-from renamed-from))
(setq file-notify--pending-event
`((,desc ,action ,file ,(file-notify--event-cookie event))
`((,desc ,action ,file
,(file-notify--event-cookie event))
,(file-notify--watch-callback watch)))
nil)
;; Look for pending event.
@ -222,8 +223,8 @@ EVENT is the cadr of the event in `file-notify-handle-event'
;; Apply callback.
(when (and action
(or
;; If there is no relative file name for that watch,
;; we watch the whole directory.
;; If there is no relative file name for that
;; watch, we watch the whole directory.
(null (file-notify--watch-filename watch))
;; File matches.
(string-equal
@ -241,8 +242,7 @@ EVENT is the cadr of the event in `file-notify-handle-event'
(file-name-nondirectory file1)))))
;;(message
;;"file-notify-callback %S %S %S %S %S"
;;desc
;;action file file1 watch)
;;desc action file file1 watch)
(if file1
(funcall (file-notify--watch-callback watch)
`(,desc ,action ,file ,file1))
@ -382,8 +382,8 @@ DESCRIPTOR should be an object returned by `file-notify-add-watch'."
'file-notify-rm-watch)))
(condition-case nil
(if handler
;; A file name handler could exist even if there is no local
;; file notification support.
;; A file name handler could exist even if there is no
;; local file notification support.
(funcall handler 'file-notify-rm-watch descriptor)
(funcall

View File

@ -61,7 +61,7 @@ static int inotifyfd = -1;
IN_ONLYDIR
Format: (descriptor . ((id filename callback mask) ...))
*/
*/
static Lisp_Object watch_list;
static Lisp_Object
@ -204,9 +204,10 @@ inotifyevent_to_event (Lisp_Object watch, struct inotify_event const *ev)
/* Add a new watch to watch-descriptor WD watching FILENAME and using
CALLBACK. Returns a cons (DESCRIPTOR . ID) uniquely identifying the
new watch. */
new watch. */
static Lisp_Object
add_watch (int wd, Lisp_Object filename, Lisp_Object aspect, Lisp_Object callback)
add_watch (int wd, Lisp_Object filename,
Lisp_Object aspect, Lisp_Object callback)
{
Lisp_Object descriptor = make_number (wd);
Lisp_Object elt = Fassoc (descriptor, watch_list);
@ -260,7 +261,7 @@ remove_descriptor (Lisp_Object descriptor, bool invalid_p)
}
}
/* Remove watch associated with (descriptor, id). */
/* Remove watch associated with (descriptor, id). */
static void
remove_watch (Lisp_Object descriptor, Lisp_Object id)
{
@ -273,7 +274,7 @@ remove_watch (Lisp_Object descriptor, Lisp_Object id)
if (! NILP (watch))
XSETCDR (elt, Fdelete (watch, XCDR (elt)));
/* Remove the descriptor if noone is watching it. */
/* Remove the descriptor if noone is watching it. */
if (NILP (XCDR (elt)))
remove_descriptor (descriptor, false);
}
@ -378,13 +379,12 @@ unmount
If a directory is watched then NAME is the name of file that caused the event.
COOKIE is an object that can be compared using `equal' to identify two matchingt
COOKIE is an object that can be compared using `equal' to identify two matching
renames (moved-from and moved-to).
See inotify(7) and inotify_add_watch(2) for further information. The inotify fd
is managed internally and there is no corresponding inotify_init. Use
`inotify-rm-watch' to remove a watch.
*/)
`inotify-rm-watch' to remove a watch. */)
(Lisp_Object filename, Lisp_Object aspect, Lisp_Object callback)
{
Lisp_Object encoded_file_name;
@ -417,8 +417,7 @@ DEFUN ("inotify-rm-watch", Finotify_rm_watch, Sinotify_rm_watch, 1, 1, 0,
WATCH-DESCRIPTOR should be an object returned by `inotify-add-watch'.
See inotify_rm_watch(2) for more information.
*/)
See inotify_rm_watch(2) for more information. */)
(Lisp_Object watch_descriptor)
{
@ -462,13 +461,13 @@ it invalid. */)
#ifdef INOTIFY_DEBUG
DEFUN ("inotify-watch-list", Finotify_watch_list, Sinotify_watch_list, 0, 0, 0,
doc: /* Return a copy of the internal watch_list. */)
doc: /* Return a copy of the internal watch_list. */)
{
return Fcopy_sequence (watch_list);
}
DEFUN ("inotify-allocated-p", Finotify_allocated_p, Sinotify_allocated_p, 0, 0, 0,
doc: /* Return non-nil, if a inotify instance is allocated. */)
doc: /* Return non-nil, if a inotify instance is allocated. */)
{
return inotifyfd < 0 ? Qnil : Qt;
}