summaryrefslogtreecommitdiff
path: root/lisp/net/zeroconf.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2017-01-04 00:40:45 -0500
committerStefan Monnier <monnier@iro.umontreal.ca>2017-01-04 00:40:45 -0500
commit2ec41c415f39990561cc9da4c9bad0b69bfad489 (patch)
tree01a5234df9caa1e9db39d76bf31ba8a3a622298c /lisp/net/zeroconf.el
parentf49f8c1454e19123572a071bf582271c70d28f01 (diff)
Avoid add-to-list on local variables
* lisp/gnus/nnir.el: Use lexical-binding and cl-lib. (nnir-retrieve-headers): Use pcase. (nnir-search-thread): Avoid add-to-list on local variables. * lisp/gnus/smime.el: Use lexical-binding and cl-lib. (smime-verify-region): Avoid add-to-list on local variables. * lisp/mail/undigest.el: Use lexical-binding and cl-lib. (rmail-digest-parse-mime, rmail-digest-rfc1153) (rmail-digest-parse-rfc934): Avoid add-to-list on local variable. * lisp/net/ldap.el (ldap-search): Move init into declaration. * lisp/net/newst-backend.el (newsticker--cache-add): Avoid add-to-list on local variables; Simplify code with `assq'. * lisp/net/zeroconf.el: Use lexical-binding and cl-lib. (dbus-debug): Remove declaration, unused. (zeroconf-service-add-hook, zeroconf-service-remove-hook) (zeroconf-service-browser-handler, zeroconf-publish-service): Avoid add-to-list and *-hook on local variables. * lisp/org/org-archive.el (org-all-archive-files): * lisp/org/org-agenda.el (org-agenda-get-restriction-and-command): Avoid add-to-list on local variables. * lisp/org/ox-publish.el (org-publish--run-functions): New function. (org-publish-projects): Use it to avoid run-hooks on a local variable. (org-publish-cache-file-needs-publishing): Avoid add-to-list on local variables. * lisp/progmodes/ada-prj.el: Use setq instead of (set '...). (ada-prj-load-from-file): Avoid add-to-list on local variables. * lisp/progmodes/ada-xref.el (ada-initialize-runtime-library): Simplify. (ada-gnat-parse-gpr, ada-parse-prj-file-1) (ada-xref-find-in-modified-ali): Avoid add-to-list on local variables. * lisp/progmodes/idlw-shell.el (idlwave-shell-update-bp-overlays): Avoid add-to-list on local variables.
Diffstat (limited to 'lisp/net/zeroconf.el')
-rw-r--r--lisp/net/zeroconf.el46
1 files changed, 19 insertions, 27 deletions
diff --git a/lisp/net/zeroconf.el b/lisp/net/zeroconf.el
index 3db65c624eb..37816bb8881 100644
--- a/lisp/net/zeroconf.el
+++ b/lisp/net/zeroconf.el
@@ -1,4 +1,4 @@
-;;; zeroconf.el --- Service browser using Avahi.
+;;; zeroconf.el --- Service browser using Avahi. -*- lexical-binding:t -*-
;; Copyright (C) 2008-2017 Free Software Foundation, Inc.
@@ -99,10 +99,7 @@
;;; Code:
-;; Pacify byte-compiler. D-Bus support in the Emacs core can be
-;; disabled with configuration option "--without-dbus". Declare used
-;; subroutines and variables of `dbus' therefore.
-(defvar dbus-debug)
+(eval-when-compile (require 'cl-lib))
(require 'dbus)
@@ -296,7 +293,7 @@ The key of an entry is a service type.")
(defun zeroconf-service-add-hook (type event function)
"Add FUNCTION to the hook of service type TYPE.
-EVENT must be either :new or :removed, indicating whether
+EVENT must be either `:new' or `:removed', indicating whether
FUNCTION shall be called when a new service has been newly
detected, or removed.
@@ -320,15 +317,13 @@ The attributes of SERVICE can be retrieved via the functions
(cond
((equal event :new)
- (let ((l-hook (gethash type zeroconf-service-added-hooks-hash nil)))
- (add-hook 'l-hook function)
- (puthash type l-hook zeroconf-service-added-hooks-hash)
- (dolist (service (zeroconf-list-services type))
- (funcall function service))))
+ (cl-pushnew function (gethash type zeroconf-service-added-hooks-hash)
+ :test #'equal)
+ (dolist (service (zeroconf-list-services type))
+ (funcall function service)))
((equal event :removed)
- (let ((l-hook (gethash type zeroconf-service-removed-hooks-hash nil)))
- (add-hook 'l-hook function)
- (puthash type l-hook zeroconf-service-removed-hooks-hash)))
+ (cl-pushnew function (gethash type zeroconf-service-removed-hooks-hash)
+ :test #'equal))
(t (error "EVENT must be either `:new' or `:removed'"))))
(defun zeroconf-service-remove-hook (type event function)
@@ -336,16 +331,13 @@ The attributes of SERVICE can be retrieved via the functions
EVENT must be either :new or :removed and has to match the event
type used when registering FUNCTION."
- (let* ((table (cond
- ((equal event :new)
- zeroconf-service-added-hooks-hash)
- ((equal event :removed)
- zeroconf-service-removed-hooks-hash)
- (t (error "EVENT must be either `:new' or `:removed'"))))
- (l-hook (gethash type table nil)))
- (remove-hook 'l-hook function)
- (if l-hook
- (puthash type l-hook table)
+ (let* ((table (pcase event
+ (:new zeroconf-service-added-hooks-hash)
+ (:removed zeroconf-service-removed-hooks-hash)
+ (_ (error "EVENT must be either `:new' or `:removed'"))))
+ (functions (remove function (gethash type table))))
+ (if functions
+ (puthash type functions table)
(remhash type table))))
(defun zeroconf-get-host ()
@@ -580,13 +572,13 @@ DOMAIN is nil, the local domain is used."
((string-equal (dbus-event-member-name last-input-event) "ItemNew")
;; Add new service.
(puthash key val zeroconf-services-hash)
- (run-hook-with-args 'ahook val))
+ (dolist (f ahook) (funcall f val)))
((string-equal (dbus-event-member-name last-input-event) "ItemRemove")
;; Remove the service.
(remhash key zeroconf-services-hash)
(remhash key zeroconf-resolved-services-hash)
- (run-hook-with-args 'rhook val)))))
+ (dolist (f rhook) (funcall f val))))))
(defun zeroconf-register-service-resolver (name type)
"Register a service resolver at the Avahi daemon."
@@ -653,7 +645,7 @@ For the description of arguments, see `zeroconf-resolved-services-hash'."
;; The TXT field has the signature "as". Transform to "aay".
(dolist (elt txt)
- (add-to-list 'result (dbus-string-to-byte-array elt)))
+ (cl-pushnew (dbus-string-to-byte-array elt) result :test #'equal))
;; Add the service.
(dbus-call-method