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

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

Re: Elisp Question...


From: Giorgos Keramidas
Subject: Re: Elisp Question...
Date: Sun, 27 Sep 2009 18:26:17 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (berkeley-unix)

On Sun, 27 Sep 2009 14:32:22 +0000 (UTC), magicus 
<REMOVEmagicus23THIS@gmail.com> 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 "<f9>") 'flp-cr)
>
>
> (fset 'flp-copyright
>    [f9 home ?\C-  ?\C-e ?\M-w])
>
> (global-set-key (kbd "<f8>") '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 "<f9>") (lambda ()
                                   (interactive)
                                   (flp-insert-copyright nil)))

    (global-set-key (kbd "<f8>") (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).



reply via email to

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