A Useful Hack for Xemacs

Copyright © 1996

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.

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.

Some weeks later, while idly browsing through some emacs newsgroup headers, I came across this posting, which I’ll quote here in full:

 In article  imac@portia.rd.abs.alcatel.co.uk
(Ian MacKinnon) writes: > When I used emacs (before I saw the light), I made use of a function
> mouse-menu-choose-yank which offered you the choice to yank from the recent
> history of selections via a popup menu, but I can't get it to work in
> XEmacs because x-popup-menu doesn't exist, and the parameters to
> popup-menu are different. Has anyone got an alternative. I enclose the
> ... I have hacked the Emacs codes of mouse-menu-choose-yank to put in
Xemacs as follows: 
(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
             #'(lambda (str)
                 (if (> (length str) yank-menu-length)
                     (setq str (substring str 0 yank-menu-length)))
                       '(push-mark (point))
                       (list 'insert (list 'current-kill count t)))
                   (setq count (1+ count))))

For this to work, you have to put on your menu bar the following submenu
(use add-submenu for that for example):

      ("Select and Yank"
       :included kill-ring
       :filter select-and-yank-filter)

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

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.

READ  Fvwm Configuration in Different Environments using cpp Issue 21

The second, shorter lisp snippet needs one small addition:

           (add-submenu nil '("Kill-Ring"
                     :included kill-ring
                     :filter select-and-yank-filter))

As well as adding the proper syntax for add-submenu, I shortened the menu-title, but it could be called anything you like.

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.

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.

indexnew-8818967 homenew-4078268 back2-3236081 fwd-2882670