Article View: gnu.epoch.misc
Article #2207Epoch Interface to Xmenu (Part 3 of 3)
From: Mark A Kolb
Date: Tue, 19 Feb 1991 16:23
Date: Tue, 19 Feb 1991 16:23
93 lines
3293 bytes
3293 bytes
Here are two sample applications of the XMENU interface, one for
selecting buffers, and one for inserting selections from the kill ring.
- Mark Kolb
kolb@crd.ge.com
;;; -*- Mode: Emacs-Lisp -*-
;;; File written by Mark A. Kolb, Tue, Jan 22 1991.
;;; Elisp functions which use the XMENU interface.
(require 'x-utils)
(provide 'xmenu-utils)
;;; Use of XMENU to select a buffer.
(defun xmenu-buffer-select (&rest ignore)
"Selects a new current buffer from a pop-up xmenu."
(interactive)
(let ((buffer-name (xmenu "Select Buffer" (get-buffer-names))))
(when buffer-name
(switch-to-buffer buffer-name))))
(defun get-buffer-names ()
"Returns a list of the names of all selectable buffers."
(let ((buffer-names nil)
(space-char ? ))
(dolist (a-name (mapcar 'buffer-name (buffer-list)))
(when (not (char-equal (elt a-name 0) space-char))
(setq buffer-names (cons a-name buffer-names))))
(nreverse buffer-names)))
;(global-set-key "Pick a key" 'xmenu-buffer-select)
;;; Sample code using XMENU to paste items from the kill ring.
(defun xmenu-kill-ring (&rest ignore)
"Inserts choices from a pop-up xmenu of the kill ring."
(interactive)
(let* ((filtered-ring (remove-whitespace-strings kill-ring))
(filtered-choices (mapcar 'trim-leading-whitespace filtered-ring))
(selection (xmenu "Kill Ring" filtered-choices filtered-ring)))
(when selection (insert selection))))
;(global-set-key "Pick a key" 'xmenu-kill-ring)
;;; Functions for filtering strings with whitespace characters.
;;; Used by XMENU-KILL-RING.
(defvar *whitespace-chars* '(? ? ?
) "A list of all whitespace characters (SPACE, TAB, NEWLINE).")
(defun remove-whitespace-strings (string-list)
"Filters out strings from STRING-LIST which contain only whitespace chars."
(let ((keepers '())
(keep-p nil))
(dolist (a-string string-list)
(setq keep-p nil)
(let ((i 0)
(length (length a-string)))
(while (and (null keep-p)
(< i length))
(if (memq (elt a-string i) *whitespace-chars*)
(setq i (+ i 1))
(setq keep-p t))))
(when keep-p
(setq keepers (cons a-string keepers))))
(nreverse keepers)))
(defun trim-leading-whitespace (a-string)
"Returns a substring of A-STRING with no leading whitespace characters."
(let ((i 0)
(length (length a-string))
(start nil))
(while (and (null start)
(< i length))
(if (memq (elt a-string i) *whitespace-chars*)
(setq i (+ i 1))
(setq start i)))
(if (zerop start)
a-string
(substring a-string start))))
;;; End of file.
Technical Details
Message-ID:
<16907@crdgw1.crd.ge.com>Path:
arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!zaphod.mps.ohio-state.edu!rpi!crdgw1!seattle!kolbShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fc7ee,543ef64e05e5a2eb,start X-Google-Attributes: gidfc7ee,public X-Google-ArrivalTime: 1991-02-20 08:01:41 PST Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!zaphod.mps.ohio-state.edu!rpi!crdgw1!seattle!kolb From: kolb@seattle.crd.ge.com (Mark A Kolb) Newsgroups: gnu.epoch.misc Subject: Epoch Interface to Xmenu (Part 3 of 3) Keywords: menus, xmenu Message-ID: <16907@crdgw1.crd.ge.com> Date: 19 Feb 91 16:23:18 GMT Sender: news@crdgw1.crd.ge.com Reply-To: kolb@crd.ge.com Organization: GE Corporate R&D Center, Schenectady, NY Lines: 93