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

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

Re: custom function getting initialized randomly


From: Michael Maurer
Subject: Re: custom function getting initialized randomly
Date: Mon, 27 Mar 2023 16:56:29 +0200

On Mon, 27 Mar 2023 at 15:56, Richard Copley <rcopley@gmail.com> wrote:
>
> On Mon, 27 Mar 2023 at 10:21, Michael Maurer <maurer.michael@gmail.com> wrote:
> >
> > Hello,
> >
> > I wrote the following function to copy the kill-ring to the scratch
> > buffer, but it only gets initialized sometimes at the start of emacs,
> > sometimes not. Why?
> >
> > (defun copy-to-scratch-on-kill
> > ()
> > "Copy every kill (delete or yank) to *scratch* buffer."
> > (let
> >     ((cur-kill-string
> >       (current-kill 0 t)))
> >   (when
> >       (and
> >        (not
> > (equal cur-kill-string ""))
> >        (not
> > (equal cur-kill-string prev-kill-string))
> >        (get-buffer "*scratch*"))
> >     (with-current-buffer "*scratch*"
> >       (goto-char
> >        (point-max))
> >       (insert cur-kill-string "\n")
> >       (goto-char
> >        (point-max))))
> >   (setq prev-kill-string cur-kill-string)))
> >
> > (add-hook 'post-command-hook #'copy-to-scratch-on-kill)
> >
>
> If an error propagates from the hook function (most likely "Kill ring
> is empty", signalled by `current-kill`) then Emacs removes the
> function from the hook. See the docstring for variable
> `post-command-hook`.

Would wrapping the body of the function in (ignore errors ..) be an ok
solution as far as cheap hacks go, or is it too sketchy?



reply via email to

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