From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michael Maurer Newsgroups: gmane.emacs.help Subject: Re: custom function getting initialized randomly Date: Mon, 27 Mar 2023 16:56:29 +0200 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="8182"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs@gnu.org To: Richard Copley Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Mar 27 16:57:17 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 1pgoHd-0001zc-BW for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 27 Mar 2023 16:57:17 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pgoH8-0004uO-E2; Mon, 27 Mar 2023 10:56:46 -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 1pgoH5-0004tw-UK for help-gnu-emacs@gnu.org; Mon, 27 Mar 2023 10:56:43 -0400 Original-Received: from mail-vs1-xe2b.google.com ([2607:f8b0:4864:20::e2b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pgoH4-0000Uz-D2 for help-gnu-emacs@gnu.org; Mon, 27 Mar 2023 10:56:43 -0400 Original-Received: by mail-vs1-xe2b.google.com with SMTP id i10so7736840vss.5 for ; Mon, 27 Mar 2023 07:56:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679929000; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=nqM1zBmev2FpUKkF58zgi9gFGUZTTSJy/EGdB0SOZyw=; b=Yz4EwwcUm25hvK1jqbnIxq+9WFadYEA2qKZv9lVPB7r4iHmkIVPPx4iNAFaKnKTMsq mxUJDeOTu+njy5t1DDyVPXR1r3lM+cVSAOK2eR2bi+h58eiyQ6UCRM8+q3aYKlZqsFom Q3Nn5mJzFY3kRFftisGHMDICU5uw8+cj1y/9jQGA015XH2vAVA7k1W7jPtQhYgzDUgBl 33s8FRcjdAHfgF1hvw7lQxqC5CWZwX3/X6cINuIlkLgxBYyjRntTqpuLcAZDt1ksAP40 HSuEuDiyRyAOsW8GmLjtsEQC5SgFIP28YKTSL8yeFoSmEUYaajtqZwDg4bt2wIum3rG2 M4sQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679929000; 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=nqM1zBmev2FpUKkF58zgi9gFGUZTTSJy/EGdB0SOZyw=; b=SRLiCdujeUZ4mtsxUg9ZZWjmZYsRApLTMo+VNiYIw6RPIYFbVxMRdb8ZgDZCRvkdak 8Tnd5khZlxwSkWNPNL7IN94Pt0tfJ1WxlWh/6IU/SUUgoDV/WTufyvNvvq56/jGkmZQi SNwBpP3E59S9gyV9tKZzE9IqT4Jirni9IQ9oFC/ydY3ZrXmoYt7iIwMlZ1pCav5irkpO NaNIr548243ZJt/suWd5tcpKh63z/EMOGIRTFu32lP1wWfAXMAYTHlWeBofhHTOpF/dp BasBe+eqh2uq71P9owfh9irMCQVWhlrY1diZV8pFPhr0800HUE+DNkrJ+5lnKuSoZiki oEdw== X-Gm-Message-State: AAQBX9dWwgw+cOtBI+HTy4TO82KPFmGi1Mm2cxbNz3iKLK9ehvwvAQ6f nnvXt/4B1RhWNE2rXbBGAc9non3lz8OHNkaV7kA= X-Google-Smtp-Source: AKy350brAg4mTibDzHQISCGhJJJEspKwRn2cbCq+YmDQNO9P70ATmupRsXEqdvn1Bc9BpNs9dTrzmNNekO1DoR0ahB4= X-Received: by 2002:a67:e199:0:b0:416:f1ea:1001 with SMTP id e25-20020a67e199000000b00416f1ea1001mr6368603vsl.5.1679929000548; Mon, 27 Mar 2023 07:56:40 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::e2b; envelope-from=maurer.michael@gmail.com; helo=mail-vs1-xe2b.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:143127 Archived-At: On Mon, 27 Mar 2023 at 15:56, Richard Copley wrote: > > 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`. 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?