From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Giorgos Keramidas Newsgroups: gmane.emacs.help Subject: Re: Elisp Question... Date: Sun, 27 Sep 2009 18:26:17 +0300 Organization: SunSITE.dk - Supporting Open source Message-ID: <87ocowh0iu.fsf@kobe.laptop> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1254066058 14153 80.91.229.12 (27 Sep 2009 15:40:58 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 27 Sep 2009 15:40:58 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Sep 27 17:40:51 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Mrvrn-00016g-6e for geh-help-gnu-emacs@m.gmane.org; Sun, 27 Sep 2009 17:40:51 +0200 Original-Received: from localhost ([127.0.0.1]:56580 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mrvrm-0002bK-I3 for geh-help-gnu-emacs@m.gmane.org; Sun, 27 Sep 2009 11:40:50 -0400 Original-Path: news.stanford.edu!usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!feed118.news.tele.dk!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (berkeley-unix) Cancel-Lock: sha1:rBVnuIrcfP6+KO99kJlQAMPGZ40= Original-Lines: 51 Original-NNTP-Posting-Host: 79.129.2.61 Original-X-Trace: news.sunsite.dk DXC=GR9bA`?OTiGYG:0; 0_3?no_>`WUg<`1joJZA^dLN@mm>:R`DM8iNYfUYgo7L; _dI`aBPdSh0TI0d Original-X-Complaints-To: staff@sunsite.dk Original-Xref: news.stanford.edu gnu.emacs.help:173378 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:68493 Archived-At: On Sun, 27 Sep 2009 14:32:22 +0000 (UTC), magicus wrote: > Hi, > > I posted this to comp.emacs when this might be a more useful newgroup. > > I am new to using elisp and I put together the following due to ignorance > about how to do it in one function: > > ==================================================================== (fset > 'flp-cr > "Copyright © 2009 Furlan Lawrence Primus. All rights reserved.") > > (global-set-key (kbd "") 'flp-cr) > > > (fset 'flp-copyright > [f9 home ?\C- ?\C-e ?\M-w]) > > (global-set-key (kbd "") 'flp-copyright) > ==================================================================== > > The main point here is that I wanted to be able to have it such that > when I press F8 it displays the text AND copys it so that I can then > use it outside of Emacs. The above seems to work and I'd like to make > it a lot more compact. In addition, while it works in version 22.2.1 > it stops after printing "Copyright" in version GNU Emacs 23.1.50.24 > (i686-pc-linux- gnu, GTK+ Version 2.16.1) of 2009-09-27 on magicbox > which I compile earlier from CVS. With a small bit of Emacs Lisp you can do something like this: (defun flp-insert-copyright (copy-text) (let ((start (point))) (insert "Copyright © 2009 Furlan Lawrence Primus. All rights reserved.") (when copy-text (copy-region-as-kill start (point))))) (global-set-key (kbd "") (lambda () (interactive) (flp-insert-copyright nil))) (global-set-key (kbd "") (lambda () (interactive) (flp-insert-copyright t))) This should work fine, AFAICT. The same basic function can do both of the things you described. Wrapping it in a `lambda' form that calls the basic function with different arguments depending on the key you typed is relatively easy (but it does require a bit of Emacs Lisp code, as you can see the `global-set-key' calls I wrote).