;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/random.el (defun do-whatever-return (fun &rest args) (let ((pnt (point)) (buf (current-buffer))) (apply fun args) (when (bufferp buf) (switch-to-buffer buf) (goto-char pnt)))) ;; (do-whatever-return #'switch-to-buffer "*Help*") (defun switch-buffer-random () (let*((buffers (buffer-list)) (num-bufs (length buffers)) (rand-buf-num (random (1- num-bufs))) (buf (nth rand-buf-num buffers))) (when (bufferp buf) (switch-to-buffer buf)))) ;; (switch-buffer-random) (defun move-point-random () (let*((min (point-min)) (max (point-max)) (random-char (+ min (random (- max min))))) (goto-char random-char) (message "point in %s: %d" (current-buffer) (point)))) ;; (move-point-random) (defun switch-buffer-move-point-random () (switch-buffer-random) (move-point-random)) ;; (switch-buffer-move-point-random) ;; (advice-add #'switch-buffer-move-point-random :around #'do-whatever-return) ;; (switch-buffer-move-point-random) ;; ;; (advice-remove #'switch-buffer-move-point-random #'do-whatever-return) ;; (switch-buffer-move-point-random) (provide 'random)