gnu-emacs-sources
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A simple repacement for `describe-bindings' function.


From: Tom Wurgler
Subject: Re: A simple repacement for `describe-bindings' function.
Date: Thu, 10 May 2001 08:55:47 -0400 (EDT)

While we are talking keybindings...:)

Some time ago I wrote a keybinding displayer for the function keys called
keys.el.... 

;; create a buffer with the function keys listed on it.

;; Author: Tom Wurgler <address@hidden>
;; Created: 11/6/1996
;; Keywords: function, keybinding

;; This file is not part of GNU Emacs.

;; This program 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 program 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.
;;
;; A copy of the GNU General Public License can be obtained from
;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
;; 02139, USA.
;;

;;; Commentary:

;; This code pops up a buffer showing what the function keys are bound to.
;; The display is active (if you change a binding during an emacs session,
;; keybindings will still display correctly).  After the pop-up, any key
;; returns to the previous window configuration.  You can display keybindings
;; for plain function keys, shift-function keys, control-function keys or
;; control-shift function keys.  This is just a handy way to scope out
;; what you had the keys bound to.

;
; $Id: keys.el,v 1.2 1999-10-01 10:37:33-04 wurgler Exp wurgler $
;
; $Log: keys.el,v $
; Revision 1.2  1999-10-01 10:37:33-04  wurgler
; added control-shift level of key display
;
; Revision 1.1  1996-11-06 09:57:14-05  wurgler
; Initial revision
;
;; add this to .emacs (with the keybinding of your choice):

;; (define-key global-map [kp-add] 'keybindings)
;; (define-key global-map [C-kp-add] 'c-keybindings)
;; (define-key global-map [S-kp-add] 's-keybindings)
;; (define-key global-map [C-S-kp-add] 'c-s-keybindings)
;; (autoload 'keybindings "keys" "Display function key bindings" t)
;; (autoload 'c-keybindings "keys" "Display control function key bindings" t)
;; (autoload 's-keybindings "keys" "Display shift function key bindings" t)
;; (autoload 'c-s-keybindings "keys" "Display control shift function key 
bindings" t)

(defun c-s-keybindings ()
  "Create a buffer containing the current control-shift function key bindings."
  (interactive)
  (keybindings nil nil t))

(defun c-keybindings ()
  "Create a buffer containing the current control function key bindings."
  (interactive)
  (keybindings t))

(defun s-keybindings ()
  "Create a buffer containing the current shift function key bindings."
  (interactive)
  (keybindings nil t))

(defun keybindings (&optional control shift control-shift)
  "Create a buffer containing the current function key bindings."
  (interactive)
  (save-window-excursion
    (save-excursion
      (let ((beg)
            (end)
            (maxc)
            (howmany 5))
        (if (one-window-p)
            (split-window-vertically))
        (set-buffer (get-buffer-create " *Keybindings*"))
        (setq buffer-read-only nil)
        (erase-buffer)
        (if control
            (progn
              (insert (describe-key-briefly [C-f1]) "\n")
              (insert (describe-key-briefly [C-f2]) "\n")
              (insert (describe-key-briefly [C-f3]) "\n")
              (insert (describe-key-briefly [C-f4]) "\n")
              (insert (describe-key-briefly [C-f5]) "\n")
              (insert (describe-key-briefly [C-f6]) "\n")
              (insert (describe-key-briefly [C-f7]) "\n")
              (insert (describe-key-briefly [C-f8]) "\n")
              (insert (describe-key-briefly [C-f9]) "\n")
              (insert (describe-key-briefly [C-f10]) "\n")
              (insert (describe-key-briefly [C-f11]) "\n")
              (insert (describe-key-briefly [C-f12]) "\n")
              (insert (describe-key-briefly [C-print]) "\n")
              (insert (describe-key-briefly [C-key-20]) "\n")
              (insert (describe-key-briefly [C-pause]) "\n"))
          (if shift
              (progn
                (insert (describe-key-briefly [S-f1]) "\n")
                (insert (describe-key-briefly [S-f2]) "\n")
                (insert (describe-key-briefly [S-f3]) "\n")
                (insert (describe-key-briefly [S-f4]) "\n")
                (insert (describe-key-briefly [S-f5]) "\n")
                (insert (describe-key-briefly [S-f6]) "\n")
                (insert (describe-key-briefly [S-f7]) "\n")
                (insert (describe-key-briefly [S-f8]) "\n")
                (insert (describe-key-briefly [S-f9]) "\n")
                (insert (describe-key-briefly [S-f10]) "\n")
                (insert (describe-key-briefly [S-f11]) "\n")
                (insert (describe-key-briefly [S-f12]) "\n")
                (insert (describe-key-briefly [S-print]) "\n")
                (insert (describe-key-briefly [S-key-20]) "\n")
                (insert (describe-key-briefly [S-pause]) "\n"))
            (if control-shift
                (progn
                  (insert (describe-key-briefly [C-S-f1]) "\n")
                  (insert (describe-key-briefly [C-S-f2]) "\n")
                  (insert (describe-key-briefly [C-S-f3]) "\n")
                  (insert (describe-key-briefly [C-S-f4]) "\n")
                  (insert (describe-key-briefly [C-S-f5]) "\n")
                  (insert (describe-key-briefly [C-S-f6]) "\n")
                  (insert (describe-key-briefly [C-S-f7]) "\n")
                  (insert (describe-key-briefly [C-S-f8]) "\n")
                  (insert (describe-key-briefly [C-S-f9]) "\n")
                  (insert (describe-key-briefly [C-S-f10]) "\n")
                  (insert (describe-key-briefly [C-S-f11]) "\n")
                  (insert (describe-key-briefly [C-S-f12]) "\n")
                  (insert (describe-key-briefly [C-S-print]) "\n")
                  (insert (describe-key-briefly [C-S-key-20]) "\n")
                  (insert (describe-key-briefly [C-S-pause]) "\n"))
              (insert (describe-key-briefly [f1]) "\n")
              (insert (describe-key-briefly [f2]) "\n")
              (insert (describe-key-briefly [f3]) "\n")
              (insert (describe-key-briefly [f4]) "\n")
              (insert (describe-key-briefly [f5]) "\n")
              (insert (describe-key-briefly [f6]) "\n")
              (insert (describe-key-briefly [f7]) "\n")
              (insert (describe-key-briefly [f8]) "\n")
              (insert (describe-key-briefly [f9]) "\n")
              (insert (describe-key-briefly [f10]) "\n")
              (insert (describe-key-briefly [f11]) "\n")
              (insert (describe-key-briefly [f12]) "\n")
              (insert (describe-key-briefly [print]) "\n")
              (insert (describe-key-briefly [key-20]) "\n")
              (insert (describe-key-briefly [pause]) "\n"))))
        (goto-char 1)
        (replace-string " runs the command" "")
        (goto-char 1)
        (setq maxc 0)
        (setq count 0)
        (while (not (= count howmany))
          (setq count (1+ count))
          (end-of-line)
          (if (> (current-column) maxc)
              (setq maxc (current-column)))
          (forward-line 1))
        (setq maxc (1+ maxc))
        (goto-char 1)
        (setq count 0)
        (while (not (= count howmany))
          (setq count (1+ count))
          (end-of-line)
          (while (< (current-column) maxc)
            (insert " "))
          (forward-line 1))
        (setq beg (point))
        (setq maxc 0)
        (setq count 0)
        (while (not (= count howmany))
          (setq count (1+ count))
          (end-of-line)
          (if (> (current-column) maxc)
              (setq maxc (current-column)))
          (forward-line 1))
        (setq maxc (1+ maxc))
        (goto-char beg)
        (setq count 0)
        (while (not (= count howmany))
          (setq count (1+ count))
          (end-of-line)
          (while (< (current-column) maxc)
            (insert " ")
            (setq end (point)))
          (forward-line 1))
        (setq end (1- (point)))
        (kill-rectangle beg end)
        (goto-char 1)
        (end-of-line)
        (yank-rectangle)
        (goto-char (1+ end))
        (setq beg (point))
        (setq maxc 0)
        (while (not (eobp))
          (setq count (1+ count))
          (end-of-line)
          (if (> (current-column) maxc)
              (setq maxc (current-column)))
          (forward-line 1))
        (forward-line -1)
        (end-of-line)
        (while (< (current-column) maxc)
          (insert " "))
        (setq end (point))
        (kill-rectangle beg end)
        (goto-char 1)
        (end-of-line)
        (yank-rectangle)
        (setq h (1- (window-height)))
        (pop-to-buffer " *Keybindings*")
        (setq buffer-read-only t)
        (shrink-window (- h (1- howmany)))
        (goto-char 1))
      (setq junkme (read-key-sequence nil)))))


Recently "Sandip Chitale" <address@hidden> wrote:

> From: "Sandip Chitale" <address@hidden>
> Sender: address@hidden
> Date: Wed, 9 May 2001 23:49:46 -0700
> 
> Does not deal with C-c prefix keymaps yet. In fact I would
> like to know how to get keybindings from a prefix keymap.
> 
> (defun keytable (arg)
>   "A simple repacement for `describe-bindings' function to print the key
> bindings in a tabular form.
> The `describe-bindings' function shows a single column of keys to their
> bindings. The `keytable'
> shows the same information in a tabular form. You can choose to display the
> bindings using
> only certain modifiers.
> 
> Bind \\[describe-bindings] to `keytable', which usually binds to
> `describe-bindings', like so
> \(global-set-key \(read-kbd-macro \"\\[describe-bindings]\"\) 'keytable\)
> "
>   (interactive "sEnter a modifier [a space separated C- S- M- A- or even
> comibination like C-S- M-C-S-]:")
>   (with-output-to-temp-buffer "*Key table*"
>     (princ (format "Major Mode: %s\nMinor Modes: %s\n" major-mode
> minor-mode-alist))
>     (let* ((i 0)
>     (keys (list
>     "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m"
>     "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"
>     "1" "2" "3" "4" "5" "6" "7" "8" "9" "0"
>     "<down>" "<up>" "<right>" "<left>"
>     "<kp-down>" "<kp-up>" "<kp-right>" "<kp-left>"
>      "<return>" "<home>" "<end>"
>      "<f1>" "<f2>" "<f3>" "<f4>" "<f5>" "<f6>" "<f7>" "<f8>" "<f9>" "<f10>"
> "<f11>" "<f12>"
>      "`" "~" "!" "@" "#" "$" "%" "^" "&" "*" "(" ")" "-" "_" "=" "+" "\\"
> "|" "{" "[" "]" "}" ";" "'" ":" "\"" "<" ">" "," "." "/" "?"
>          ))
>     (n (length keys))
>     (modifiers (list "" "C-" "M-" "S-" "M-C-" "S-C-"))
>     )
>       (if (not (string= arg ""))
>    (setq modifiers (split-string arg))
>  )
>       (setq k (length modifiers))
>       (princ (format "_%-10.10s__" "__________"))
>       (let ((j 0))
>  (while (< j k)
>    (princ (format "_%-50.50s__"
> "__________________________________________________"))
>    (setq j (+ j 1))
>    )
>  )
>       (princ "\n")
>       (princ (format " %-10.10s |" "Key"))
>       (let ((j 0))
>  (while (< j k)
>    (princ (format " %-50.50s |" (nth j modifiers)))
>    (setq j (+ j 1))
>    )
>  )
>       (princ "\n")
>       (princ (format "_%-10.10s_|" "__________"))
>       (let ((j 0))
>  (while (< j k)
>    (princ (format "_%-50.50s_|"
> "__________________________________________________"))
>    (setq j (+ j 1))
>    )
>  )
>       (princ "\n")
>       (while (< i n)
>  (princ (format " %-10.10s |" (nth i keys)))
>  (let ((j 0))
>    (while (< j k)
>      (let* ((binding (key-binding (read-kbd-macro (concat (nth j modifiers)
> (nth i keys)))))
>      (binding-string "_")
>      )
>        (if (null binding)
>     ()
>   (if (eq binding 'self-insert-command)
>       (setq binding-string (concat "'" (nth i keys) "'"))
>     (setq binding-string (format "%s" binding))
>     )
>   )
>        (setq binding-string (substring binding-string 0 (min (length
> binding-string) 48)))
>        (princ (format " %-50.50s |" binding-string))
>        (setq j (+ j 1))
>        )
>      )
>    )
>  (princ "\n")
>  (setq i (+ i 1))
>  )
>       (princ (format "_%-10.10s_|" "__________"))
>       (let ((j 0))
>  (while (< j k)
>    (princ (format "_%-50.50s_|"
> "__________________________________________________"))
>    (setq j (+ j 1))
>    )
>  )
>       )
>     )
>   (delete-window)
>   (hscroll-mode)
>   )
> 
> 
> _______________________________________________
> Gnu-emacs-sources mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/gnu-emacs-sources
> 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]