all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* custom function getting initialized randomly
@ 2023-03-27  8:22 Michael Maurer
  2023-03-27 13:56 ` Richard Copley
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Maurer @ 2023-03-27  8:22 UTC (permalink / raw)
  To: help-gnu-emacs

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)



^ permalink raw reply	[flat|nested] 8+ messages in thread
* custom function getting initialized randomly
@ 2023-03-27  8:29 Michael Maurer
  0 siblings, 0 replies; 8+ messages in thread
From: Michael Maurer @ 2023-03-27  8:29 UTC (permalink / raw)
  To: help-gnu-emacs

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)



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-03-27 15:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-27  8:22 custom function getting initialized randomly Michael Maurer
2023-03-27 13:56 ` Richard Copley
2023-03-27 14:56   ` Michael Maurer
2023-03-27 15:06     ` Richard Copley
2023-03-27 15:20   ` tomas
2023-03-27 15:30     ` Michael Maurer
2023-03-27 15:52       ` tomas
  -- strict thread matches above, loose matches on Subject: below --
2023-03-27  8:29 Michael Maurer

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.