From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Richard Copley Newsgroups: gmane.emacs.help Subject: Re: custom function getting initialized randomly Date: Mon, 27 Mar 2023 14:56:01 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29599"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs@gnu.org To: Michael Maurer Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Mar 27 15:57:14 2023 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pgnLR-0007J6-K1 for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 27 Mar 2023 15:57:09 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pgnKu-0004tH-RQ; Mon, 27 Mar 2023 09:56:36 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pgnKq-0004r0-Vu for help-gnu-emacs@gnu.org; Mon, 27 Mar 2023 09:56:34 -0400 Original-Received: from mail-qt1-x82b.google.com ([2607:f8b0:4864:20::82b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pgnKo-0008Un-I9 for help-gnu-emacs@gnu.org; Mon, 27 Mar 2023 09:56:31 -0400 Original-Received: by mail-qt1-x82b.google.com with SMTP id n14so8587076qta.10 for ; Mon, 27 Mar 2023 06:56:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679925389; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=XnDYnYG461+uFYdue0D+rbjCHSQL79dHV9/GbCBF1WA=; b=Bk7m1TZRrngQFFnqtp06Kj2pnU29SeLMreH4vtiY7I9a/PrFnbGWIBiDR+m56ofbq8 wOAFIscgOD+AqJmrE4uGPCQsZs5gBclDd/8geI3/ea4/Z5UgDHyeJjPOkLzoCvL4dVz5 I1d5vJY09xWuTUe/MZa5kfG9KXFzmj58TuEI346T50l57k9xQ8BFkvOjIGteGt/NSXXQ mVaukjUhWnDpUJskIQ2QWWWmjRtVSM3kgvWlmPheC9SjGGnmEkuCJDl1/dB91BvRgubM 9dkhG4nkduptQR7s1TtFYvS4LfIn4G7GPQhPY1pWJTvD0SuQaMZeFt7RZJgazMzz9D3c +89Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679925389; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XnDYnYG461+uFYdue0D+rbjCHSQL79dHV9/GbCBF1WA=; b=uw0gfoRZQxZdsGpOHFrJishLs+rFCixgIIfcFIy/OUreIKN4xQ9lDzvU+UyJqEsSPU E61P4RfATd3ZpBdNleUwL5jl/D4j5hdj7MhvjTNo7eDBA1oBCjES9kG6AJ29HgiytLyz RVbcQzPdrg9DEV3z2DtyLmTg4WzPGeEvD5JweyNJkgoxdypkRdZkWIqzpLbs5+DumMLJ HKPi9ItEMb/5b7qNILgGqfQgi4Dc5nljun1U3LTRl+PU4lShChzkw8NvO5/xXPSsBlns PRggtjt8C1QcG5mWgbLK4cMiHN8ASHyaP5KchQl3wxLJXy/x7I+kJI/RUjeKc+nAJZPK FYdg== X-Gm-Message-State: AO0yUKU29vDj/rPLIq0Hj7wCgW47cwwN07rD7wrbigU1s4vAT54lu3/G tb5buk3DbgEQl4qbXkGGvIAOakPMj2Cx7Mgu7yx9GebKjUc= X-Google-Smtp-Source: AK7set8OCEt5VouJMStj9xkI8qf5wc3hYK2AY0+EnW9EMp3qCyKRqFO+qyb0aoCBXq8uTrrwkxUHCHl4DMfLy02RmeU= X-Received: by 2002:a05:622a:18a0:b0:3e0:4bb6:f998 with SMTP id v32-20020a05622a18a000b003e04bb6f998mr4376383qtc.10.1679925388686; Mon, 27 Mar 2023 06:56:28 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::82b; envelope-from=rcopley@gmail.com; helo=mail-qt1-x82b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:143124 Archived-At: On Mon, 27 Mar 2023 at 10:21, Michael Maurer 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`.