Replace add-to-list to lexical variable with push (bug#39373)

Since 'add-to-list', being a plain function, cannot access lexical
variables, such use must be rewritten for correctness.
(Some instances actually do work thanks to a compiler macro,
but it's not something code should rely on.)

* lisp/autoinsert.el (auto-insert-alist):
* lisp/cedet/mode-local.el (mode-local-print-bindings):
* lisp/net/tramp-cache.el (tramp-flush-connection-properties)
(tramp-list-connections):
* lisp/net/zeroconf.el (zeroconf-list-service-names)
(zeroconf-list-service-types, zeroconf-list-services):
* lisp/org/org.el (org-reload):
* lisp/whitespace.el (whitespace-report-region):
* test/lisp/emacs-lisp/map-tests.el (test-map-do):
Replace add-to-list with push.
This commit is contained in:
Mattias Engdegård 2020-02-01 18:07:32 +01:00
parent d07f177382
commit 32763dac46
7 changed files with 20 additions and 21 deletions

View file

@ -171,7 +171,7 @@ If this contains a %s, that will be replaced by the matching rule."
(mapatoms (lambda (mode) (mapatoms (lambda (mode)
(let ((name (symbol-name mode))) (let ((name (symbol-name mode)))
(when (string-match "-mode$" name) (when (string-match "-mode$" name)
(add-to-list 'modes name))))) (push name modes)))))
(sort modes 'string<))) (sort modes 'string<)))
(completing-read "Local variables for mode: " v1 nil t) (completing-read "Local variables for mode: " v1 nil t)
" . ((" " . (("

View file

@ -819,14 +819,12 @@ META-NAME is a cons (OVERLOADABLE-SYMBOL . MAJOR-MODE)."
) )
;; Order symbols by type ;; Order symbols by type
(mapatoms (mapatoms
#'(lambda (s) (lambda (s) (push s (cond
(add-to-list (cond
((get s 'mode-variable-flag) ((get s 'mode-variable-flag)
(if (get s 'constant-flag) 'mc 'mv)) (if (get s 'constant-flag) mc mv))
((get s 'override-flag) ((get s 'override-flag)
(if (get s 'constant-flag) 'fo 'ov)) (if (get s 'constant-flag) fo ov))
('us)) (t us))))
s))
table) table)
;; Print symbols by type ;; Print symbols by type
(when us (when us

View file

@ -373,7 +373,7 @@ used to cache connection properties of the local machine."
(let ((hash (gethash key tramp-cache-data)) (let ((hash (gethash key tramp-cache-data))
properties) properties)
(when (hash-table-p hash) (when (hash-table-p hash)
(maphash (lambda (x _y) (add-to-list 'properties x 'append)) hash)) (maphash (lambda (x _y) (push x properties)) hash))
properties)) properties))
(setq tramp-cache-data-changed t) (setq tramp-cache-data-changed t)
(remhash key tramp-cache-data)) (remhash key tramp-cache-data))
@ -427,7 +427,7 @@ used to cache connection properties of the local machine."
(when (and (tramp-file-name-p key) (when (and (tramp-file-name-p key)
(null (tramp-file-name-localname key)) (null (tramp-file-name-localname key))
(tramp-connection-property-p key "process-buffer")) (tramp-connection-property-p key "process-buffer"))
(add-to-list 'result key))) (push key result)))
tramp-cache-data) tramp-cache-data)
result)) result))

View file

@ -256,17 +256,17 @@ supported keys depend on the service type.")
"Return all discovered Avahi service names as list." "Return all discovered Avahi service names as list."
(let (result) (let (result)
(maphash (maphash
(lambda (_key value) (add-to-list 'result (zeroconf-service-name value))) (lambda (_key value) (push (zeroconf-service-name value) result))
zeroconf-services-hash) zeroconf-services-hash)
result)) (delete-dups result)))
(defun zeroconf-list-service-types () (defun zeroconf-list-service-types ()
"Return all discovered Avahi service types as list." "Return all discovered Avahi service types as list."
(let (result) (let (result)
(maphash (maphash
(lambda (_key value) (add-to-list 'result (zeroconf-service-type value))) (lambda (_key value) (push (zeroconf-service-type value) result))
zeroconf-services-hash) zeroconf-services-hash)
result)) (delete-dups result)))
(defun zeroconf-list-services (type) (defun zeroconf-list-services (type)
"Return all discovered Avahi services for a given service type TYPE. "Return all discovered Avahi services for a given service type TYPE.
@ -278,9 +278,9 @@ format of SERVICE."
(maphash (maphash
(lambda (_key value) (lambda (_key value)
(when (equal type (zeroconf-service-type value)) (when (equal type (zeroconf-service-type value))
(add-to-list 'result value))) (push value result)))
zeroconf-services-hash) zeroconf-services-hash)
result)) (delete-dups result)))
(defvar zeroconf-service-added-hooks-hash (make-hash-table :test 'equal) (defvar zeroconf-service-added-hooks-hash (make-hash-table :test 'equal)
"Hash table of hooks for newly added services. "Hash table of hooks for newly added services.

View file

@ -18682,13 +18682,14 @@ With prefix arg UNCOMPILED, load the uncompiled versions."
(and (string= org-dir contrib-dir) (and (string= org-dir contrib-dir)
(org-load-noerror-mustsuffix (concat contrib-dir f))) (org-load-noerror-mustsuffix (concat contrib-dir f)))
(and (org-load-noerror-mustsuffix (concat (org-find-library-dir f) f)) (and (org-load-noerror-mustsuffix (concat (org-find-library-dir f) f))
(add-to-list 'load-uncore f 'append) (push f load-uncore)
't) 't)
f)) f))
lfeat))) lfeat)))
(when load-uncore (when load-uncore
(message "The following feature%s found in load-path, please check if that's correct:\n%s" (message "The following feature%s found in load-path, please check if that's correct:\n%s"
(if (> (length load-uncore) 1) "s were" " was") load-uncore)) (if (> (length load-uncore) 1) "s were" " was")
(reverse load-uncore)))
(if load-misses (if load-misses
(message "Some error occurred while reloading Org feature%s\n%s\nPlease check *Messages*!\n%s" (message "Some error occurred while reloading Org feature%s\n%s\nPlease check *Messages*!\n%s"
(if (> (length load-misses) 1) "s" "") load-misses (org-version nil 'full)) (if (> (length load-misses) 1) "s" "") load-misses (org-version nil 'full))

View file

@ -1684,7 +1684,7 @@ cleaning up these problems."
(mapcar (mapcar
#'(lambda (option) #'(lambda (option)
(when force (when force
(add-to-list 'style (car option))) (push (car option) style))
(goto-char rstart) (goto-char rstart)
(let ((regexp (let ((regexp
(cond (cond

View file

@ -227,7 +227,7 @@ Evaluate BODY for each created map.
(with-maps-do map (with-maps-do map
(let ((result nil)) (let ((result nil))
(map-do (lambda (k v) (map-do (lambda (k v)
(add-to-list 'result (list (int-to-string k) v))) (push (list (int-to-string k) v) result))
map) map)
(should (equal result '(("2" 5) ("1" 4) ("0" 3))))))) (should (equal result '(("2" 5) ("1" 4) ("0" 3)))))))