help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to return to the position from where I did tags-query-replace?


From: Emanuel Berg
Subject: Re: How to return to the position from where I did tags-query-replace?
Date: Sun, 04 Feb 2018 05:30:11 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Boy, advices are sure difficult to use, even
for people who do not know how to use them!

But this seems to work (?). The original
function I wrote, actually didn't require any
modification, just the extra advice call to
glue it together.

I wrote a couple of pretty meaningless random
functions, no pun intended, just for testing.
Those are the ones one should replace with the
real thing, if one would like to do this
for real.

(defun do-whatever-return (fun &rest args)
  (let ((point  (point))
        (buffer (current-buffer)) )
    (apply fun args)
    (when (bufferp buffer)
      (switch-to-buffer buffer)
      (goto-char (point) ))))
;; (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))))
        (new-char (goto-char random-char)) )
    (message "New point in %s is %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)

-- 
underground experts united
http://user.it.uu.se/~embe8573


reply via email to

[Prev in Thread] Current Thread [Next in Thread]