help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [emacs-lisp newbie] print-something() -> clipboard?


From: Tom Roche
Subject: Re: [emacs-lisp newbie] print-something() -> clipboard?
Date: Sun, 20 May 2012 16:27:58 -0400
User-agent: GNU Emacs 24.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 2.20.1)

Tom Roche 18.05.2012 21:46
>>> (defun print-buffer-name ()
>>>    "Print (at point) the current buffer's name."
>>>    (interactive "*") ; abort if buffer is read-only
>>>    (insert (buffer-name (window-buffer (minibuffer-selected-window)))))
>>> (global-set-key "\C-pb" 'print-buffer-name)
...
>>> I'd like to have the option to "print" the datum to the clipboard.
>>> How can I (easily :-) do that?

Andreas Röhler Sat, 19 May 2012 09:19:36 +0200
>> (defun yank-date-clipboard ()
>>   "Insert into the kill-ring, at X also into the clipboard."
>>   (interactive)
>>   (kill-new (format-time-string "%Y%m%d")))

Drew Adams Sun, 20 May 2012 12:20:09 -0700
> (defun foo (&optional arg)
>  "..."
>  (interactive "P")
>  (let ((bn ...))
>    (if arg
>      (insert bn)
>      (kill-new bn))))

Thanks! I probably should `let`, but this works:

(defun print-buffer-name (&optional arg)
  "Print (at point) the current buffer's name, or to clipboard with prefix."
  (interactive "P") ; sets first arg to the raw command prefix
  (setq bn (buffer-name (window-buffer (minibuffer-selected-window))))
  (if arg
    (kill-new bn)
    (insert bn)))
(global-set-key "\C-pb" 'print-buffer-name)

thanks again, Tom Roche <Tom_Roche@pobox.com>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]