|
From: | ken |
Subject: | Re: goof in small function where??? |
Date: | Tue, 22 Jul 2014 06:28:33 -0400 |
User-agent: | Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 |
On 07/22/2014 06:02 AM Michael Heerdegen wrote:
ken <gebser@mousecar.com> writes:(defun file-name-into-kill-buffer () "Put path/filename of current buffer onto kill-ring so to paste into an X application. Also display it in minibuffer." (interactive) (let ((str (buffer-file-name))) (and str (kill-new str) (message "Copied filename %s to kill ring" str))) )This doesn't work when `kill-new' returns nil, which happens when `interprogram-cut-function' is nil (which is the default). Note that the doc of `kill-new' doesn't say anything about the return value, it can be anything. Ergo: the `and' should better be a `when'.
Yes! That fixed it!! Thanks very much.I'm vaguely understanding that the 'and' doesn't evaluate '(message...' when '(kill-new...' returns nil and, since its return value is undefined, it can do on occasion. Replacing 'and' with 'when' ensures '(message...' is evaluated regardless of what '(kill-new...' returns.
Is that about right? Thanks again.
[Prev in Thread] | Current Thread | [Next in Thread] |