old-www/LDP/LG/issue11/xemacs-tip.html

134 lines
5.0 KiB
HTML

<html>
<head>
<title>A Useful Hack for Xemacs</title>
</head>
<body BGCOLOR="#ffefd5" TEXT="#181871">
<H4><IMG ALIGN=MIDDLE SRC="./gx/bat-l.gif">
&quot;Linux Gazette...<I>making Linux just a little less scary!</I>
&quot;<IMG ALIGN=MIDDLE SRC="./gx/bat-r.gif"> </H4>
<P> <HR> <P>
<!--===================================================================-->
<center><h2>A "Kill-Ring" Menu For Xemacs</h2></center>
<center><h4><a href="mailto: layers@vax2.rain.gen.mo.us">by Larry
Ayers</a></h4></center>
<center>Copyright &copy; 1996</center><BR>
<center><H5>Published in Issue 11 of the Linux Gazette</H5></center>
<P> <HR> <P>
Lately I've been enjoying exploring the myriad capabilities of GNU Emacs'
offspring and competitor, Xemacs. Aside from the burden of downloading the
voluminous source, Xemacs offers quite a few features which Gnu Emacs
lacks. Luckily for those considering a transition, the basic keystrokes and
commands are nearly identical.
<p>One feature of Gnu Emacs which I began to miss after a while was the handy
pull-down menu which displays the first few words of each cut or copied
selection made in the current session, i.e. the "kill-ring". The prospect of
figuring out how the lisp files work which determine the menu-bar's structure
wasn't too appealing. I know a little lisp, but not enough to add a new menu
entry.
<p>Some weeks later, while idly browsing through some emacs newsgroup
headers, I came across this posting, which I'll quote here in full:<br>
<pre>
In article <9604170740.AA26236@portia.uk.abs> imac@portia.rd.abs.alcatel.co.uk
(Ian MacKinnon) writes:
&gt When I used emacs (before I saw the light), I made use of a function
&gt mouse-menu-choose-yank which offered you the choice to yank from the recent
&gt history of selections via a popup menu, but I can't get it to work in
&gt XEmacs because x-popup-menu doesn't exist, and the parameters to
&gt popup-menu are different. Has anyone got an alternative. I enclose the
&gt ...
I have hacked the Emacs codes of mouse-menu-choose-yank to put in
Xemacs as follows:
<code>
(defvar yank-menu-length 40
"*Maximum length of an item in the menu for select-and-yank.")
(defun select-and-yank-filter (menu)
(let* ((count 0))
(append menu
(mapcar
#'(lambda (str)
(if (> (length str) yank-menu-length)
(setq str (substring str 0 yank-menu-length)))
(prog1
(vector
str
(list
'progn
'(push-mark (point))
(list 'insert (list 'current-kill count t)))
t)
(setq count (1+ count))))
kill-ring))))
</code>
For this to work, you have to put on your menu bar the following submenu
(use add-submenu for that for example):
<code>
("Select and Yank"
:included kill-ring
:filter select-and-yank-filter)
</code>
Hope this help
-----------------------------------------------------------------------
PHAM Dinh Tuan | e-mail: Dinh-Tuan.Pham@imag.fr
Laboratoire de Modelisation et Calcul | Tel: +33 76 51 44 23
BP 53, 38041 Grenoble cedex (France) | Fax: +33 76 63 12 63
-----------------------------------------------------------------------
</pre>
<p>
It took a little experimenting to get this to work. The first section
of lisp code, ending with "kill-ring))))", can be copied unaltered into
the xemacs section of your ~/.emacs file. If you're using Xemacs 19.14
(the current version), it goes into your ~/.xemacs-options file.
<p>The second, shorter lisp snippet needs one small addition:<br>
<pre>
<code>
(add-submenu nil '("Kill-Ring"
:included kill-ring
:filter select-and-yank-filter))
</pre>
</code><br>
<p>As well as adding the proper syntax for <i>add-submenu</i>, I shortened
the menu-title, but it could be called anything you like.
<p>When I first restarted Xemacs after placing this code into the init file
the new submenu was nowhere to be seen. I surmised that I'd made some error,
and put off further experimentation for another time. A few minutes later I
was busily editing some file. I happened to glance up at the menu-bar and
found a brand-new kill-ring submenu. Surprisingly the new menu only appears
after a selection has been cut or copied.
<p>I was happy, and thought that by relating my experience I could encourage
other Xemacs users (especially the ones who know as little lisp as I do!) to
try this neat hack. Thanks to Dinh Tuan Pham, if he or she should happen to
see this.
<!--===================================================================-->
<P> <hr> <P>
<A HREF="./index.html"><IMG ALIGN=BOTTOM SRC="../gx/indexnew.gif"
ALT="[ TABLE OF CONTENTS ]"></A>
<A HREF="../index.html"><IMG ALIGN=BOTTOM SRC="../gx/homenew.gif"
ALT="[ FRONT PAGE ]"></A>
<A HREF="./gm.html"><IMG SRC="../gx/back2.gif"
ALT=" Back "></A>
<A HREF="./linus.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
<P> <hr> <P>
</body>
</html>