Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting a menu in the minibuffer

0 views
Skip to first unread message

Cecil Westerhof

unread,
Dec 22, 2009, 9:18:15 AM12/22/09
to
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?

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

jpkotta

unread,
Dec 23, 2009, 6:34:36 PM12/23/09
to

A very simple echo area menu is http://www.emacswiki.org/emacs/OneTwoThreeMenu.

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. I use my
modified version but I wanted to work on it a bit more before
submitting a patch. If you're interested I can send it.

Cecil Westerhof

unread,
Dec 24, 2009, 1:25:42 AM12/24/09
to
jpkotta <jpk...@gmail.com> 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. I use my
> modified version but I wanted to work on it a bit more before
> submitting a patch. If you're interested I can send it.

I sure am.

jpkotta

unread,
Dec 25, 2009, 3:00:32 AM12/25/09
to
On Dec 24, 12:25 am, Cecil Westerhof <Ce...@decebal.nl> wrote:

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 <http://marc-abramowitz.com>
;; Modified by Jonathan Kotta <jpk...@gmail.com>
;; 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 = %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 = %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 = %s ; func = %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

Xavier Maillard

unread,
Dec 28, 2009, 4:45:46 AM12/28/09
to jpkotta, help-gn...@gnu.org
Please use the "source" list for such post.

Xavier
--
http://www.gnu.org
http://www.april.org
http://www.lolica.org


0 new messages