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 14:57:30 -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")))

Thanks! So now I'm wondering, how can I toggle between
insert-to-buffer and insert-to-clipboard semantics? I now have

(defun print-buffer-name ()
  "Print (at point) the current buffer's name."
  (interactive "*") ; abort if buffer is read-only
  (let ((bn (buffer-name (window-buffer (minibuffer-selected-window)))))
    (insert bn)))
(global-set-key "\C-pb" 'print-buffer-name)

(defun print-buffer-name-clipboard ()
  "Print to clipboard the current buffer's name."
  (interactive "*") ; abort if buffer is read-only
  (let ((bn (buffer-name (window-buffer (minibuffer-selected-window)))))
    (kill-new bn)))
(global-set-key "\C-pc" 'print-buffer-name-clipboard)

but I don't want to define a separate keychord in each case. I want
something like (expressed procedurally--unfortunately I currently think
in '{}', not '()')

if I type [C-p b]
  (insert bn)
else if I type [C-u C-p b]
  (kill-new bn)

Can that be done with one {function, keychord} definition?
Or must I have 2, like above? If the latter, how to define
[C-u C-p b]?

your assistance is appreciated, Tom Roche <address@hidden>



reply via email to

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