Skip to content

Commit 32763da

Browse files
committed
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.
1 parent d07f177 commit 32763da

File tree

7 files changed

+20
-21
lines changed

7 files changed

+20
-21
lines changed

lisp/autoinsert.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ If this contains a %s, that will be replaced by the matching rule."
171171
(mapatoms (lambda (mode)
172172
(let ((name (symbol-name mode)))
173173
(when (string-match "-mode$" name)
174-
(add-to-list 'modes name)))))
174+
(push name modes)))))
175175
(sort modes 'string<)))
176176
(completing-read "Local variables for mode: " v1 nil t)
177177
" . (("

lisp/cedet/mode-local.el

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -819,14 +819,12 @@ META-NAME is a cons (OVERLOADABLE-SYMBOL . MAJOR-MODE)."
819819
)
820820
;; Order symbols by type
821821
(mapatoms
822-
#'(lambda (s)
823-
(add-to-list (cond
824-
((get s 'mode-variable-flag)
825-
(if (get s 'constant-flag) 'mc 'mv))
826-
((get s 'override-flag)
827-
(if (get s 'constant-flag) 'fo 'ov))
828-
('us))
829-
s))
822+
(lambda (s) (push s (cond
823+
((get s 'mode-variable-flag)
824+
(if (get s 'constant-flag) mc mv))
825+
((get s 'override-flag)
826+
(if (get s 'constant-flag) fo ov))
827+
(t us))))
830828
table)
831829
;; Print symbols by type
832830
(when us

lisp/net/tramp-cache.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ used to cache connection properties of the local machine."
373373
(let ((hash (gethash key tramp-cache-data))
374374
properties)
375375
(when (hash-table-p hash)
376-
(maphash (lambda (x _y) (add-to-list 'properties x 'append)) hash))
376+
(maphash (lambda (x _y) (push x properties)) hash))
377377
properties))
378378
(setq tramp-cache-data-changed t)
379379
(remhash key tramp-cache-data))
@@ -427,7 +427,7 @@ used to cache connection properties of the local machine."
427427
(when (and (tramp-file-name-p key)
428428
(null (tramp-file-name-localname key))
429429
(tramp-connection-property-p key "process-buffer"))
430-
(add-to-list 'result key)))
430+
(push key result)))
431431
tramp-cache-data)
432432
result))
433433

lisp/net/zeroconf.el

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,17 +256,17 @@ supported keys depend on the service type.")
256256
"Return all discovered Avahi service names as list."
257257
(let (result)
258258
(maphash
259-
(lambda (_key value) (add-to-list 'result (zeroconf-service-name value)))
259+
(lambda (_key value) (push (zeroconf-service-name value) result))
260260
zeroconf-services-hash)
261-
result))
261+
(delete-dups result)))
262262

263263
(defun zeroconf-list-service-types ()
264264
"Return all discovered Avahi service types as list."
265265
(let (result)
266266
(maphash
267-
(lambda (_key value) (add-to-list 'result (zeroconf-service-type value)))
267+
(lambda (_key value) (push (zeroconf-service-type value) result))
268268
zeroconf-services-hash)
269-
result))
269+
(delete-dups result)))
270270

271271
(defun zeroconf-list-services (type)
272272
"Return all discovered Avahi services for a given service type TYPE.
@@ -278,9 +278,9 @@ format of SERVICE."
278278
(maphash
279279
(lambda (_key value)
280280
(when (equal type (zeroconf-service-type value))
281-
(add-to-list 'result value)))
281+
(push value result)))
282282
zeroconf-services-hash)
283-
result))
283+
(delete-dups result)))
284284

285285
(defvar zeroconf-service-added-hooks-hash (make-hash-table :test 'equal)
286286
"Hash table of hooks for newly added services.

lisp/org/org.el

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18682,13 +18682,14 @@ With prefix arg UNCOMPILED, load the uncompiled versions."
1868218682
(and (string= org-dir contrib-dir)
1868318683
(org-load-noerror-mustsuffix (concat contrib-dir f)))
1868418684
(and (org-load-noerror-mustsuffix (concat (org-find-library-dir f) f))
18685-
(add-to-list 'load-uncore f 'append)
18685+
(push f load-uncore)
1868618686
't)
1868718687
f))
1868818688
lfeat)))
1868918689
(when load-uncore
1869018690
(message "The following feature%s found in load-path, please check if that's correct:\n%s"
18691-
(if (> (length load-uncore) 1) "s were" " was") load-uncore))
18691+
(if (> (length load-uncore) 1) "s were" " was")
18692+
(reverse load-uncore)))
1869218693
(if load-misses
1869318694
(message "Some error occurred while reloading Org feature%s\n%s\nPlease check *Messages*!\n%s"
1869418695
(if (> (length load-misses) 1) "s" "") load-misses (org-version nil 'full))

lisp/whitespace.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1684,7 +1684,7 @@ cleaning up these problems."
16841684
(mapcar
16851685
#'(lambda (option)
16861686
(when force
1687-
(add-to-list 'style (car option)))
1687+
(push (car option) style))
16881688
(goto-char rstart)
16891689
(let ((regexp
16901690
(cond

test/lisp/emacs-lisp/map-tests.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ Evaluate BODY for each created map.
227227
(with-maps-do map
228228
(let ((result nil))
229229
(map-do (lambda (k v)
230-
(add-to-list 'result (list (int-to-string k) v)))
230+
(push (list (int-to-string k) v) result))
231231
map)
232232
(should (equal result '(("2" 5) ("1" 4) ("0" 3)))))))
233233

0 commit comments

Comments
 (0)