From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: jpkotta Newsgroups: gmane.emacs.help Subject: Re: Getting a menu in the minibuffer Date: Fri, 25 Dec 2009 00:00:32 -0800 (PST) Organization: http://groups.google.com Message-ID: <40d89bee-5e79-4da3-9af8-04bfba7ba8e3@n38g2000yqf.googlegroups.com> References: <87d4273xeg.fsf@Traian.DecebalComp> <86e48787-f41e-4205-93eb-746e622d0507@h9g2000yqa.googlegroups.com> <87oclo7us9.fsf@Traian.DecebalComp> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1261831343 16803 80.91.229.12 (26 Dec 2009 12:42:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 26 Dec 2009 12:42:23 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Dec 26 13:42:16 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 1NOVyK-0005yo-5i for geh-help-gnu-emacs@m.gmane.org; Sat, 26 Dec 2009 13:42:16 +0100 Original-Received: from localhost ([127.0.0.1]:44481 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NOVyK-0001ef-HI for geh-help-gnu-emacs@m.gmane.org; Sat, 26 Dec 2009 07:42:16 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!postnews.google.com!n38g2000yqf.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 199 Original-NNTP-Posting-Host: 97.114.191.210 Original-X-Trace: posting.google.com 1261728032 20863 127.0.0.1 (25 Dec 2009 08:00:32 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Fri, 25 Dec 2009 08:00:32 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: n38g2000yqf.googlegroups.com; posting-host=97.114.191.210; posting-account=EwI0QQoAAADdqmqX_mVfawBNtwyks2YE User-Agent: G2/1.0 X-HTTP-UserAgent: Opera/9.80 (X11; Linux i686; U; en) Presto/2.2.15 Version/10.10,gzip(gfe),gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:175779 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:70865 Archived-At: On Dec 24, 12:25=A0am, Cecil Westerhof wrote: > jpkotta writes: > >> There are several commands that give a little menu in the menu buffer. > >> For example tmm-menubar. I would like something like that also. I am > >> busy with extending GNUS. I think the best way to use those extra > >> functions -and maybe some standard ones- would be by using a menu. Is > >> there a place where building something like that is explained, or do I > >> need to consult the sources? > > > A very simple echo area menu is > >http://www.emacswiki.org/emacs/OneTwoThreeMenu. > > Thanks. > > > I have some modifications to it that: automatically format the items > > into columns; allow for continually re-displaying the menu until C-g > > is pressed; and allow for any keystroke to select an item. =A0I use my > > modified version but I wanted to work on it a bit more before > > submitting a patch. =A0If you're interested I can send it. > > I sure am. > > -- > Cecil Westerhof > Senior Software Engineer > LinkedIn:http://www.linkedin.com/in/cecilwesterhof I figured I might as well post it here, sorry if it's too big. Example: (123-menu-defmenu-repeated nav-menu ("i" "[i] up line" 'previous-line) ("j" "[j] left char" 'backward-char) ("k" "[k] down line" 'next-line) ("l" "[l] right char" 'forward-char) ("C-i" "[C-i] up para" 'backward-paragraph) ("C-j" "[C-j] left word" 'c-backward-subword) ("C-k" "[C-k] down para" 'forward-paragraph) ("C-l" "[C-l] right word" 'c-forward-subword) ("u" "[u] scroll left" (lambda () (interactive) (force-scroll-left -8))) ("o" "[o] scroll right" (lambda () (interactive) (force-scroll-left 8))) ("C-u" "[C-u] scroll up" 'cua-scroll-up) ("C-o" "[C-o] scroll down" 'cua-scroll-down) ) Modified 123-menu.el file: ;;; 123-menu.el --- Simple menuing system, reminiscent of Lotus 123 in DOS ;; Copyright (C) 2006 Free Software Foundation, Inc. ;; Author: Marc Abramowitz ;; Modified by Jonathan Kotta ;; Keywords: convenience ;; This file is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; This file is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;; Even though I've been using Emacs for years, I still have trouble ;; remembering a lot of the key combinations for commands that I don't ;; use all the time (e.g.: killing and yanking rectangles, bookmarks, ;; etc.). I think Lotus 123 for DOS had a remarkably cool user ;; interface in that the menus let you explore around and find things ;; if you were a newbie, but once you knew the key sequences, you ;; could become very fast with it. This is my attempt at doing ;; something like the Lotus 123 menu system for Emacs. ;;; Code: ;; Common Lisp functions (eval-when-compile (require 'cl)) (defmacro ilam (&rest body) `(lambda () (interactive) ,@body)) (defmacro ilamq (&rest body) `'(lambda () (interactive) ,@body)) (defvar 123-menu-stack '()) (defmacro 123-menu-make-menu-item (menu key caption &rest rest) `(setf ,menu (append ,menu (list (list :key ,key :caption ,caption :func ,@rest))))) (defmacro 123-menu-defmenu (name &rest rest) `(progn (defconst ,name (let ((menu)) ;; (message (format "%s has %d entries" ',name (length ',rest))) (dolist (item ',rest) (123-menu-make-menu-item menu (first item) (second item) (eval (third item)))) ;; (message (format "menu =3D %s" menu)) menu)) (fset (intern (concat "123-menu-display-menu-" (symbol-name ',name))) (ilamq (123-menu-display-menu ,name))) ) ) (defmacro 123-menu-defmenu-repeated (name &rest rest) `(progn (defconst ,name (let ((menu)) ;; (message (format "%s has %d entries" ',name (length ',rest))) (dolist (item ',rest) (123-menu-make-menu-item menu (first item) (second item) (eval (third item)))) ;; (message (format "menu =3D %s" menu)) menu)) (fset (intern (concat "123-menu-display-menu-" (symbol-name ',name))) (ilamq (123-menu-display-menu ,name t))) ) ) (defun format-width (str width) (format (concat "%-" (format "%d" width) "s") str)) (defun 123-menu-print-menu (menu) (let ((col-width 0) (num-cols 0) (captions ()) (msg "")) (setq captions (mapcar (lambda (x) (getf x :caption)) menu)) (setq col-width (1+ (reduce 'max (mapcar 'length captions)))) (setq num-cols (/ (frame-width) col-width)) (setq captions (mapcar (lambda (x) (format-width x col-width)) captions)) (dotimes (i (length captions)) (if (and (not (eq i 0)) (eq 0 (mod i num-cols))) (setq msg (concat msg "\n"))) (setq msg (concat msg (elt captions i)))) (message msg) )) (defun 123-menu-display-menu (menu &optional repeated) (interactive) (let ((map (make-sparse-keymap)) (continue t) (c "")) (dolist (item menu) (define-key map (eval `(kbd ,(getf item :key))) (getf item :func))) ;; (message (format "caption =3D %s ; func =3D %s" (getf item :caption) (getf item :func)))) (define-key map "~" (ilamq (123-menu-display-menu (elt 123-menu- stack 1)))) (setf 123-menu-stack (push menu 123-menu-stack)) (while continue (123-menu-print-menu menu) (setq c (read-key-sequence nil)) (setq c (lookup-key map c)) (cond ((eq c 'Helper-help-options) (Helper-help-options)) ((commandp c) (condition-case nil (call-interactively c) (error nil)) (unless repeated (setq continue nil))) (t (ding) (setq continue nil))))) (pop 123-menu-stack)) (provide '123-menu) ;;; 123-menu.el ends here