]> git.eshelyaron.com Git - emacs.git/commitdiff
Replace add-to-list to lexical variable with push (bug#39373)
authorMattias Engdegård <mattiase@acm.org>
Sat, 1 Feb 2020 17:07:32 +0000 (18:07 +0100)
committerMattias Engdegård <mattiase@acm.org>
Sat, 1 Feb 2020 21:27:23 +0000 (22:27 +0100)
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.

lisp/autoinsert.el
lisp/cedet/mode-local.el
lisp/net/tramp-cache.el
lisp/net/zeroconf.el
lisp/org/org.el
lisp/whitespace.el
test/lisp/emacs-lisp/map-tests.el

index 9bc3aad27855b077ca62cdf4a83d7a5756d9c5ae..25961d41089793224919acbd75b5242ba4358337 100644 (file)
@@ -171,7 +171,7 @@ If this contains a %s, that will be replaced by the matching rule."
                  (mapatoms (lambda (mode)
                              (let ((name (symbol-name mode)))
                                (when (string-match "-mode$" name)
-                                 (add-to-list 'modes name)))))
+                                 (push name modes)))))
                  (sort modes 'string<)))
      (completing-read "Local variables for mode: " v1 nil t)
      " . (("
index a6e143cfcd65ddc0a6c85b8baf0c82b3f69f6427..a1aea30c20d803041e4574748e939a9a8f71c8ad 100644 (file)
@@ -819,14 +819,12 @@ META-NAME is a cons (OVERLOADABLE-SYMBOL . MAJOR-MODE)."
         )
     ;; Order symbols by type
     (mapatoms
-     #'(lambda (s)
-         (add-to-list (cond
-                       ((get s 'mode-variable-flag)
-                        (if (get s 'constant-flag) 'mc 'mv))
-                       ((get s 'override-flag)
-                        (if (get s 'constant-flag) 'fo 'ov))
-                       ('us))
-                      s))
+     (lambda (s) (push s (cond
+                          ((get s 'mode-variable-flag)
+                           (if (get s 'constant-flag) mc mv))
+                          ((get s 'override-flag)
+                           (if (get s 'constant-flag) fo ov))
+                          (t us))))
      table)
     ;; Print symbols by type
     (when us
index b81a1a23d5f8e3ba3351181e4061641a786f3fc0..62e25fa1f082bf00561451534b80dc14ed6e1baa 100644 (file)
@@ -373,7 +373,7 @@ used to cache connection properties of the local machine."
    (let ((hash (gethash key tramp-cache-data))
         properties)
      (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))
   (setq tramp-cache-data-changed t)
   (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)
                    (null (tramp-file-name-localname key))
                    (tramp-connection-property-p key "process-buffer"))
-          (add-to-list 'result key)))
+          (push key result)))
        tramp-cache-data)
       result))
 
index b8becd712f5a06c0df7c24db72eb2440a8257b89..cb3c0f2a7ee57f5744b5ed129df2f0c56d6f3a6f 100644 (file)
@@ -256,17 +256,17 @@ supported keys depend on the service type.")
   "Return all discovered Avahi service names as list."
   (let (result)
     (maphash
-     (lambda (_key value) (add-to-list 'result (zeroconf-service-name value)))
+     (lambda (_key value) (push (zeroconf-service-name value) result))
      zeroconf-services-hash)
-    result))
+    (delete-dups result)))
 
 (defun zeroconf-list-service-types ()
   "Return all discovered Avahi service types as list."
   (let (result)
     (maphash
-     (lambda (_key value) (add-to-list 'result (zeroconf-service-type value)))
+     (lambda (_key value) (push (zeroconf-service-type value) result))
      zeroconf-services-hash)
-    result))
+    (delete-dups result)))
 
 (defun zeroconf-list-services (type)
   "Return all discovered Avahi services for a given service type TYPE.
@@ -278,9 +278,9 @@ format of SERVICE."
     (maphash
      (lambda (_key value)
        (when (equal type (zeroconf-service-type value))
-        (add-to-list 'result value)))
+        (push value result)))
      zeroconf-services-hash)
-    result))
+    (delete-dups result)))
 
 (defvar zeroconf-service-added-hooks-hash (make-hash-table :test 'equal)
   "Hash table of hooks for newly added services.
index 5c8b02b9d1f6cac42ccc3bcb5a7da061b1ce0bbc..568f5b9b873328ef4513dba53774f2b3b960b56f 100644 (file)
@@ -18682,13 +18682,14 @@ With prefix arg UNCOMPILED, load the uncompiled versions."
                              (and (string= org-dir contrib-dir)
                                   (org-load-noerror-mustsuffix (concat contrib-dir 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)
                              f))
                        lfeat)))
     (when load-uncore
       (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
        (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))
index 111b17526323e86fc5abfa9f4fbbceeee25cbbeb..db7c023324bbec8b74ac5c9001e8d53044c693f7 100644 (file)
@@ -1684,7 +1684,7 @@ cleaning up these problems."
             (mapcar
              #'(lambda (option)
                  (when force
-                   (add-to-list 'style (car option)))
+                   (push (car option) style))
                  (goto-char rstart)
                  (let ((regexp
                         (cond
index 06fd55faad3f7d8ebea61bcc2e1e781839f07704..c52bb83fa331ef17b2de43e434a7103dd297dc1e 100644 (file)
@@ -227,7 +227,7 @@ Evaluate BODY for each created map.
   (with-maps-do map
     (let ((result nil))
       (map-do (lambda (k v)
-                (add-to-list 'result (list (int-to-string k) v)))
+                (push (list (int-to-string k) v) result))
               map)
       (should (equal result '(("2" 5) ("1" 4) ("0" 3)))))))