mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-11-21 06:55:39 +00:00
Prefer seq-random-elt to nth+random
* lisp/emacs-lisp/seq.el (seq-random-elt): Autoload. * lisp/avoid.el (mouse-avoidance-random-shape): * lisp/epa-ks.el (epa-ks--query-url): * lisp/erc/erc-networks.el (erc-server-select): * lisp/gnus/gnus-fun.el (gnus--random-face-with-type) (gnus-fun-ppm-change-string): * lisp/net/soap-inspect.el (soap-sample-value-for-xs-simple-type): * lisp/obsolete/landmark.el (landmark-random-move): * lisp/play/mpuz.el (mpuz-build-random-perm): * lisp/play/zone.el (zone-pgm-stress): * lisp/vc/add-log.el (add-change-log-entry): * test/lisp/net/tramp-tests.el (tramp-test44-asynchronous-requests): Prefer seq-random-elt to nth+random.
This commit is contained in:
parent
8fbf816ccd
commit
35d0675467
@ -43,7 +43,7 @@
|
||||
;;
|
||||
;; (if (eq window-system 'x)
|
||||
;; (mouse-avoidance-set-pointer-shape
|
||||
;; (nth (random 4)
|
||||
;; (seq-random-elt
|
||||
;; (list x-pointer-man x-pointer-spider
|
||||
;; x-pointer-gobbler x-pointer-gumby))))
|
||||
;;
|
||||
@ -125,7 +125,6 @@ TOP-OR-BOTTOM-POS: Distance from top or bottom edge of frame or window."
|
||||
;; Internal variables
|
||||
(defvar mouse-avoidance-state nil)
|
||||
(defvar mouse-avoidance-pointer-shapes nil)
|
||||
(defvar mouse-avoidance-n-pointer-shapes 0)
|
||||
(defvar mouse-avoidance-old-pointer-shape nil)
|
||||
(defvar mouse-avoidance-animating-pointer nil)
|
||||
|
||||
@ -306,11 +305,8 @@ redefine this function to suit your own tastes."
|
||||
(all-completions "x-pointer-" obarray
|
||||
(lambda (x)
|
||||
(and (boundp x)
|
||||
(integerp (symbol-value x)))))))
|
||||
(setq mouse-avoidance-n-pointer-shapes
|
||||
(length mouse-avoidance-pointer-shapes))))
|
||||
(nth (random mouse-avoidance-n-pointer-shapes)
|
||||
mouse-avoidance-pointer-shapes))
|
||||
(integerp (symbol-value x)))))))))
|
||||
(seq-random-elt mouse-avoidance-pointer-shapes))
|
||||
|
||||
(defun mouse-avoidance-ignore-p ()
|
||||
(let ((mp (mouse-position)))
|
||||
|
@ -570,6 +570,7 @@ SEQUENCE must be a sequence of numbers or markers."
|
||||
If no element is found, return nil."
|
||||
(ignore-errors (seq-elt sequence n)))
|
||||
|
||||
;;;###autoload
|
||||
(cl-defgeneric seq-random-elt (sequence)
|
||||
"Return a random element from SEQUENCE.
|
||||
Signal an error if SEQUENCE is empty."
|
||||
|
@ -149,8 +149,7 @@ If EXACT is non-nil, don't accept approximate matches."
|
||||
(cond ((null epa-keyserver)
|
||||
(user-error "Empty keyserver pool"))
|
||||
((listp epa-keyserver)
|
||||
(nth (random (length epa-keyserver))
|
||||
epa-keyserver))
|
||||
(seq-random-elt epa-keyserver))
|
||||
((stringp epa-keyserver)
|
||||
epa-keyserver)
|
||||
((error "Invalid type for `epa-keyserver'")))
|
||||
|
@ -824,7 +824,7 @@ As an example:
|
||||
(ports (if (listp (nth 3 srv))
|
||||
(erc-ports-list (nth 3 srv))
|
||||
(list (nth 3 srv))))
|
||||
(port (nth (random (length ports)) ports)))
|
||||
(port (and ports (seq-random-elt ports))))
|
||||
(erc :server host :port port)))
|
||||
|
||||
;;; The following experimental
|
||||
|
@ -103,7 +103,7 @@ PNG format."
|
||||
(remove nil (mapcar
|
||||
(lambda (f) (unless (string-match (or omit "^$") f) f))
|
||||
(directory-files dir t ext))))
|
||||
(file (nth (random (length files)) files)))
|
||||
(file (and files (seq-random-elt files))))
|
||||
(when file
|
||||
(funcall fun file)))))
|
||||
|
||||
@ -315,7 +315,7 @@ colors of the displayed X-Faces."
|
||||
(let* ((possibilities '("%02x0000" "00%02x00" "0000%02x"
|
||||
"%02x%02x00" "00%02x%02x" "%02x00%02x"))
|
||||
(format (concat "'#%02x%02x%02x' '#"
|
||||
(nth (random 6) possibilities)
|
||||
(seq-random-elt possibilities)
|
||||
"'"))
|
||||
(values nil))
|
||||
(dotimes (i 255)
|
||||
|
@ -114,7 +114,7 @@ This is a specialization of `soap-sample-value' for
|
||||
(cond
|
||||
((soap-xs-simple-type-enumeration type)
|
||||
(let ((enumeration (soap-xs-simple-type-enumeration type)))
|
||||
(nth (random (length enumeration)) enumeration)))
|
||||
(and enumeration (seq-random-elt enumeration))))
|
||||
((soap-xs-simple-type-pattern type)
|
||||
(format "a string matching %s" (soap-xs-simple-type-pattern type)))
|
||||
((soap-xs-simple-type-length-range type)
|
||||
@ -134,7 +134,7 @@ This is a specialization of `soap-sample-value' for
|
||||
(t (random 100)))))
|
||||
((consp (soap-xs-simple-type-base type)) ; an union of values
|
||||
(let ((base (soap-xs-simple-type-base type)))
|
||||
(soap-sample-value (nth (random (length base)) base))))
|
||||
(soap-sample-value (and base (seq-random-elt base)))))
|
||||
((soap-xs-basic-type-p (soap-xs-simple-type-base type))
|
||||
(soap-sample-value (soap-xs-simple-type-base type))))))
|
||||
|
||||
|
@ -1470,7 +1470,7 @@ push him out of it."
|
||||
(mapc
|
||||
(lambda (direction) (put direction 'y_t 0))
|
||||
landmark-directions)
|
||||
(dolist (direction (nth (random 8) landmark-8-directions))
|
||||
(dolist (direction (seq-random-elt landmark-8-directions))
|
||||
(put direction 'y_t 1.0))
|
||||
(landmark-move))
|
||||
|
||||
|
@ -153,7 +153,7 @@ You may abort a game by typing \\<mpuz-mode-map>\\[mpuz-offer-abort]."
|
||||
(index 10)
|
||||
elem)
|
||||
(while letters
|
||||
(setq elem (nth (random index) letters)
|
||||
(setq elem (seq-random-elt letters)
|
||||
letters (delq elem letters)
|
||||
index (1- index))
|
||||
(aset mpuz-digit-to-letter index elem)
|
||||
|
@ -596,7 +596,7 @@ If the element is a function or a list of a function and a number,
|
||||
(forward-line -1)
|
||||
(delete-region (point) (line-beginning-position 2))
|
||||
(goto-char (point-min))
|
||||
(insert (nth (random (length lines)) lines)))
|
||||
(insert (seq-random-elt lines)))
|
||||
(message (concat (make-string (random (- (frame-width) 5)) ? ) "grrr"))
|
||||
(sit-for 0.1)))))
|
||||
|
||||
|
@ -930,8 +930,7 @@ non-nil, otherwise in local time."
|
||||
(not (looking-at "[ \t]+.*<.*>$")))
|
||||
(setq hit t)))))
|
||||
(forward-line 1)
|
||||
(insert (nth (random (length new-entries))
|
||||
new-entries)
|
||||
(insert (and new-entries (seq-random-elt new-entries))
|
||||
(if use-hard-newlines hard-newline "\n")
|
||||
(if use-hard-newlines hard-newline "\n"))
|
||||
(forward-line -1))))
|
||||
|
@ -6787,8 +6787,7 @@ process sentinels. They shall not disturb each other."
|
||||
(let ((time (float-time))
|
||||
(default-directory tmp-name)
|
||||
(file
|
||||
(buffer-name
|
||||
(nth (random (length buffers)) buffers)))
|
||||
(buffer-name (seq-random-elt buffers)))
|
||||
;; A remote operation in a timer could
|
||||
;; confuse Tramp heavily. So we ignore this
|
||||
;; error here.
|
||||
@ -6853,7 +6852,7 @@ process sentinels. They shall not disturb each other."
|
||||
;; the buffers. Mix with regular operation.
|
||||
(let ((buffers (copy-sequence buffers)))
|
||||
(while buffers
|
||||
(let* ((buf (nth (random (length buffers)) buffers))
|
||||
(let* ((buf (seq-random-elt buffers))
|
||||
(proc (get-buffer-process buf))
|
||||
(file (process-get proc 'foo))
|
||||
(count (process-get proc 'bar)))
|
||||
|
Loading…
Reference in New Issue
Block a user