* goof in small function where???
@ 2014-07-22 9:21 ken
2014-07-22 10:02 ` Michael Heerdegen
2014-07-22 10:33 ` Thorsten Jolitz
0 siblings, 2 replies; 9+ messages in thread
From: ken @ 2014-07-22 9:21 UTC (permalink / raw)
To: GNU Emacs List
The function below half works: it does put the buffer-file-name into the
kill ring, but nothing is displayed in the minibuffer. Why? And how to
fix this?
(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)))
)
Thanks much.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: goof in small function where???
[not found] <mailman.5851.1406020938.1147.help-gnu-emacs@gnu.org>
@ 2014-07-22 9:41 ` Joost Kremers
2014-07-22 10:16 ` ken
0 siblings, 1 reply; 9+ messages in thread
From: Joost Kremers @ 2014-07-22 9:41 UTC (permalink / raw)
To: help-gnu-emacs
ken wrote:
> The function below half works: it does put the buffer-file-name into the
> kill ring, but nothing is displayed in the minibuffer. Why? And how to
> fix this?
>
> (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)))
> )
Works for me. You're probably doing something (or Emacs does something)
that makes the message disappear right away. (Messages in the minibuffer
disappear as soon as you press a key or even hit a cursor key.)
Check the *Messages* buffer if the message is there (`C-h e` or mouse-1
in the minibuffer.[1])
HTH
Joost
[1] Thanks, Drew. (Sincerely.)
--
Joost Kremers joostkremers@fastmail.fm
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: goof in small function where???
2014-07-22 9:21 ken
@ 2014-07-22 10:02 ` Michael Heerdegen
2014-07-22 10:28 ` ken
2014-07-22 10:33 ` Thorsten Jolitz
1 sibling, 1 reply; 9+ messages in thread
From: Michael Heerdegen @ 2014-07-22 10:02 UTC (permalink / raw)
To: help-gnu-emacs
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'.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: goof in small function where???
2014-07-22 9:41 ` goof in small function where??? Joost Kremers
@ 2014-07-22 10:16 ` ken
0 siblings, 0 replies; 9+ messages in thread
From: ken @ 2014-07-22 10:16 UTC (permalink / raw)
To: Joost Kremers, help-gnu-emacs
On 07/22/2014 05:41 AM Joost Kremers wrote:
> ken wrote:
>> The function below half works: it does put the buffer-file-name into the
>> kill ring, but nothing is displayed in the minibuffer. Why? And how to
>> fix this?
>>
>> (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)))
>> )
>
> Works for me. You're probably doing something (or Emacs does something)
> that makes the message disappear right away. (Messages in the minibuffer
> disappear as soon as you press a key or even hit a cursor key.)
>
> Check the *Messages* buffer if the message is there (`C-h e` or mouse-1
> in the minibuffer.[1])
>
> HTH
>
> Joost
Thanks, Joost. But "Copied filename..." isn't anywhere in *Messages*
buffer. If, however, I do in a file:
(message "Hello Message")C-x C-e
I do see "Hello Message" in the minibuffer and (some seconds later) in
*Messages*.
Very weird! How could this be?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: goof in small function where???
2014-07-22 10:02 ` Michael Heerdegen
@ 2014-07-22 10:28 ` ken
2014-07-22 11:07 ` Michael Heerdegen
0 siblings, 1 reply; 9+ messages in thread
From: ken @ 2014-07-22 10:28 UTC (permalink / raw)
To: help-gnu-emacs
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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: goof in small function where???
2014-07-22 9:21 ken
2014-07-22 10:02 ` Michael Heerdegen
@ 2014-07-22 10:33 ` Thorsten Jolitz
2014-07-22 10:52 ` Thorsten Jolitz
1 sibling, 1 reply; 9+ messages in thread
From: Thorsten Jolitz @ 2014-07-22 10:33 UTC (permalink / raw)
To: help-gnu-emacs
ken <gebser@mousecar.com> writes:
> The function below half works: it does put the buffer-file-name into
> the kill ring, but nothing is displayed in the minibuffer. Why? And
> how to fix this?
>
> (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)))
> )
Try:
#+begin_src emacs-lisp
(defun tj/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)))
(when str
(kill-new str)
(message "Copied filename %s to kill ring" str))))
#+end_src
#+results:
: tj/file-name-into-kill-buffer
#+begin_src emacs-lisp
(tj/file-name-into-kill-buffer)
#+end_src
#+results:
: Copied filename /home/tj/News/drafts/drafts/853 to kill ring
I guess `kill-new` is for side-effects only and returns nil, so in your
version the `message` call is never executed.
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: goof in small function where???
2014-07-22 10:33 ` Thorsten Jolitz
@ 2014-07-22 10:52 ` Thorsten Jolitz
2014-07-22 11:09 ` Michael Heerdegen
0 siblings, 1 reply; 9+ messages in thread
From: Thorsten Jolitz @ 2014-07-22 10:52 UTC (permalink / raw)
To: help-gnu-emacs
Thorsten Jolitz <tjolitz@gmail.com> writes:
> ken <gebser@mousecar.com> writes:
>
>> The function below half works: it does put the buffer-file-name into
>> the kill ring, but nothing is displayed in the minibuffer. Why? And
>> how to fix this?
> Try: ...
ok, I should have pressed 'g' in gnus first before answering - too late
to the party ;)
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: goof in small function where???
2014-07-22 10:28 ` ken
@ 2014-07-22 11:07 ` Michael Heerdegen
0 siblings, 0 replies; 9+ messages in thread
From: Michael Heerdegen @ 2014-07-22 11:07 UTC (permalink / raw)
To: help-gnu-emacs
ken <gebser@mousecar.com> writes:
> 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?
Exactly. `and' is not the right way to tell Emacs "do this _and_
that" ;-)
The following would also be ok, btw:
(and str
(progn (kill-new str)
(message "Copied filename %s to kill ring" str)))
Regards,
Michael.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: goof in small function where???
2014-07-22 10:52 ` Thorsten Jolitz
@ 2014-07-22 11:09 ` Michael Heerdegen
0 siblings, 0 replies; 9+ messages in thread
From: Michael Heerdegen @ 2014-07-22 11:09 UTC (permalink / raw)
To: help-gnu-emacs
Thorsten Jolitz <tjolitz@gmail.com> writes:
> ok, I should have pressed 'g' in gnus first before answering - too late
> to the party ;)
I'm happy that this time I'm not the one who is saying that :-P
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2014-07-22 11:09 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.5851.1406020938.1147.help-gnu-emacs@gnu.org>
2014-07-22 9:41 ` goof in small function where??? Joost Kremers
2014-07-22 10:16 ` ken
2014-07-22 9:21 ken
2014-07-22 10:02 ` Michael Heerdegen
2014-07-22 10:28 ` ken
2014-07-22 11:07 ` Michael Heerdegen
2014-07-22 10:33 ` Thorsten Jolitz
2014-07-22 10:52 ` Thorsten Jolitz
2014-07-22 11:09 ` Michael Heerdegen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).