diff options
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/avoid.el | 10 | ||||
-rw-r--r-- | lisp/emacs-lisp/seq.el | 1 | ||||
-rw-r--r-- | lisp/epa-ks.el | 3 | ||||
-rw-r--r-- | lisp/erc/erc-networks.el | 2 | ||||
-rw-r--r-- | lisp/gnus/gnus-fun.el | 4 | ||||
-rw-r--r-- | lisp/net/soap-inspect.el | 4 | ||||
-rw-r--r-- | lisp/obsolete/landmark.el | 2 | ||||
-rw-r--r-- | lisp/play/mpuz.el | 2 | ||||
-rw-r--r-- | lisp/play/zone.el | 2 | ||||
-rw-r--r-- | lisp/vc/add-log.el | 3 |
10 files changed, 14 insertions, 19 deletions
diff --git a/lisp/avoid.el b/lisp/avoid.el index d3afecf8cc2..03707d10465 100644 --- a/lisp/avoid.el +++ b/lisp/avoid.el @@ -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))) diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el index ae5988296d8..baafc51693c 100644 --- a/lisp/emacs-lisp/seq.el +++ b/lisp/emacs-lisp/seq.el @@ -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." diff --git a/lisp/epa-ks.el b/lisp/epa-ks.el index ebdb1274218..35caa1a93c5 100644 --- a/lisp/epa-ks.el +++ b/lisp/epa-ks.el @@ -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'"))) diff --git a/lisp/erc/erc-networks.el b/lisp/erc/erc-networks.el index 1c7742afd21..678c596760b 100644 --- a/lisp/erc/erc-networks.el +++ b/lisp/erc/erc-networks.el @@ -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 diff --git a/lisp/gnus/gnus-fun.el b/lisp/gnus/gnus-fun.el index 8bca4ffe38f..bfc57a2d605 100644 --- a/lisp/gnus/gnus-fun.el +++ b/lisp/gnus/gnus-fun.el @@ -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) diff --git a/lisp/net/soap-inspect.el b/lisp/net/soap-inspect.el index b994b0ed862..5207ca8ff19 100644 --- a/lisp/net/soap-inspect.el +++ b/lisp/net/soap-inspect.el @@ -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)))))) diff --git a/lisp/obsolete/landmark.el b/lisp/obsolete/landmark.el index cc4fd19c389..83e7649a69c 100644 --- a/lisp/obsolete/landmark.el +++ b/lisp/obsolete/landmark.el @@ -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)) diff --git a/lisp/play/mpuz.el b/lisp/play/mpuz.el index ff174fed6c2..df2b6fc867a 100644 --- a/lisp/play/mpuz.el +++ b/lisp/play/mpuz.el @@ -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) diff --git a/lisp/play/zone.el b/lisp/play/zone.el index 27aa48f4c9a..a5d4ac9dc66 100644 --- a/lisp/play/zone.el +++ b/lisp/play/zone.el @@ -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))))) diff --git a/lisp/vc/add-log.el b/lisp/vc/add-log.el index 2e20284951f..1290d7e03a5 100644 --- a/lisp/vc/add-log.el +++ b/lisp/vc/add-log.el @@ -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)))) |